Mercurial > projects > dang
annotate ast/Exp.d @ 158:57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 00:33:58 +0200 |
parents | a14ac9e5c858 |
children | 6cb2f4201e2a |
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, |
1 | 23 IntegerLit, |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
48
diff
changeset
|
24 MemberReference, |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
25 Index, |
1 | 26 Identifier, |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
27 ArrayIdentifier, |
136 | 28 StaticArrayIdentifier, |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
29 PointerIdentifier, |
1 | 30 AssignExp, |
31 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
|
32 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
|
33 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
|
34 NewExp, |
1 | 35 } |
36 | |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
37 abstract class Exp |
1 | 38 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
39 this(ExpType expType, SLoc loc) |
1 | 40 { |
41 this.expType = expType; | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
42 this.loc = loc; |
1 | 43 } |
44 | |
129 | 45 /** |
46 Get the fully qualified name for the expression (if it can be resolved to | |
47 one) - otherwise null is returned | |
48 **/ | |
49 char[] getFQN() { return null; } | |
50 | |
51 /// The same as getFQN, except that the name is mangled | |
52 char[] getMangledFQN() { return null; } | |
53 | |
54 /** | |
55 Try to get the symbol the expression represents. | |
56 | |
57 Returns null for most expressions as they don't represent any symbol. | |
58 Identifiers and member references can have a sensible value. | |
59 **/ | |
60 Symbol getSymbol() { return null; } | |
61 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
62 /// Get the type of the expression |
110 | 63 abstract DType type(); |
58 | 64 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
65 /// Indicates which type the expression is - to avoid a lot of casts |
1 | 66 ExpType expType; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
67 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
68 /// The environment of the expression |
1 | 69 Scope env; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
70 |
129 | 71 Symbol symbol; |
72 | |
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
|
73 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
|
74 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
75 /** |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
76 The "main" location of the expression. |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
77 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
|
78 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
|
79 **/ |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
80 SourceLocation loc; |
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 /// Return the starting location of this expression |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
83 SourceLocation startLoc() { return loc; } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
84 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
85 /// Get the full extents of the expression |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
86 SourceRange sourceRange() { return SourceRange(loc, loc + 1); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
87 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
88 /// Do some simplifications |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
89 Exp simplify() { return this; } |
1 | 90 } |
91 | |
92 class CallExp : Exp | |
93 { | |
94 this(Exp exp, Exp[] args) | |
95 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
96 super(ExpType.CallExp, exp.loc); |
1 | 97 this.exp = exp; |
98 this.args = args; | |
99 } | |
100 | |
58 | 101 override DType type() |
102 { | |
103 DFunction f = cast(DFunction)exp.type(); | |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
58
diff
changeset
|
104 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
|
105 return f.returnType; |
58 | 106 } |
107 | |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
108 override CallExp simplify() |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
109 { |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
110 foreach (ref arg; args) |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
111 arg = arg.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
112 exp = exp.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
113 return this; |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
114 } |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
115 |
1 | 116 Exp exp; |
117 Exp[] args; | |
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
|
118 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
|
119 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
120 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
121 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
122 SourceRange res = exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
123 if (args.length > 0) |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
124 res = res + args[$ - 1].sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
125 return res; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
126 } |
1 | 127 } |
128 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
129 class AssignExp : BinaryExp |
1 | 130 { |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
131 this(SLoc op_loc, Operator op, Exp identifier, Exp exp) |
1 | 132 { |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
133 super(ExpType.AssignExp, op_loc, op, identifier, exp); |
1 | 134 this.identifier = identifier; |
135 this.exp = exp; | |
136 } | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
137 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
138 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
|
139 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
140 identifier = identifier.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
141 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
|
142 |
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
|
143 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
|
144 } |
1 | 145 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
146 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
147 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
148 return identifier.sourceRange + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
149 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
150 |
58 | 151 override DType type() { return identifier.type(); } |
152 | |
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
|
153 Exp identifier; |
1 | 154 Exp exp; |
155 } | |
156 | |
157 class BinaryExp : Exp | |
158 { | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
159 public enum Operator |
1 | 160 { |
48
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
161 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
|
162 AddAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
163 SubAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
164 MulAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
165 DivAssign, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
166 ModAssign, |
48
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
167 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
168 Eq, Ne, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
169 |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
170 Lt, Le, |
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
171 Gt, Ge, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
172 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
173 Add, Sub, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
174 Mul, Div, Mod, |
123 | 175 |
176 LeftShift, RightShift, UnsignedRightShift, | |
125
d604152de1eb
Support shifts and binary logical operators in codegen
Anders Halager <halager@gmail.com>
parents:
123
diff
changeset
|
177 |
d604152de1eb
Support shifts and binary logical operators in codegen
Anders Halager <halager@gmail.com>
parents:
123
diff
changeset
|
178 And, Or, Xor, |
1 | 179 } |
180 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
181 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
|
182 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
183 this(SLoc op_loc, Operator op, Exp left, Exp right) |
1 | 184 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
185 super(ExpType.Binary, op_loc); |
1 | 186 this.op = op; |
187 this.left = left; | |
188 this.right = right; | |
189 } | |
190 | |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
191 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
|
192 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
197 } |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
125
diff
changeset
|
198 |
58 | 199 override DType type() |
200 { | |
201 if (myType) | |
202 return myType; | |
203 | |
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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 { |
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
|
211 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
|
212 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
|
213 } |
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
|
214 |
58 | 215 DType l = left.type; |
216 DType r = right.type; | |
217 if (l is r) | |
218 myType = l; | |
219 else if (l.hasImplicitConversionTo(r)) | |
220 myType = r; | |
221 else if (r.hasImplicitConversionTo(l)) | |
222 myType = l; | |
223 else | |
224 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
|
225 return myType; |
58 | 226 } |
227 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
228 override SLoc startLoc() { return left.startLoc(); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
229 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
230 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
231 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
232 return left.sourceRange + right.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
233 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
234 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
235 char[] resultType() |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
236 { |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
237 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
|
238 return "bool"; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
239 return null; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
240 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
241 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
242 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
|
243 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
244 left = left.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
245 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
|
246 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
|
247 } |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
248 |
1 | 249 Operator op; |
250 Exp left, right; | |
58 | 251 private DType myType; |
1 | 252 } |
253 | |
254 class NegateExp : Exp | |
255 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
256 this(SLoc op, Exp exp) |
1 | 257 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
258 super(ExpType.Negate, op); |
1 | 259 this.exp = exp; |
260 } | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
261 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
262 override NegateExp simplify() |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
263 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
264 exp = exp.simplify(); |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
265 return this; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
266 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
267 |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
268 override DType type() { return exp.type(); } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
269 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
270 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
271 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
272 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
273 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
274 |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
275 public Exp exp; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
276 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
277 |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
278 class DerefExp : Exp |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
279 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
280 this(SLoc op, Exp exp) |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
281 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
282 super(ExpType.Deref, op); |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
72
diff
changeset
|
283 this.exp = exp; |
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 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
286 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
|
287 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
288 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
|
289 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
|
290 } |
1 | 291 |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
79
diff
changeset
|
292 override DType type() |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
98
diff
changeset
|
293 { |
129 | 294 return exp.type().asPointer().pointerOf; |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
79
diff
changeset
|
295 } |
58 | 296 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
297 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
298 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
299 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
300 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
301 |
1 | 302 public Exp exp; |
303 } | |
304 | |
305 class IntegerLit : Exp | |
306 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
307 this(SLoc loc, char[] t) |
1 | 308 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
309 super(ExpType.IntegerLit, loc); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
310 range = SourceRange(loc, loc + t.length); |
111
c658172ca8a0
Parsing basic integers and floats.
Anders Johnsen <skabet@gmail.com>
parents:
110
diff
changeset
|
311 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
|
312 } |
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
|
313 |
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
|
314 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
|
315 { |
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
|
316 return name; |
1 | 317 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
318 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
319 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
|
320 { |
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
|
321 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
|
322 } |
1 | 323 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
324 override DType type() |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
325 { |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
326 switch(number.type) |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
327 { |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
328 case NumberType.Int: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
329 return DType.Int; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
330 case NumberType.Long: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
331 return DType.Long; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
332 case NumberType.ULong: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
333 return DType.ULong; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
334 case NumberType.Double: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
335 return DType.Double; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
336 case NumberType.Real: |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
337 return DType.Real; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
338 } |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
339 } |
58 | 340 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
341 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
342 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
343 return range; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
344 } |
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
|
345 |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
346 Number number; |
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
347 |
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
|
348 char[] name; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
349 private SourceRange range; |
1 | 350 } |
351 | |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
48
diff
changeset
|
352 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
|
353 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
354 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
|
355 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
360 |
129 | 361 override char[] getFQN() |
362 { | |
363 return getSymbol().getFQN(); | |
364 } | |
365 | |
366 override char[] getMangledFQN() | |
367 { | |
368 return target.type.mangle() ~ child.getMangledFQN(); | |
369 } | |
370 | |
371 override Symbol getSymbol() | |
372 { | |
373 auto s = target.getSymbol(); | |
374 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
|
375 return s.findMembers(child.get)[0]; |
129 | 376 return null; |
377 } | |
378 | |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
379 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
|
380 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
381 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
|
382 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
|
383 } |
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
|
384 |
58 | 385 override DType type() |
386 { | |
387 if (myType) | |
388 return myType; | |
389 | |
390 DStruct st = cast(DStruct)target.type; | |
391 assert(st, "Only structs have members"); | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
392 if (auto t = st.typeOf(child.name)) |
58 | 393 myType = t; |
394 // no error reporting here | |
395 else assert(0, "Referencing non-existant member"); | |
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
|
396 |
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
|
397 return myType; |
58 | 398 } |
399 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
400 override SLoc startLoc() { return target.startLoc(); } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
401 |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
402 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
403 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
404 return target.sourceRange + child.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
405 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
406 |
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
|
407 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
|
408 Exp target; |
58 | 409 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
|
410 } |
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
|
411 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
412 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
|
413 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
414 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
|
415 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
416 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
|
417 this.target = target; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
418 this.left_bracket = left_bracket; |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
419 this.index = index; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
420 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
|
421 } |
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
|
422 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
423 override DType type() |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
424 { |
85
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
425 DType type = target.type(); |
136 | 426 if (type.isStaticArray()) |
427 return type.asStaticArray().arrayOf; | |
85
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
428 else if (type.isPointer()) |
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
429 return type.asPointer().pointerOf; |
9375bd975730
Allow indexing of pointers also
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
430 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
|
431 } |
58 | 432 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
433 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
434 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
435 return target.sourceRange + SourceRange(right_bracket); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
436 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
437 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
438 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
|
439 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
440 target = target.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
441 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
|
442 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
|
443 } |
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
|
444 |
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
|
445 Exp target; |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
446 Exp index; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
447 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
|
448 } |
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
|
449 |
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
|
450 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
|
451 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
452 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
|
453 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 } |
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
|
458 |
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
|
459 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
|
460 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
139
diff
changeset
|
461 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
|
462 } |
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
|
463 |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
464 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
|
465 { |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
466 castType = castType.simplify(); |
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
467 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
|
468 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
|
469 } |
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
|
470 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
471 override SourceRange sourceRange() |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
472 { |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
473 return SourceRange(loc) + exp.sourceRange; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
474 } |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
475 |
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
|
476 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
|
477 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
|
478 } |
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
|
479 |
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
|
480 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
|
481 { |
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
|
482 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
|
483 { |
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
|
484 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
|
485 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
|
486 } |
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
|
487 |
110 | 488 override DType type() { return null; } |
489 | |
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
|
490 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
|
491 } |
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
|
492 |
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
|
493 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
|
494 { |
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
|
495 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
|
496 { |
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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 } |
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
|
502 |
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
|
503 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
|
504 { |
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
|
505 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
|
506 } |
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
|
507 |
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
|
508 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
|
509 Identifier 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
|
510 } |
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
|
511 |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
512 class PointerIdentifier : Identifier |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
513 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
514 this(Identifier pointerOf) |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
515 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
516 super(ExpType.PointerIdentifier, pointerOf.loc); |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
517 this.pointerOf = pointerOf; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
518 this.name = pointerOf.name; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
519 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
520 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
521 override DType type() |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
522 { |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
523 return pointerOf.type.getPointerTo(); |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
524 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
525 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
526 Identifier pointerOf; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
527 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
528 |
136 | 529 class StaticArrayIdentifier : Identifier |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
530 { |
81 | 531 this(Identifier arrayOf, IntegerLit size) |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
532 { |
136 | 533 super(ExpType.StaticArrayIdentifier, arrayOf.loc); |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
534 this.arrayOf = arrayOf; |
81 | 535 this.size = Integer.parse(size.get); |
536 this.name = arrayOf.name; | |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
537 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
538 |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
539 override DType type() |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
540 { |
136 | 541 return arrayOf.type.getAsStaticArray(size); |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
542 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
543 |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
544 Identifier arrayOf; |
81 | 545 int size; |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
546 |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
547 private DType myType; |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
548 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
549 |
136 | 550 class ArrayIdentifier : Identifier |
551 { | |
552 this(Identifier arrayOf) | |
553 { | |
554 super(ExpType.ArrayIdentifier, arrayOf.loc); | |
555 this.arrayOf = arrayOf; | |
556 this.name = arrayOf.name; | |
557 } | |
558 | |
559 override DType type() | |
560 { | |
561 return arrayOf.type.getAsArray(); | |
562 } | |
563 | |
564 Identifier arrayOf; | |
565 | |
566 private DType myType; | |
567 } | |
568 | |
1 | 569 class Identifier : Exp |
570 { | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
571 this(SLoc loc, char[] name) |
1 | 572 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
573 super(ExpType.Identifier, loc); |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
574 this.name = name; |
1 | 575 } |
576 | |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
577 protected this(ExpType t, SLoc loc) |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
578 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
579 super(t, loc); |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
580 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
581 |
129 | 582 override char[] getFQN() |
583 { | |
584 return name; | |
585 } | |
586 | |
587 override char[] getMangledFQN() | |
588 { | |
589 return Integer.toString(name.length) ~ name; | |
590 } | |
591 | |
592 override Symbol getSymbol() | |
593 { | |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
139
diff
changeset
|
594 if (auto decl = env.find(this.get)) |
129 | 595 return decl.sym; |
596 else | |
597 return null; | |
598 } | |
599 | |
58 | 600 override DType type() |
601 { | |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
58
diff
changeset
|
602 if (myType !is null) |
58 | 603 return myType; |
129 | 604 else if (auto sym = getSymbol) |
605 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
|
606 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
|
607 myType = DType.Int; |
129 | 608 |
58 | 609 return myType; |
610 } | |
611 | |
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
|
612 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
|
613 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
86
diff
changeset
|
614 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
|
615 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
|
616 } |
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
|
617 |
1 | 618 char[] get() |
619 { | |
620 return name; | |
621 } | |
622 | |
623 hash_t toHash() | |
624 { | |
625 return jhash(name); | |
626 } | |
627 | |
628 int opCmp(Object o) | |
629 { | |
630 if (auto id = cast(Identifier)o) | |
631 return typeid(char[]).compare(&name, &id.name); | |
632 return 0; | |
633 } | |
634 | |
635 int opEquals(Object o) | |
636 { | |
637 if (auto id = cast(Identifier)o) | |
638 return typeid(char[]).equals(&name, &id.name); | |
639 return 0; | |
640 } | |
641 | |
139
a22e3663de89
Fixed up our simplify functions
Anders Halager <halager@gmail.com>
parents:
136
diff
changeset
|
642 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
|
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 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
|
645 } |
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
|
646 |
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
|
647 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
|
648 { |
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
|
649 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
|
650 } |
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
|
651 |
1 | 652 char[] name; |
58 | 653 private DType myType; |
1 | 654 } |
655 |