annotate src/TypeRules.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/TypeRules.d@f51305056196
children 451ede0105e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
5 module TypeRules;
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
6
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
7 import cmd.Generate : xml_escape;
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
8
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
9 import TypeRulesData;
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
10 import common;
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
11
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
12 static const string[] basicTypes = [
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
13 "char"[], "wchar", "dchar", "bool",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
14 "byte", "ubyte", "short", "ushort",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
15 "int", "uint", "long", "ulong",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
16 /+"cent", "ucent",+/
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
17 "float", "double", "real",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
18 "ifloat", "idouble", "ireal",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
19 "cfloat", "cdouble", "creal"/+, "void"+/
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
20 ];
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
21
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
22 static const string[] unaryExpressions = [
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
23 "!x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
24 "&x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
25 "~x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
26 "+x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
27 "-x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
28 "++x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
29 "--x",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
30 "x++",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
31 "x--",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
32 ];
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
33
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
34 static const string[] binaryExpressions = [
792
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
35 "x!<>=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
36 "x!<>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
37 "x!<=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
38 "x!<y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
39 "x!>=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
40 "x!>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
41 "x<>=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
42 "x<>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
43
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
44 "x=y", "x==y", "x!=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
45 "x<=y", "x<y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
46 "x>=y", "x>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
47 "x<<=y", "x<<y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
48 "x>>=y","x>>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
49 "x>>>=y", "x>>>y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
50 "x|=y", "x||y", "x|y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
51 "x&=y", "x&&y", "x&y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
52 "x+=y", "x+y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
53 "x-=y", "x-y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
54 "x/=y", "x/y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
55 "x*=y", "x*y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
56 "x%=y", "x%y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
57 "x^=y", "x^y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
58 "x~=y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
59 "x~y",
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
60 "x,y"
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
61 ];
05dfe88dd3bb Added new module TypeRules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
62
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
63 void genHTMLTypeRulesTables()
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
64 {
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
65 Stdout(
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
66 `<!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
67 `<html>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
68 `<head>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
69 ` <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
70 ` <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
71 ` <style type="text/css">`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
72 ` .E { color: darkred; } /* Error */`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
73 ` .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
74 ` .X { color: darkorange; }`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
75 ` .Y { color: darkblue; }`\n
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
76 ` </style>`\n
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
77 `</head>`\n
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
78 `<body>`\n
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
79 `<p>These tables show what the type results of certain expressions are.</p>`\n
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
80 );
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
81
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
82 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
83 Stdout("<tr><td><!--typecol--></td>");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
84 foreach (unaryExpression; unaryExpressions)
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
85 Stdout.format("<td>{}</td>", {
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
86 if (unaryExpression[0] == 'x')
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
87 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
88 else
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
89 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
90 }());
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
91 Stdout("</tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
92 foreach (i, basicType; basicTypes)
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
93 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
94 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
95 foreach (expResults; unaryExpsResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
96 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
97 auto result = expResults[i];
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
98 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
99 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
100 Stdout("\n<tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
101 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
102 Stdout("</table>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
103
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
104 foreach (i, expResults; binaryExpsResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
105 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
106 auto binaryExpression = binaryExpressions[i];
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
107 binaryExpression = `<span class="X">x</span> ` ~
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
108 xml_escape(binaryExpression[1..$-1]) ~
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
109 ` <span class="Y">y</span>`;
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
110 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
111 Stdout.format("<tr><td><!--typecol--></td>");
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
112 foreach (basicType; basicTypes)
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
113 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
114 Stdout("\n<tr>\n");
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
115 foreach (j, results; expResults)
800
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
116 {
802
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
117 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
118 foreach (result; results)
f51305056196 Added modules related to type rules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 800
diff changeset
119 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
120 Stdout("\n<tr>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
121 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
122 Stdout("</table>\n");
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
123 }
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
124
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
125 Stdout(
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
126 "\n</body>"
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
127 "\n</html>"
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
128 );
dcd30b0ba711 Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 792
diff changeset
129 }