Mercurial > projects > dang
annotate ast/Decl.d @ 194:08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Also added support for alias.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 29 Jul 2008 13:54:44 +0200 |
parents | 50b98a06a200 |
children |
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, |
194
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
26 AliasDecl, |
1 | 27 } |
28 | |
29 class Decl | |
30 { | |
31 this(DeclType declType) | |
32 { | |
33 this.declType = declType; | |
34 } | |
35 | |
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
|
36 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
|
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 } |
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
|
39 |
150 | 40 void verify(VC vc) |
41 { | |
42 } | |
43 | |
129 | 44 DType type() |
45 { | |
46 if (sym !is null) | |
47 return sym.type; | |
48 return null; | |
49 } | |
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
|
50 |
136 | 51 Identifier getIdentifier() |
52 { | |
53 switch(declType) | |
54 { | |
55 case DeclType.VarDecl: | |
56 return (cast(VarDecl)this).identifier; | |
57 case DeclType.FuncDecl: | |
58 return (cast(FuncDecl)this).identifier; | |
59 default: | |
60 assert(0, "Invalid DeclType for getting a identifier"); | |
61 } | |
62 } | |
63 | |
1 | 64 DeclType declType; |
65 Scope env; | |
129 | 66 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
|
67 Attribute att; |
1 | 68 } |
69 | |
129 | 70 class DummyDecl : Decl |
71 { | |
72 this() | |
73 { | |
74 super(DeclType.DummyDecl); | |
75 } | |
76 } | |
77 | |
1 | 78 class VarDecl : Decl |
79 { | |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
170
diff
changeset
|
80 this(IdentifierTypeExp type, Identifier identifier, |
1 | 81 Exp e = null) |
82 { | |
83 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
|
84 this.varType = type; |
1 | 85 this.identifier = identifier; |
86 this.init = e; | |
87 } | |
88 | |
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
|
89 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
|
90 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
91 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
|
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 |
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
|
94 Identifier varType, identifier; |
1 | 95 Exp init; |
96 } | |
97 | |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
98 class ImportDecl : Decl |
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 this() |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
101 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
102 super(DeclType.ImportDecl); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
103 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
104 |
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
|
105 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
|
106 { |
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 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 } |
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
|
113 |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
114 bool isStatic = false; |
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[] packages; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
117 Identifier name; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
118 Identifier aliasedName; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
119 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
120 Identifier[2][] explicitSymbols; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
121 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
93
diff
changeset
|
122 |
1 | 123 class FuncDecl : Decl |
124 { | |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
170
diff
changeset
|
125 this(IdentifierTypeExp type, Identifier identifier) |
1 | 126 { |
127 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
|
128 this.returnType = type; |
1 | 129 this.identifier = identifier; |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
130 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
131 |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
170
diff
changeset
|
132 void addParam(IdentifierTypeExp type, Identifier name = null) |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
133 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
134 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
|
135 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
136 |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
137 void setBody(CompoundStatement stmts) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
138 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
139 statements = stmts.statements; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
140 emptyFunction = false; |
1 | 141 } |
142 | |
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 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
|
144 { |
129 | 145 /* |
146 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
|
147 { |
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
|
148 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
|
149 { |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
150 VarDecl[] funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
151 auto i = new Identifier("ret.val"); |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
152 i.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 var.env = env; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
157 funcArgs ~= var; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
158 funcArgs ~= this.funcArgs; |
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 env.find(identifier).setType(t); |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
163 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
|
164 |
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
165 myType = null; |
60
2451f0904bf6
Dumping Ast with AstPrinter is now possible again! :)
Anders Johnsen <skabet@gmail.com>
parents:
56
diff
changeset
|
166 } |
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 } |
129 | 168 */ |
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 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
170 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
|
171 funcArg.simplify(); |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
102
diff
changeset
|
172 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
|
173 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
|
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:
53
diff
changeset
|
175 |
150 | 176 override void verify(VC vc) |
177 { | |
178 foreach (stmt; statements) | |
179 stmt.verify(vc); | |
180 } | |
181 | |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
182 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
|
183 { |
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 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
|
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 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
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 |
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
|
201 Identifier returnType, identifier; |
1 | 202 VarDecl[] funcArgs; |
203 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
|
204 bool sret = false; |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
64
diff
changeset
|
205 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
|
206 private DFunction myType; |
1 | 207 } |
208 | |
22 | 209 class StructDecl : Decl |
210 { | |
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
|
211 this(Identifier identifier) |
22 | 212 { |
213 super(DeclType.StructDecl); | |
214 this.identifier = identifier; | |
215 } | |
216 | |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
217 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
|
218 { |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
219 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
|
220 } |
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
|
221 |
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
|
222 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
|
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 } |
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
|
225 |
150 | 226 override void verify(VC vc) |
227 { | |
228 foreach (decl; decls) | |
229 decl.verify(vc); | |
230 } | |
231 | |
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
|
232 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
|
233 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
234 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
|
235 } |
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
|
236 |
22 | 237 Identifier identifier; |
102
cd066f3b539a
Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents:
101
diff
changeset
|
238 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
|
239 private DType myType; |
22 | 240 } |
241 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
242 class ClassDecl : Decl |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
243 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
244 this(Identifier identifier) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
245 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
246 super(DeclType.ClassDecl); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
247 this.identifier = identifier; |
170
09150374ddf9
added a __vptr to all classes.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
248 |
09150374ddf9
added a __vptr to all classes.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
249 auto name = new Identifier(identifier.loc, "__vptr"); |
173
50b98a06a200
Start of support for virtual functions
Anders Halager <halager@gmail.com>
parents:
172
diff
changeset
|
250 auto type = new IdentifierTypeExp(identifier.loc, "byte"); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
170
diff
changeset
|
251 auto p_type = new PointerTypeExp(type); |
170
09150374ddf9
added a __vptr to all classes.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
252 decls ~= new VarDecl(p_type, name, null); |
144
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
255 void addMember(Decl decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
256 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
257 decls ~= decl; |
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
260 void addBaseClass(Identifier identifier) |
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 baseClasses ~= identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
263 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
264 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
265 void simplify() |
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
269 override DType type() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
270 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
271 return env.findType(identifier.get); |
144
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 Identifier identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
275 Identifier[] baseClasses; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
276 Decl[] decls; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
277 private DType myType; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
278 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
279 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
280 class InterfaceDecl : Decl |
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 this(Identifier identifier) |
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 super(DeclType.InterfaceDecl); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
285 this.identifier = identifier; |
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
288 void addMember(Decl decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
289 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
290 decls ~= decl; |
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
293 void addBaseClass(Identifier identifier) |
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 baseClasses ~= identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
296 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
297 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
298 void simplify() |
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
302 override DType type() |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
303 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
304 return env.findType(identifier.get); |
144
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 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
307 Identifier identifier; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
308 Identifier[] baseClasses; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
309 Decl[] decls; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
310 private DType myType; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
311 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
312 |
194
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
313 class AliasDecl : Decl |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
314 { |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
315 this(Decl decl) |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
316 { |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
317 super(DeclType.AliasDecl); |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
318 this.decl = decl; |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
319 } |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
320 |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
321 Decl decl; |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
322 } |
08f68d684047
Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents:
173
diff
changeset
|
323 |