comparison trunk/src/TypeRules.d @ 792:05dfe88dd3bb

Added new module TypeRules.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 27 Feb 2008 02:12:59 +0100
parents
children dcd30b0ba711
comparison
equal deleted inserted replaced
791:5fe89bb8cbdd 792:05dfe88dd3bb
1 /++
2 Author: Aziz Köksal
3 License: GPL3
4 +/
5 module TypeRules;
6
7 import common;
8
9 template ExpressionType(char[] T1, char[] T2, char[] expression)
10 {
11 mixin("alias "~T1~" X;");
12 mixin("alias "~T2~" Y;");
13 X x;
14 Y y;
15 static if(is(typeof(mixin(expression)) ResultType))
16 const char[] result = ResultType.stringof;
17 else
18 const char[] result = "Error";
19 }
20 alias ExpressionType EType;
21
22 // pragma(msg, EType!("char", "int", "&x").result);
23
24 static const string[] basicTypes = [
25 "char"[], "wchar", "dchar", "bool",
26 "byte", "ubyte", "short", "ushort",
27 "int", "uint", "long", "ulong",
28 /+"cent", "ucent",+/
29 "float", "double", "real",
30 "ifloat", "idouble", "ireal",
31 "cfloat", "cdouble", "creal"/+, "void"+/
32 ];
33
34 static const string[] unaExpressions = [
35 "!x",
36 "&x",
37 "~x",
38 "+x",
39 "-x",
40 "++x",
41 "--x",
42 "x++",
43 "x--",
44 ];
45
46 static const string[] binExpressions = [
47 "x!<>=y",
48 "x!<>y",
49 "x!<=y",
50 "x!<y",
51 "x!>=y",
52 "x!>y",
53 "x<>=y",
54 "x<>y",
55
56 "x=y", "x==y", "x!=y",
57 "x<=y", "x<y",
58 "x>=y", "x>y",
59 "x<<=y", "x<<y",
60 "x>>=y","x>>y",
61 "x>>>=y", "x>>>y",
62 "x|=y", "x||y", "x|y",
63 "x&=y", "x&&y", "x&y",
64 "x+=y", "x+y",
65 "x-=y", "x-y",
66 "x/=y", "x/y",
67 "x*=y", "x*y",
68 "x%=y", "x%y",
69 "x^=y", "x^y",
70 "x~=y",
71 "x~y",
72 "x,y"
73 ];
74
75 char[] genBinExpArray(char[] expression)
76 {
77 char[] result = "[\n";
78 foreach (t1; basicTypes)
79 {
80 result ~= "[\n";
81 foreach (t2; basicTypes)
82 result ~= `EType!("`~t1~`", "`~t2~`", "`~expression~`").result,`\n;
83 result[result.length-2] = ']'; // Overwrite last comma.
84 result[result.length-1] = ','; // Overwrite last \n.
85 }
86 result[result.length-1] = ']'; // Overwrite last comma.
87 return result;
88 }
89
90 char[] genUnaExpArray(char[] expression)
91 {
92 char[] result = "[\n";
93 foreach (t1; basicTypes)
94 result ~= `EType!("`~t1~`", "int", "`~expression~`").result,`\n;
95 result[result.length-2] = ']'; // Overwrite last comma.
96 return result;
97 }
98
99 // pragma(msg, mixin(genBinExpArray("x+y")).stringof);