Mercurial > projects > dang
annotate ast/Exp.d @ 10:2f493057cf17
Some support for the rest of the boolean operators
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 13:01:11 +0200 |
parents | 2ce5209f1954 |
children | 69464d465284 |
rev | line source |
---|---|
1 | 1 module ast.Exp; |
2 | |
3 import tango.text.Util : jhash; | |
4 | |
5 import lexer.Token; | |
6 | |
7 import sema.SymbolTable; | |
8 | |
9 enum ExpType | |
10 { | |
11 Binary, | |
12 Negate, | |
13 IntegerLit, | |
14 Identifier, | |
15 AssignExp, | |
16 CallExp, | |
17 } | |
18 | |
19 class Exp | |
20 { | |
21 this(ExpType expType) | |
22 { | |
23 this.expType = expType; | |
24 } | |
25 | |
26 ExpType expType; | |
27 Scope env; | |
28 } | |
29 | |
30 class CallExp : Exp | |
31 { | |
32 this(Exp exp, Exp[] args) | |
33 { | |
34 super(ExpType.CallExp); | |
35 this.exp = exp; | |
36 this.args = args; | |
37 } | |
38 | |
39 Exp exp; | |
40 Exp[] args; | |
41 } | |
42 | |
43 class AssignExp : Exp | |
44 { | |
45 this(Identifier identifier, Exp exp) | |
46 { | |
47 super(ExpType.AssignExp); | |
48 this.identifier = identifier; | |
49 this.exp = exp; | |
50 } | |
51 | |
52 Identifier identifier; | |
53 Exp exp; | |
54 } | |
55 | |
56 class BinaryExp : Exp | |
57 { | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
58 public enum Operator |
1 | 59 { |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
60 Eq, Ne, |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
61 Lt, Le, |
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
62 Gt, Ge, |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
63 Mul, Div, |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
64 Add, Sub, |
1 | 65 } |
66 | |
67 this(Operator op, Exp left, Exp right) | |
68 { | |
69 super(ExpType.Binary); | |
70 this.op = op; | |
71 this.left = left; | |
72 this.right = right; | |
73 } | |
74 | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
75 char[] resultType() |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
76 { |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
77 if (op >= Operator.Eq && op <= Operator.Ge) |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
78 return "bool"; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
79 return null; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
80 } |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
81 |
1 | 82 Operator op; |
83 Exp left, right; | |
84 } | |
85 | |
86 class NegateExp : Exp | |
87 { | |
88 this(Exp exp) | |
89 { | |
90 super(ExpType.Negate); | |
91 this.exp = exp; | |
92 } | |
93 | |
94 public Exp exp; | |
95 } | |
96 | |
97 class IntegerLit : Exp | |
98 { | |
99 this(Token t) | |
100 { | |
101 super(ExpType.IntegerLit); | |
102 this.token = t; | |
103 } | |
104 | |
105 Token token; | |
106 } | |
107 | |
108 class Identifier : Exp | |
109 { | |
110 this(Token t) | |
111 { | |
112 super(ExpType.Identifier); | |
113 this.token = t; | |
114 name = t.get; | |
115 } | |
116 | |
117 char[] get() | |
118 { | |
119 return name; | |
120 } | |
121 | |
122 hash_t toHash() | |
123 { | |
124 return jhash(name); | |
125 } | |
126 | |
127 int opCmp(Object o) | |
128 { | |
129 if (auto id = cast(Identifier)o) | |
130 return typeid(char[]).compare(&name, &id.name); | |
131 return 0; | |
132 } | |
133 | |
134 int opEquals(Object o) | |
135 { | |
136 if (auto id = cast(Identifier)o) | |
137 return typeid(char[]).equals(&name, &id.name); | |
138 return 0; | |
139 } | |
140 | |
141 Token token; | |
142 char[] name; | |
143 } | |
144 | |
145 |