annotate ast/Exp.d @ 129:ed815b31479b

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