annotate ast/Exp.d @ 192:fda35d57847e

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