Mercurial > projects > dang
annotate ast/Decl.d @ 136:2be29b296081
Lots of changes:
- Parsing classes and interfaces
- Fixed some seg faults in sema
- Supporting "private" to some extend
- And a lot of other small fixes
author | johnsen@johnsen-laptop |
---|---|
date | Fri, 11 Jul 2008 21:47:57 +0200 |
parents | ed815b31479b |
children | 6e6355fb5f0f |
rev | line source |
---|---|
1 | 1 module ast.Decl; |
2 | |
3 import ast.Exp, | |
4 ast.Stmt; | |
5 | |
6 import lexer.Token; | |
7 | |
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:
53
diff
changeset
|
8 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:
53
diff
changeset
|
9 |
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:
86
diff
changeset
|
10 import sema.Scope, |
129 | 11 sema.Symbol, |
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
|
12 sema.DType, |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
13 basic.SmallArray, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
14 basic.Attribute; |
1 | 15 |
16 enum DeclType | |
17 { | |
18 VarDecl, | |
129 | 19 DummyDecl, |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
20 ImportDecl, |
1 | 21 FuncDecl, |
22 | 22 StructDecl, |
1 | 23 } |
24 | |
25 class Decl | |
26 { | |
27 this(DeclType declType) | |
28 { | |
29 this.declType = declType; | |
30 } | |
31 | |
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:
53
diff
changeset
|
32 void 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:
53
diff
changeset
|
33 { |
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:
53
diff
changeset
|
34 } |
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:
53
diff
changeset
|
35 |
129 | 36 DType type() |
37 { | |
38 if (sym !is null) | |
39 return sym.type; | |
40 return null; | |
41 } | |
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
|
42 |
136 | 43 Identifier getIdentifier() |
44 { | |
45 switch(declType) | |
46 { | |
47 case DeclType.VarDecl: | |
48 return (cast(VarDecl)this).identifier; | |
49 case DeclType.FuncDecl: | |
50 return (cast(FuncDecl)this).identifier; | |
51 default: | |
52 assert(0, "Invalid DeclType for getting a identifier"); | |
53 } | |
54 } | |
55 | |
1 | 56 DeclType declType; |
57 Scope env; | |
129 | 58 Symbol sym; |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
59 Attribute att; |
1 | 60 } |
61 | |
129 | 62 class DummyDecl : Decl |
63 { | |
64 this() | |
65 { | |
66 super(DeclType.DummyDecl); | |
67 } | |
68 } | |
69 | |
1 | 70 class VarDecl : Decl |
71 { | |
72 this(Identifier type, Identifier identifier, | |
73 Exp e = null) | |
74 { | |
75 super(DeclType.VarDecl); | |
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
|
76 this.varType = type; |
1 | 77 this.identifier = identifier; |
78 this.init = e; | |
79 } | |
80 | |
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:
53
diff
changeset
|
81 void 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:
53
diff
changeset
|
82 { |
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:
53
diff
changeset
|
83 } |
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:
53
diff
changeset
|
84 |
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
|
85 override DType type() |
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
|
86 { |
129 | 87 return env.findType(varType); |
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
|
88 } |
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
|
89 |
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
|
90 Identifier varType, identifier; |
1 | 91 Exp init; |
92 } | |
93 | |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
94 class ImportDecl : Decl |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
95 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
96 this() |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
97 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
98 super(DeclType.ImportDecl); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
99 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
100 |
101
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
101 char[] get() |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
102 { |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
103 char[] res; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
104 foreach(i ; packages) |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
105 res ~= i.get ~ "."; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
106 res ~= name.get; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
107 return res; |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
108 } |
fea8d61a2451
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents:
99
diff
changeset
|
109 |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
110 bool isStatic = false; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
111 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
112 Identifier[] packages; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
113 Identifier name; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
114 Identifier aliasedName; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
115 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
116 Identifier[2][] explicitSymbols; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
117 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
118 |
1 | 119 class FuncDecl : Decl |
120 { | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
121 this(Identifier type, Identifier identifier) |
1 | 122 { |
123 super(DeclType.FuncDecl); | |
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
|
124 this.returnType = type; |
1 | 125 this.identifier = identifier; |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
126 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
127 |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
128 void addParam(Identifier type, Identifier name = null) |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
129 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
130 funcArgs ~= new VarDecl(type, name, null); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
131 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
132 |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
133 void setBody(CompoundStatement stmts) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
134 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
135 statements = stmts.statements; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
136 emptyFunction = false; |
1 | 137 } |
138 | |
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:
53
diff
changeset
|
139 void 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:
53
diff
changeset
|
140 { |
129 | 141 /* |
142 if(auto t = env.find(identifier).type.asFunction()) | |
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:
53
diff
changeset
|
143 { |
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
|
144 if(auto s = cast(DStruct)t.returnType) |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
145 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
146 VarDecl[] funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
147 auto i = new Identifier("ret.val"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
148 i.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
149 i.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
|
150 i.env.find(i).setType( s ); |
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
|
151 auto var = new VarDecl(returnType, i); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
152 var.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
153 funcArgs ~= var; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
154 funcArgs ~= this.funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
155 this.funcArgs = funcArgs; |
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
|
156 t.returnType = DType.Void; |
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
|
157 this.returnType = new Identifier("void"); |
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
|
158 env.find(identifier).setType(t); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
159 sret = true; |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
160 |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
161 myType = null; |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
162 } |
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:
53
diff
changeset
|
163 } |
129 | 164 */ |
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:
53
diff
changeset
|
165 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
166 foreach (funcArg; funcArgs) |
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:
53
diff
changeset
|
167 funcArg.simplify(); |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
168 foreach (stmt; 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:
53
diff
changeset
|
169 stmt.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:
53
diff
changeset
|
170 } |
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:
53
diff
changeset
|
171 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
172 override DFunction type() |
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
|
173 { |
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
|
174 if (myType !is null) |
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
|
175 return myType; |
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
|
176 |
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
|
177 auto t = new DFunction(identifier); |
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
|
178 t.returnType = env.findType(returnType); |
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
|
179 SmallArray!(DType) array; |
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
|
180 foreach (a; funcArgs) |
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
|
181 array ~= a.type(); |
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
|
182 t.params = array.safe(); |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
183 t.firstParamIsReturnValue = this.sret; |
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
|
184 myType = t; |
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
|
185 return myType; |
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
|
186 } |
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
|
187 |
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
|
188 Identifier returnType, identifier; |
1 | 189 VarDecl[] funcArgs; |
190 Stmt[] 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:
53
diff
changeset
|
191 bool sret = false; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
192 bool emptyFunction = true; |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
193 private DFunction myType; |
1 | 194 } |
195 | |
22 | 196 class StructDecl : Decl |
197 { | |
53
da551f90e03f
Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents:
44
diff
changeset
|
198 this(Identifier identifier) |
22 | 199 { |
200 super(DeclType.StructDecl); | |
201 this.identifier = identifier; | |
202 } | |
203 | |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
204 void addMember(Decl decl) |
53
da551f90e03f
Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents:
44
diff
changeset
|
205 { |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
206 decls ~= decl; |
53
da551f90e03f
Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents:
44
diff
changeset
|
207 } |
da551f90e03f
Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents:
44
diff
changeset
|
208 |
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:
53
diff
changeset
|
209 void 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:
53
diff
changeset
|
210 { |
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:
53
diff
changeset
|
211 } |
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:
53
diff
changeset
|
212 |
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
|
213 override DType type() |
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
|
214 { |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
215 return env.findType(identifier); |
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
|
216 } |
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
|
217 |
22 | 218 Identifier identifier; |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
219 Decl[] decls; |
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
|
220 private DType myType; |
22 | 221 } |
222 |