Mercurial > projects > dang
annotate ast/Decl.d @ 163:362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 16:50:47 +0200 |
parents | 6c5a3c0bb4fb |
children | 09150374ddf9 |
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, |
150 | 13 sema.VC, |
126
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.SmallArray, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
15 basic.Attribute; |
1 | 16 |
17 enum DeclType | |
18 { | |
19 VarDecl, | |
129 | 20 DummyDecl, |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
21 ImportDecl, |
1 | 22 FuncDecl, |
22 | 23 StructDecl, |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
24 ClassDecl, |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
25 InterfaceDecl, |
1 | 26 } |
27 | |
28 class Decl | |
29 { | |
30 this(DeclType declType) | |
31 { | |
32 this.declType = declType; | |
33 } | |
34 | |
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
|
35 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
|
36 { |
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
|
37 } |
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
|
38 |
150 | 39 void verify(VC vc) |
40 { | |
41 } | |
42 | |
129 | 43 DType type() |
44 { | |
45 if (sym !is null) | |
46 return sym.type; | |
47 return null; | |
48 } | |
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
|
49 |
136 | 50 Identifier getIdentifier() |
51 { | |
52 switch(declType) | |
53 { | |
54 case DeclType.VarDecl: | |
55 return (cast(VarDecl)this).identifier; | |
56 case DeclType.FuncDecl: | |
57 return (cast(FuncDecl)this).identifier; | |
58 default: | |
59 assert(0, "Invalid DeclType for getting a identifier"); | |
60 } | |
61 } | |
62 | |
1 | 63 DeclType declType; |
64 Scope env; | |
129 | 65 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
|
66 Attribute att; |
1 | 67 } |
68 | |
129 | 69 class DummyDecl : Decl |
70 { | |
71 this() | |
72 { | |
73 super(DeclType.DummyDecl); | |
74 } | |
75 } | |
76 | |
1 | 77 class VarDecl : Decl |
78 { | |
79 this(Identifier type, Identifier identifier, | |
80 Exp e = null) | |
81 { | |
82 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
|
83 this.varType = type; |
1 | 84 this.identifier = identifier; |
85 this.init = e; | |
86 } | |
87 | |
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 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
|
89 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
90 return env.findType(varType.get); |
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
|
91 } |
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
|
92 |
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
|
93 Identifier varType, identifier; |
1 | 94 Exp init; |
95 } | |
96 | |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
97 class ImportDecl : Decl |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
98 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
99 this() |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
100 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
101 super(DeclType.ImportDecl); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
102 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
103 |
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
|
104 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
|
105 { |
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 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 } |
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
|
112 |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
113 bool isStatic = false; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
114 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
115 Identifier[] packages; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
116 Identifier name; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
117 Identifier aliasedName; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
118 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
119 Identifier[2][] explicitSymbols; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
120 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
121 |
1 | 122 class FuncDecl : Decl |
123 { | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
124 this(Identifier type, Identifier identifier) |
1 | 125 { |
126 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
|
127 this.returnType = type; |
1 | 128 this.identifier = identifier; |
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 |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
131 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
|
132 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
133 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
|
134 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
135 |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
136 void setBody(CompoundStatement stmts) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
137 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
138 statements = stmts.statements; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
139 emptyFunction = false; |
1 | 140 } |
141 | |
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
|
142 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
|
143 { |
129 | 144 /* |
145 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
|
146 { |
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
|
147 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
|
148 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
149 VarDecl[] funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
150 auto i = new Identifier("ret.val"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
151 i.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 var.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
156 funcArgs ~= var; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
157 funcArgs ~= this.funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 env.find(identifier).setType(t); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
162 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
|
163 |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
164 myType = null; |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
165 } |
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
|
166 } |
129 | 167 */ |
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
|
168 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
169 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
|
170 funcArg.simplify(); |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
171 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
|
172 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
|
173 } |
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
|
174 |
150 | 175 override void verify(VC vc) |
176 { | |
177 foreach (stmt; statements) | |
178 stmt.verify(vc); | |
179 } | |
180 | |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
181 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
|
182 { |
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
|
183 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
|
184 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
|
185 |
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 auto t = new DFunction(identifier); |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
150
diff
changeset
|
187 if ( identifier.get == "this" ) |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
150
diff
changeset
|
188 t.returnType = DType.Void; |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
150
diff
changeset
|
189 else |
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
150
diff
changeset
|
190 t.returnType = env.findType(returnType.get); |
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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 } |
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
|
199 |
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
|
200 Identifier returnType, identifier; |
1 | 201 VarDecl[] funcArgs; |
202 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
|
203 bool sret = false; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
204 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
|
205 private DFunction myType; |
1 | 206 } |
207 | |
22 | 208 class StructDecl : Decl |
209 { | |
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
|
210 this(Identifier identifier) |
22 | 211 { |
212 super(DeclType.StructDecl); | |
213 this.identifier = identifier; | |
214 } | |
215 | |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
216 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
|
217 { |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
218 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
|
219 } |
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
|
220 |
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
|
221 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
|
222 { |
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
|
223 } |
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
|
224 |
150 | 225 override void verify(VC vc) |
226 { | |
227 foreach (decl; decls) | |
228 decl.verify(vc); | |
229 } | |
230 | |
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
|
231 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
|
232 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
233 return env.findType(identifier.get); |
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
|
234 } |
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
|
235 |
22 | 236 Identifier identifier; |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
237 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
|
238 private DType myType; |
22 | 239 } |
240 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
241 class ClassDecl : Decl |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
242 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
243 this(Identifier identifier) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
244 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
245 super(DeclType.ClassDecl); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
246 this.identifier = identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
247 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
248 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
249 void addMember(Decl decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
250 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
251 decls ~= decl; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
252 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
253 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
254 void addBaseClass(Identifier identifier) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
255 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
256 baseClasses ~= identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
257 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
258 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
259 void simplify() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
260 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
261 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
262 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
263 override DType type() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
264 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
265 return env.findType(identifier.get); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
266 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
267 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
268 Identifier identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
269 Identifier[] baseClasses; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
270 Decl[] decls; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
271 private DType myType; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
272 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
273 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
274 class InterfaceDecl : Decl |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
275 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
276 this(Identifier identifier) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
277 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
278 super(DeclType.InterfaceDecl); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
279 this.identifier = identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
280 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
281 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
282 void addMember(Decl decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
283 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
284 decls ~= decl; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
285 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
286 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
287 void addBaseClass(Identifier identifier) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
288 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
289 baseClasses ~= identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
290 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
291 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
292 void simplify() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
293 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
294 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
295 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
296 override DType type() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
297 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
298 return env.findType(identifier.get); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
299 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
300 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
301 Identifier identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
302 Identifier[] baseClasses; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
303 Decl[] decls; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
304 private DType myType; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
305 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
306 |