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