Mercurial > projects > dang
annotate ast/Exp.d @ 194:08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Also added support for alias.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 29 Jul 2008 13:54:44 +0200 |
parents | 658178183018 |
children | 4e1a7265d620 |
rev | line source |
---|---|
1 | 1 module ast.Exp; |
2 | |
129 | 3 import tango.text.Util, |
4 Integer = tango.text.convert.Integer; | |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
5 import tango.io.Stdout; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
6 |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
7 import ast.Decl, |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
8 ast.Stmt; |
1 | 9 |
10 import lexer.Token; | |
11 | |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
12 import sema.Scope, |
129 | 13 sema.Symbol, |
58 | 14 sema.DType; |
1 | 15 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
16 import basic.LiteralParsing; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
17 |
1 | 18 enum ExpType |
19 { | |
20 Binary, | |
21 Negate, | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
22 Deref, |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
23 AddressOfExp, |
1 | 24 IntegerLit, |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
48
diff
changeset
|
25 MemberReference, |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
26 Index, |
1 | 27 Identifier, |
28 AssignExp, | |
29 CallExp, | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
30 CastExp, |
104
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
31 StringExp, |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
32 NewExp, |
194
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
33 NullExp, |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
34 ArrayLiteralExp, |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
35 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
36 IdentifierTypeExp, |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
37 ArrayTypeExp, |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
38 StaticArrayTypeExp, |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
39 PointerTypeExp, |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
40 FunctionTypeExp, |
1 | 41 } |
42 | |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
43 abstract class Exp |
1 | 44 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
45 this(ExpType expType, SLoc loc) |
1 | 46 { |
47 this.expType = expType; | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
48 this.loc = loc; |
1 | 49 } |
50 | |
129 | 51 /** |
52 Get the fully qualified name for the expression (if it can be resolved to | |
53 one) - otherwise null is returned | |
54 **/ | |
55 char[] getFQN() { return null; } | |
56 | |
57 /// The same as getFQN, except that the name is mangled | |
58 char[] getMangledFQN() { return null; } | |
59 | |
60 /** | |
61 Try to get the symbol the expression represents. | |
62 | |
63 Returns null for most expressions as they don't represent any symbol. | |
64 Identifiers and member references can have a sensible value. | |
65 **/ | |
66 Symbol getSymbol() { return null; } | |
67 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
68 /// Get the type of the expression |
110 | 69 abstract DType type(); |
58 | 70 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
71 /// Indicates which type the expression is - to avoid a lot of casts |
1 | 72 ExpType expType; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
73 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
74 /// The environment of the expression |
1 | 75 Scope env; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
76 |
129 | 77 Symbol symbol; |
78 | |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
79 int stmtIndex; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
80 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
81 /** |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
82 The "main" location of the expression. |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
83 What exactly this represents varies but for most things its the start |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
84 while for a binary expression its the operator. |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
85 **/ |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
86 SourceLocation loc; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
87 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
88 /// Return the starting location of this expression |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
89 SourceLocation startLoc() { return loc; } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
90 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
91 /// Get the full extents of the expression |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
92 SourceRange sourceRange() { return SourceRange(loc, loc + 1); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
93 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
94 /// Do some simplifications |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
95 Exp simplify() { return this; } |
1 | 96 } |
97 | |
98 class CallExp : Exp | |
99 { | |
100 this(Exp exp, Exp[] args) | |
101 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
102 super(ExpType.CallExp, exp.loc); |
1 | 103 this.exp = exp; |
104 this.args = args; | |
105 } | |
106 | |
58 | 107 override DType type() |
108 { | |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
109 DFunction f = exp.type.asCallable(); |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
58
diff
changeset
|
110 assert(f !is null, "Can only call functions"); |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
60
diff
changeset
|
111 return f.returnType; |
58 | 112 } |
113 | |
193
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
114 DType callerType() |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
115 { |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
116 DFunction f = new DFunction(new Identifier("function")); |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
117 f.returnType = type; |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
118 foreach (a ; args) |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
119 f.params ~= a.type; |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
120 |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
121 return f; |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
122 } |
658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
Anders Johnsen <skabet@gmail.com>
parents:
192
diff
changeset
|
123 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
124 override CallExp simplify() |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
125 { |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
126 foreach (ref arg; args) |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
127 arg = arg.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
128 exp = exp.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
129 return this; |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
130 } |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
131 |
1 | 132 Exp exp; |
133 Exp[] args; | |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
134 Symbol callSym; |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
135 bool sret = false; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
136 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
137 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
138 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
139 SourceRange res = exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
140 if (args.length > 0) |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
141 res = res + args[$ - 1].sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
142 return res; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
143 } |
1 | 144 } |
145 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
146 class AssignExp : BinaryExp |
1 | 147 { |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
148 this(SLoc op_loc, Operator op, Exp identifier, Exp exp) |
1 | 149 { |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
150 super(ExpType.AssignExp, op_loc, op, identifier, exp); |
1 | 151 this.identifier = identifier; |
152 this.exp = exp; | |
153 } | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
154 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
155 override AssignExp simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
156 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
157 identifier = identifier.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
158 exp = exp.simplify(); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
159 |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
160 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
161 } |
1 | 162 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
163 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
164 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
165 return identifier.sourceRange + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
166 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
167 |
58 | 168 override DType type() { return identifier.type(); } |
169 | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
170 Exp identifier; |
1 | 171 Exp exp; |
172 } | |
173 | |
174 class BinaryExp : Exp | |
175 { | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
176 public enum Operator |
1 | 177 { |
48
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
178 Assign, |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
179 AddAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
180 SubAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
181 MulAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
182 DivAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
183 ModAssign, |
48
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
184 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
185 Eq, Ne, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
186 |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
187 Lt, Le, |
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
188 Gt, Ge, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
189 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
190 Add, Sub, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
191 Mul, Div, Mod, |
123 | 192 |
193 LeftShift, RightShift, UnsignedRightShift, | |
125
d604152de1eb
Support shifts and binary logical operators in codegen
Anders Halager <halager@gmail.com>
parents:
123
diff
changeset
|
194 |
d604152de1eb
Support shifts and binary logical operators in codegen
Anders Halager <halager@gmail.com>
parents:
123
diff
changeset
|
195 And, Or, Xor, |
1 | 196 } |
197 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
198 char[][] getOp = ["=","+=","-=","*=","/=","%=","==","!=","<","<=",">",">=","+","-","*","/","%","<<",">>",">>>"]; |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
199 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
200 this(SLoc op_loc, Operator op, Exp left, Exp right) |
1 | 201 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
202 super(ExpType.Binary, op_loc); |
1 | 203 this.op = op; |
204 this.left = left; | |
205 this.right = right; | |
206 } | |
207 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
208 protected this(ExpType e, SLoc op_loc, Operator op, Exp left, Exp right) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
209 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
210 super(e, op_loc); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
211 this.op = op; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
212 this.left = left; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
213 this.right = right; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
214 } |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
215 |
58 | 216 override DType type() |
217 { | |
218 if (myType) | |
219 return myType; | |
220 | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
221 if (op == Operator.Eq || |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
222 op == Operator.Ne || |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
223 op == Operator.Lt || |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
224 op == Operator.Le || |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
225 op == Operator.Gt || |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
226 op == Operator.Ge) |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
227 { |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
228 myType = DType.Bool; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
229 return myType; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
230 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
231 |
58 | 232 DType l = left.type; |
233 DType r = right.type; | |
234 if (l is r) | |
235 myType = l; | |
236 else if (l.hasImplicitConversionTo(r)) | |
237 myType = r; | |
238 else if (r.hasImplicitConversionTo(l)) | |
239 myType = l; | |
240 else | |
241 return null; | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
242 return myType; |
58 | 243 } |
244 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
245 override SLoc startLoc() { return left.startLoc(); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
246 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
247 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
248 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
249 return left.sourceRange + right.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
250 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
251 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
252 char[] resultType() |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
253 { |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
254 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
|
255 return "bool"; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
256 return null; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
257 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
258 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
259 override BinaryExp simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
260 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
261 left = left.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
262 right = right.simplify(); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
263 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
264 } |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
265 |
1 | 266 Operator op; |
267 Exp left, right; | |
58 | 268 private DType myType; |
1 | 269 } |
270 | |
271 class NegateExp : Exp | |
272 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
273 this(SLoc op, Exp exp) |
1 | 274 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
275 super(ExpType.Negate, op); |
1 | 276 this.exp = exp; |
277 } | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
278 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
279 override NegateExp simplify() |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
280 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
281 exp = exp.simplify(); |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
282 return this; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
283 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
284 |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
285 override DType type() { return exp.type(); } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
286 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
287 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
288 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
289 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
290 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
291 |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
292 public Exp exp; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
293 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
294 |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
295 class DerefExp : Exp |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
296 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
297 this(SLoc op, Exp exp) |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
298 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
299 super(ExpType.Deref, op); |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
300 this.exp = exp; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
301 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
302 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
303 override DerefExp simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
304 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
305 exp = exp.simplify(); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
306 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
307 } |
1 | 308 |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
79
diff
changeset
|
309 override DType type() |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
310 { |
183
8ea749b7da91
Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param.
Anders Johnsen <skabet@gmail.com>
parents:
181
diff
changeset
|
311 if (_type) |
8ea749b7da91
Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param.
Anders Johnsen <skabet@gmail.com>
parents:
181
diff
changeset
|
312 return _type; |
129 | 313 return exp.type().asPointer().pointerOf; |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
79
diff
changeset
|
314 } |
58 | 315 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
316 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
317 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
318 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
319 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
320 |
183
8ea749b7da91
Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param.
Anders Johnsen <skabet@gmail.com>
parents:
181
diff
changeset
|
321 DType _type; |
1 | 322 public Exp exp; |
323 } | |
324 | |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
325 class AddressOfExp : Exp |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
326 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
327 this(SLoc op, Exp exp) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
328 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
329 super(ExpType.AddressOfExp, op); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
330 this.exp = exp; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
331 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
332 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
333 override AddressOfExp simplify() |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
334 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
335 exp = exp.simplify(); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
336 return this; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
337 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
338 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
339 override DType type() |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
340 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
341 return exp.type().getPointerTo; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
342 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
343 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
344 override SourceRange sourceRange() |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
345 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
346 return SourceRange(loc) + exp.sourceRange; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
347 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
348 |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
349 public Exp exp; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
350 } |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
351 |
1 | 352 class IntegerLit : Exp |
353 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
354 this(SLoc loc, char[] t) |
1 | 355 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
356 super(ExpType.IntegerLit, loc); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
357 range = SourceRange(loc, loc + t.length); |
111
c658172ca8a0
Parsing basic integers and floats.
Anders Johnsen <skabet@gmail.com>
parents:
110
diff
changeset
|
358 this.name = t; |
67
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
359 } |
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
360 |
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
361 char[] get() |
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
362 { |
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
363 return name; |
1 | 364 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
365 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
366 override IntegerLit simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
367 { |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
368 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
369 } |
1 | 370 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
371 override DType type() |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
372 { |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
373 switch(number.type) |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
374 { |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
375 case NumberType.Int: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
376 return DType.Int; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
377 case NumberType.Long: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
378 return DType.Long; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
379 case NumberType.ULong: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
380 return DType.ULong; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
381 case NumberType.Double: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
382 return DType.Double; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
383 case NumberType.Real: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
384 return DType.Real; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
385 } |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
386 } |
58 | 387 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
388 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
389 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
390 return range; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
391 } |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
392 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
393 Number number; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
394 |
67
3fdf20b08a81
Been working on the floating point parsing. Still a bit of work to do here.
Anders Johnsen <skabet@gmail.com>
parents:
65
diff
changeset
|
395 char[] name; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
396 private SourceRange range; |
1 | 397 } |
398 | |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
48
diff
changeset
|
399 class MemberReference : Exp |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
400 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
401 this(SLoc dot, Exp target, Identifier child) |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
402 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
403 super(ExpType.MemberReference, dot); |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
404 this.target = target; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
405 this.child = child; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
406 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
407 |
129 | 408 override char[] getFQN() |
409 { | |
410 return getSymbol().getFQN(); | |
411 } | |
412 | |
413 override char[] getMangledFQN() | |
414 { | |
415 return target.type.mangle() ~ child.getMangledFQN(); | |
416 } | |
417 | |
418 override Symbol getSymbol() | |
419 { | |
420 auto s = target.getSymbol(); | |
421 if (s !is null) | |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
422 return s.findMembers(child.get)[0]; |
129 | 423 return null; |
424 } | |
425 | |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
426 override MemberReference simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
427 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
428 target = target.simplify(); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
429 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
430 } |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
431 |
58 | 432 override DType type() |
433 { | |
434 if (myType) | |
435 return myType; | |
436 | |
162
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
437 if ( target.type.isStruct ) |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
438 { |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
439 Symbol st = target.getSymbol; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
440 if (auto t = st.findMembers(child.name)) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
441 myType = t[0].type; |
162
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
442 // else assert(0, "Referencing non-existant member"); |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
443 } |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
444 else if ( target.type.isClass ) |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
445 { |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
446 Symbol cl = target.getSymbol; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
447 if (auto t = cl.findMembers(child.name)) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
448 myType = t[0].type; |
162
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
449 // else assert(0, "Referencing non-existant member"); |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
450 } |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
451 else |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
160
diff
changeset
|
452 assert(0, "Only structs and classes have members"); |
58 | 453 // no error reporting here |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
454 |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
455 return myType; |
58 | 456 } |
457 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
458 override SLoc startLoc() { return target.startLoc(); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
459 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
460 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
461 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
462 return target.sourceRange + child.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
463 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
464 |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
465 Identifier child; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
466 Exp target; |
58 | 467 private DType myType; |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
468 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
469 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
470 class IndexExp : Exp |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
471 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
472 this(Exp target, SLoc left_bracket, Exp index, SLoc right_bracket) |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
473 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
474 super(ExpType.Index, target.startLoc); |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
475 this.target = target; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
476 this.left_bracket = left_bracket; |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
477 this.index = index; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
478 this.right_bracket = right_bracket; |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
479 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
480 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
481 override DType type() |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
482 { |
85
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
483 DType type = target.type(); |
136 | 484 if (type.isStaticArray()) |
485 return type.asStaticArray().arrayOf; | |
85
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
486 else if (type.isPointer()) |
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
487 return type.asPointer().pointerOf; |
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
488 else assert(0, "Can only index pointers and arrays"); |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
489 } |
58 | 490 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
491 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
492 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
493 return target.sourceRange + SourceRange(right_bracket); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
494 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
495 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
496 override IndexExp simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
497 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
498 target = target.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
499 index = index.simplify(); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
500 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
501 } |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
502 |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
503 Exp target; |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
504 Exp index; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
505 SLoc left_bracket, right_bracket; |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
506 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
507 |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
508 class CastExp : Exp |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
509 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
510 this(SLoc loc, Identifier castType, Exp exp) |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
511 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
512 super(ExpType.CastExp, loc); |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
513 this.castType = castType; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
514 this.exp = exp; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
515 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
516 |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
517 override DType type() |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
518 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
139
diff
changeset
|
519 return env.findType(this.castType.get); |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
520 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
521 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
522 override CastExp simplify() |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
523 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
524 castType = castType.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
525 exp = exp.simplify(); |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
526 return this; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
527 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
528 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
529 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
530 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
531 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
532 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
533 |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
534 Identifier castType; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
535 Exp exp; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
536 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
67
diff
changeset
|
537 |
104
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
538 class StringExp : Exp |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
539 { |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
540 this(SLoc loc, char[] str) |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
541 { |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
542 super(ExpType.StringExp, loc); |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
543 this.str = str; |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
544 } |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
545 |
192
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
546 override DType type() |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
547 { |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
548 switch (data.type) |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
549 { |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
550 case StringType.Char: |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
551 return DType.Char.getAsStaticArray(data.data.length); |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
552 case StringType.WChar: |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
553 return DType.WChar.getAsStaticArray(data.data.length/2); |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
554 case StringType.DChar: |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
555 return DType.DChar.getAsStaticArray(data.data.length/4); |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
556 } |
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
557 } |
110 | 558 |
104
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
559 char[] str; |
192
fda35d57847e
Fixed String parsing, so that they get created with the right type in AST.
Anders Johnsen <skabet@gmail.com>
parents:
185
diff
changeset
|
560 String data; |
104
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
561 } |
7ff4bc2accf2
Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents:
98
diff
changeset
|
562 |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
563 class NewExp : Exp |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
564 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
565 this(Identifier newType, Exp[] a_args, Exp[] c_args) |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
566 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
567 super(ExpType.NewExp, newType.loc); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
568 this.newType = newType; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
569 this.a_args = a_args; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
570 this.c_args = c_args; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
571 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
572 |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
573 override DType type() |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
574 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
575 return env.findType(this.newType.get); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
576 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
577 |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
578 Exp[] a_args, c_args; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
579 Identifier newType; |
164
ba94fd563548
The symbol for the constructor a "new"-exp is calling is now stored in callSym in NewExp.
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
580 Symbol callSym; |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
581 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
582 |
194
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
583 class NullExp : Exp |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
584 { |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
585 this(SLoc loc) |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
586 { |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
587 super(ExpType.NullExp, loc); |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
588 } |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
589 |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
590 override DType type() |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
591 { |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
592 return new DPointer(DType.Int); |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
593 } |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
594 } |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
193
diff
changeset
|
595 |
1 | 596 class Identifier : Exp |
597 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
598 this(SLoc loc, char[] name) |
1 | 599 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
600 super(ExpType.Identifier, loc); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
601 this.name = name; |
1 | 602 } |
603 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
604 protected this(ExpType t, SLoc loc) |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
605 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
606 super(t, loc); |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
607 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
608 |
129 | 609 override char[] getFQN() |
610 { | |
611 return name; | |
612 } | |
613 | |
614 override char[] getMangledFQN() | |
615 { | |
616 return Integer.toString(name.length) ~ name; | |
617 } | |
618 | |
619 override Symbol getSymbol() | |
620 { | |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
139
diff
changeset
|
621 if (auto decl = env.find(this.get)) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
622 if(decl.length) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
623 return decl[$-1].sym; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
624 return null; |
129 | 625 } |
626 | |
58 | 627 override DType type() |
628 { | |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
58
diff
changeset
|
629 if (myType !is null) |
58 | 630 return myType; |
129 | 631 else if (auto sym = getSymbol) |
632 myType = sym.type; | |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
111
diff
changeset
|
633 else |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
111
diff
changeset
|
634 myType = DType.Int; |
129 | 635 |
58 | 636 return myType; |
637 } | |
638 | |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
639 this(char[] name) |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
640 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
641 super(ExpType.Identifier, SLoc.Invalid); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
642 this.name = name; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
643 } |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
644 |
1 | 645 char[] get() |
646 { | |
647 return name; | |
648 } | |
649 | |
650 hash_t toHash() | |
651 { | |
652 return jhash(name); | |
653 } | |
654 | |
655 int opCmp(Object o) | |
656 { | |
657 if (auto id = cast(Identifier)o) | |
658 return typeid(char[]).compare(&name, &id.name); | |
659 return 0; | |
660 } | |
661 | |
662 int opEquals(Object o) | |
663 { | |
664 if (auto id = cast(Identifier)o) | |
665 return typeid(char[]).equals(&name, &id.name); | |
666 return 0; | |
667 } | |
668 | |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
669 override Identifier simplify() |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
670 { |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
671 return this; |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
672 } |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
673 |
93
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
674 void setType(DType myType) |
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
675 { |
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
676 this.myType = myType; |
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
677 } |
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
678 |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
679 override SourceRange sourceRange() |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
680 { |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
681 return SourceRange(loc, loc + name.length); |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
682 } |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
683 |
1 | 684 char[] name; |
58 | 685 private DType myType; |
1 | 686 } |
687 | |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
688 class IdentifierTypeExp : Identifier |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
689 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
690 this(SLoc loc, char[] name) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
691 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
692 super(ExpType.IdentifierTypeExp, loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
693 this.name = name; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
694 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
695 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
696 protected this(ExpType t, SLoc loc) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
697 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
698 super(t, loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
699 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
700 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
701 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
702 class PointerTypeExp : IdentifierTypeExp |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
703 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
704 this(IdentifierTypeExp pointerOf) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
705 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
706 super(ExpType.PointerTypeExp, pointerOf.loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
707 this.pointerOf = pointerOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
708 this.name = pointerOf.name; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
709 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
710 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
711 override DType type() |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
712 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
713 return pointerOf.type.getPointerTo(); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
714 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
715 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
716 Identifier pointerOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
717 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
718 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
719 class StaticArrayTypeExp : IdentifierTypeExp |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
720 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
721 this(IdentifierTypeExp arrayOf, IntegerLit size) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
722 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
723 super(ExpType.StaticArrayTypeExp, arrayOf.loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
724 this.arrayOf = arrayOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
725 this.size = Integer.parse(size.get); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
726 this.name = arrayOf.name; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
727 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
728 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
729 override DType type() |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
730 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
731 return arrayOf.type.getAsStaticArray(size); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
732 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
733 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
734 Identifier arrayOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
735 int size; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
736 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
737 private DType myType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
738 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
739 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
740 class ArrayTypeExp : IdentifierTypeExp |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
741 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
742 this(IdentifierTypeExp arrayOf) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
743 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
744 super(ExpType.ArrayTypeExp, arrayOf.loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
745 this.arrayOf = arrayOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
746 this.name = arrayOf.name; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
747 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
748 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
749 override DType type() |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
750 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
751 return arrayOf.type.getAsArray(); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
752 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
753 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
754 Identifier arrayOf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
755 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
756 private DType myType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
757 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
758 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
759 class FunctionTypeExp : IdentifierTypeExp |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
760 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
761 this(IdentifierTypeExp returnType, VarDecl[] decls) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
762 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
763 super(ExpType.FunctionTypeExp, returnType.loc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
764 this.returnType = returnType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
765 this.decls = decls; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
766 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
767 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
768 override DType type() |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
769 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
770 if (myType) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
771 return myType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
772 auto t = new DFunction(returnType); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
773 t.returnType = returnType.type; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
774 foreach (decl ; decls) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
775 t.params ~= decl.identifier.type; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
776 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
777 myType = t.getPointerTo; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
778 return myType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
779 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
780 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
781 VarDecl[] decls; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
782 IdentifierTypeExp returnType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
783 private DType myType; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
784 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
785 |
185
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
786 class ArrayLiteralExp : Exp |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
787 { |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
788 this(Exp[] exps, SLoc begin, SLoc end) |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
789 { |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
790 super(ExpType.ArrayLiteralExp, begin); |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
791 this.exps = exps; |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
792 this.begin = begin; |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
793 this.end = end; |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
794 } |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
795 |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
796 override DType type() |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
797 { |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
798 return exps[0].type.getAsStaticArray(exps.length); |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
799 } |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
800 |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
801 Exp[] exps; |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
802 SLoc begin, end; |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
803 } |
7b274cfdc1dc
Added support for array literals. Codegen is broken, though.
Anders Johnsen <skabet@gmail.com>
parents:
183
diff
changeset
|
804 |