annotate src/TypeRules.d @ 839:4063da6f3edd default tip

Refactored the config file and how it is loaded.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Thu, 21 Aug 2008 17:51:04 +0200
parents 110f741dab45
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
837
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
1 #!/usr/bin/rdmd
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 /++
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 Author: Aziz Köksal
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 License: GPL3
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
5 +/
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
6 module TypeRules;
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
7
837
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
8 import tango.io.Stdout;
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
9
835
451ede0105e0 Applied minor fixes and tidied some code up a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
10 void main(char[][] args)
451ede0105e0 Applied minor fixes and tidied some code up a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 806
diff changeset
11 {
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
12 Stdout(
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
13 `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
14 `<html>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
15 `<head>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
16 ` <meta http-equiv="Content-Type" content="text/html; charset=utf-8">`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
17 ` <link href="" rel="stylesheet" type="text/css">`\n
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
18 ` <style type="text/css">`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
19 ` .E { color: darkred; } /* Error */`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
20 ` .R { font-size: 0.8em; } /* Result */`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
21 ` .X { color: darkorange; }`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
22 ` .Y { color: darkblue; }`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
23 ` </style>`\n
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
24 `</head>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
25 `<body>`\n
837
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
26 `<p>The following tables show the type results of different expressions. Compiler used: `
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
27 );
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
28
837
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
29 Stdout.format("{} {}.{,:d3}.</p>\n", __VENDOR__, __VERSION__/1000, __VERSION__%1000);
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
30
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
31 Stdout.format("<table>\n<tr><th colspan=\"{}\">Unary Expressions</th></tr>\n", unaryExpressions.length);
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
32 Stdout("<tr><td><!--typecol--></td>");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
33 foreach (unaryExpression; unaryExpressions)
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
34 Stdout.format("<td>{}</td>", {
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
35 if (unaryExpression[0] == 'x')
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
36 return `<span class="X">x</span>` ~ xml_escape(unaryExpression[1..$]);
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
37 else
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
38 return xml_escape(unaryExpression[0..$-1]) ~ `<span class="X">x</span>`;
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
39 }());
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
40 Stdout("</tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
41 foreach (i, basicType; basicTypes)
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
42 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
43 Stdout.format("<tr>\n"`<td class="X">{}</td>`, basicType);
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
44 foreach (expResults; unaryExpsResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
45 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
46 auto result = expResults[i];
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
47 Stdout.format(`<td class="R">{}</td>`, result[0] == 'E' ? `<span class="E">Error</span>`[] : result);
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
48 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
49 Stdout("\n<tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
50 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
51 Stdout("</table>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
52
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
53 foreach (i, expResults; binaryExpsResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
54 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
55 auto binaryExpression = binaryExpressions[i];
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
56 binaryExpression = `<span class="X">x</span> ` ~
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
57 xml_escape(binaryExpression[1..$-1]) ~
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
58 ` <span class="Y">y</span>`;
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
59 Stdout.format("<table>\n<tr><th colspan=\"{}\">{}</th></tr>\n", basicTypes.length, binaryExpression);
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
60 Stdout.format("<tr><td><!--typecol--></td>");
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
61 foreach (basicType; basicTypes)
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
62 Stdout.format(`<td class="Y">{}</td>`, basicType);
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
63 Stdout("\n<tr>\n");
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
64 foreach (j, results; expResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
65 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
66 Stdout.format("<tr>\n"`<td class="X">{}</td>`, basicTypes[j]);
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
67 foreach (result; results)
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
68 Stdout.format(`<td class="R">{}</td>`, result[0] == 'E' ? `<span class="E">Error</span>`[] : result);
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
69 Stdout("\n<tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
70 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
71 Stdout("</table>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
72 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
73
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
74 Stdout(
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
75 "\n</body>"
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
76 "\n</html>"
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
77 );
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
78 }
837
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
79
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
80 /// Escapes the characters '<', '>' and '&' with named character entities.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
81 /// Taken from module cmd.Highlight;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
82 char[] xml_escape(char[] text)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
83 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
84 char[] result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
85 foreach(c; text)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
86 switch(c)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
87 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
88 case '<': result ~= "&lt;"; break;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
89 case '>': result ~= "&gt;"; break;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
90 case '&': result ~= "&amp;"; break;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
91 default: result ~= c;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
92 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
93 if (result.length != text.length)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
94 return result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
95 // Nothing escaped. Return original text.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
96 delete result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
97 return text;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
98 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
99
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
100 char char_; wchar wchar_; dchar dchar_; bool bool_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
101 byte byte_; ubyte ubyte_; short short_; ushort ushort_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
102 int int_; uint uint_; long long_; ulong ulong_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
103 /+cent cent_; ucent ucent_;+/
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
104 float float_; double double_; real real_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
105 ifloat ifloat_; idouble idouble_; ireal ireal_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
106 cfloat cfloat_; cdouble cdouble_; creal creal_;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
107
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
108 static const char[][] basicTypes = [
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
109 "char"[], "wchar", "dchar", "bool",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
110 "byte", "ubyte", "short", "ushort",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
111 "int", "uint", "long", "ulong",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
112 /+"cent", "ucent",+/
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
113 "float", "double", "real",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
114 "ifloat", "idouble", "ireal",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
115 "cfloat", "cdouble", "creal"/+, "void"+/
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
116 ];
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
117
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
118 static const char[][] unaryExpressions = [
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
119 "!x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
120 "&x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
121 "~x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
122 "+x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
123 "-x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
124 "++x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
125 "--x",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
126 "x++",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
127 "x--",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
128 ];
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
129
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
130 static const char[][] binaryExpressions = [
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
131 "x!<>=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
132 "x!<>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
133 "x!<=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
134 "x!<y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
135 "x!>=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
136 "x!>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
137 "x<>=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
138 "x<>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
139
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
140 "x=y", "x==y", "x!=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
141 "x<=y", "x<y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
142 "x>=y", "x>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
143 "x<<=y", "x<<y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
144 "x>>=y","x>>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
145 "x>>>=y", "x>>>y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
146 "x|=y", "x||y", "x|y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
147 "x&=y", "x&&y", "x&y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
148 "x+=y", "x+y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
149 "x-=y", "x-y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
150 "x/=y", "x/y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
151 "x*=y", "x*y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
152 "x%=y", "x%y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
153 "x^=y", "x^y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
154 "x~=y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
155 "x~y",
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
156 "x,y"
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
157 ];
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
158
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
159 template ExpressionType(alias x, alias y, char[] expression)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
160 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
161 static if(is(typeof(mixin(expression)) ResultType))
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
162 const char[] result = ResultType.stringof;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
163 else
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
164 const char[] result = "Error";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
165 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
166 alias ExpressionType EType;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
167
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
168 char[] genBinaryExpArray(char[] expression)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
169 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
170 char[] result = "[\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
171 foreach (t1; basicTypes)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
172 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
173 result ~= "[\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
174 foreach (t2; basicTypes)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
175 result ~= `EType!(`~t1~`_, `~t2~`_, "`~expression~`").result,`\n;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
176 result[result.length-2] = ']'; // Overwrite last comma.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
177 result[result.length-1] = ','; // Overwrite last \n.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
178 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
179 result[result.length-1] = ']'; // Overwrite last comma.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
180 return result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
181 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
182 // pragma(msg, mixin(genBinaryExpArray("x%y")).stringof);
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
183
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
184 char[] genBinaryExpsArray()
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
185 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
186 char[] result = "[\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
187 foreach (expression; binaryExpressions)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
188 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
189 result ~= genBinaryExpArray(expression);
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
190 result ~= ",\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
191 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
192 result[result.length-2] = ']';
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
193 return result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
194 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
195
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
196 // pragma(msg, mixin(genBinaryExpsArray()).stringof);
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
197
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
198 char[] genUnaryExpArray(char[] expression)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
199 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
200 char[] result = "[\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
201 foreach (t1; basicTypes)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
202 result ~= `EType!(`~t1~`_, int_, "`~expression~`").result,`\n;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
203 result[result.length-2] = ']'; // Overwrite last comma.
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
204 return result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
205 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
206
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
207 char[] genUnaryExpsArray()
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
208 {
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
209 char[] result = "[\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
210 foreach (expression; unaryExpressions)
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
211 result ~= genUnaryExpArray(expression) ~ ",\n";
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
212 result[result.length-2] = ']';
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
213 return result;
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
214 }
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
215
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
216 // pragma(msg, mixin(genUnaryExpsArray()).stringof);
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
217
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
218 auto unaryExpsResults = mixin(genUnaryExpsArray());
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
219 auto binaryExpsResults = mixin(genBinaryExpsArray());
110f741dab45 Consolidated type rules table generation code into one file.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 835
diff changeset
220