Mercurial > projects > dang
annotate sema/ScopeBuilder.d @ 180:29324df1d649
Fixed a but that did't allow type-only params.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 01:34:12 +0200 |
parents | dc9bf56b7ace |
children |
rev | line source |
---|---|
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
|
1 module sema.ScopeBuilder; |
1 | 2 |
14 | 3 import tango.io.Stdout, |
4 tango.core.Array : find; | |
1 | 5 |
26 | 6 public |
129 | 7 import sema.Scope, |
8 sema.Symbol; | |
1 | 9 |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
56
diff
changeset
|
10 import sema.Visitor, |
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
56
diff
changeset
|
11 basic.SmallArray; |
1 | 12 |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
13 class SymbolFactory |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
14 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
15 void put(Symbol symbol, DType type) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
16 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
17 types[type] = symbol; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
18 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
19 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
20 Symbol get(Symbol owner, DType type, Identifier i, Decl decl) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
21 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
22 if (type in types) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
23 return owner.createAlias(i.get, types[type], decl); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
24 else |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
25 return owner.createMember(i.get, type, decl); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
26 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
27 |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
28 Symbol[DType] types; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
29 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
30 |
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
|
31 class ForwardReference : Visitor!(void) |
1 | 32 { |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
33 this(SymbolFactory sf) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
34 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
35 this.sf = sf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
36 } |
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
|
37 override void visit(Module[] modules) |
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
|
38 { |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
39 (new TypeBuilder(sf)).visit(modules); |
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
|
40 this.modules = modules; |
129 | 41 inFunctionBodyStack.push(false); |
42 foreach (mod; modules) | |
43 { | |
44 current = mod; | |
45 foreach (decl; mod.decls) | |
46 visitDecl(decl); | |
47 } | |
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
|
48 } |
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
|
49 |
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:
45
diff
changeset
|
50 override void visitFuncDecl(FuncDecl d) |
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:
45
diff
changeset
|
51 { |
129 | 52 |
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:
59
diff
changeset
|
53 visitExp(d.returnType); |
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:
45
diff
changeset
|
54 visitExp(d.identifier); |
162
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
55 |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
56 d.sym = current.symbol.createMember( |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
57 d.identifier.get, |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
58 d.type, |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
59 d); |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
60 |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
61 auto old = current.symbol; |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
62 current.symbol = d.sym; |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
63 |
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:
45
diff
changeset
|
64 foreach (arg; d.funcArgs) |
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:
45
diff
changeset
|
65 visitDecl(arg); |
129 | 66 |
67 inFunctionBodyStack.push(true); | |
68 | |
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:
45
diff
changeset
|
69 foreach (stmt; d.statements) |
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:
45
diff
changeset
|
70 visitStmt(stmt); |
59
1d6f4ad38a91
Make most of the tests pass again
Anders Halager <halager@gmail.com>
parents:
56
diff
changeset
|
71 |
129 | 72 inFunctionBodyStack.pop(); |
73 | |
162
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
74 current.symbol = old; |
0f38f1a0f06f
Fixed symbol for a functions members.
Anders Johnsen <skabet@gmail.com>
parents:
158
diff
changeset
|
75 |
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:
45
diff
changeset
|
76 } |
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:
45
diff
changeset
|
77 |
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:
45
diff
changeset
|
78 override void visitVarDecl(VarDecl d) |
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:
45
diff
changeset
|
79 { |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
81
diff
changeset
|
80 visitExp(d.varType); |
180
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
81 if(d.identifier) |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
82 visitExp(d.identifier); |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
81
diff
changeset
|
83 |
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:
45
diff
changeset
|
84 if (d.init) |
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:
45
diff
changeset
|
85 visitExp(d.init); |
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:
45
diff
changeset
|
86 |
180
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
87 if(d.identifier) |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
88 { |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
89 DType t = typeOf(d.varType, d.env); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
90 d.sym = sf.get(current.symbol, t, d.identifier, d); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
91 d.sym.type = t; |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
92 } |
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:
45
diff
changeset
|
93 } |
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:
45
diff
changeset
|
94 |
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:
45
diff
changeset
|
95 override void visitStructDecl(StructDecl s) |
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:
45
diff
changeset
|
96 { |
129 | 97 auto old = current.symbol; |
98 current.symbol = s.sym; | |
99 inFunctionBodyStack.push(false); | |
100 super.visitStructDecl(s); | |
101 inFunctionBodyStack.pop(); | |
102 current.symbol = old; | |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
103 } |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
104 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
105 override void visitClassDecl(ClassDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
106 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
107 auto old = current.symbol; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
108 current.symbol = s.sym; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
109 inFunctionBodyStack.push(false); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
110 super.visitClassDecl(s); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
111 inFunctionBodyStack.pop(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
112 current.symbol = old; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
113 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
114 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
115 override void visitInterfaceDecl(InterfaceDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
116 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
117 auto old = current.symbol; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
118 current.symbol = s.sym; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
119 inFunctionBodyStack.push(false); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
120 super.visitInterfaceDecl(s); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
121 inFunctionBodyStack.pop(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
122 current.symbol = old; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
123 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
124 |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
125 override void visitFunctionTypeExp(FunctionTypeExp f) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
126 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
127 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
128 |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
129 DType typeOf(Identifier id, Scope sc) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
130 { |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
131 if(auto i = cast(PointerTypeExp)id) |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
132 return (typeOf(i.pointerOf, sc)).getPointerTo(); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
133 else if(auto i = cast(StaticArrayTypeExp)id) |
136 | 134 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
135 else if(auto i = cast(FunctionTypeExp)id) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
136 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
137 auto d = new DFunction(id); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
138 d.returnType = typeOf(i.returnType, sc); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
139 foreach (decl ; i.decls) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
140 d.params ~= typeOf(decl.varType, sc); |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
141 return d.getPointerTo; |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
142 } |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
143 return sc.findType(id.get); |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
144 } |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
145 |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
146 Module[] modules; |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
147 Module current; |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
148 SmallArray!(bool) inFunctionBodyStack; |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
149 SymbolFactory sf; |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
150 } |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
151 |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
152 class TypeBuilder : Visitor!(void) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
153 { |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
154 this(SymbolFactory sf) |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
155 { |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
156 this.sf = sf; |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
157 } |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
158 |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
159 override void visit(Module[] modules) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
160 { |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
161 foreach (mod; modules) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
162 { |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
163 current = mod; |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
164 foreach (decl; mod.decls) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
165 visitDecl(decl); |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
166 } |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
167 } |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
168 |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
169 override void visitStructDecl(StructDecl s) |
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
170 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
171 auto st = s.env.findType(s.identifier.get).asStruct; |
136 | 172 s.sym = current.symbol.createMember( |
173 s.identifier.get, | |
174 st, | |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
175 s.env.find(s.identifier.get)[0]); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
176 sf.put(s.sym, st); |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
177 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
178 foreach (decl; s.decls) |
129 | 179 { |
180 DType type; | |
181 char[] name; | |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
182 if (auto varDecl = cast(VarDecl)decl) |
129 | 183 { |
184 type = typeOf(varDecl.varType, varDecl.env); | |
185 name = varDecl.identifier.get; | |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
186 st.addMember(type, name); |
129 | 187 } |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
188 /* |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
189 else if (auto fd = cast(FuncDecl)decl) |
129 | 190 { |
191 type = fd.type; | |
192 name = fd.identifier.get; | |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
193 }*/ |
129 | 194 } |
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:
45
diff
changeset
|
195 } |
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:
45
diff
changeset
|
196 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
197 override void visitClassDecl(ClassDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
198 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
199 auto st = s.env.findType(s.identifier.get).asClass; |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
200 s.sym = current.symbol.createMember( |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
201 s.identifier.get, |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
202 st, |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
203 s.env.find(s.identifier.get)[0]); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
204 |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
205 sf.put(s.sym, st); |
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
206 |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
207 foreach (decl; s.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
208 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
209 DType type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
210 char[] name; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
211 if (auto varDecl = cast(VarDecl)decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
212 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
213 type = typeOf(varDecl.varType, varDecl.env); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
214 name = varDecl.identifier.get; |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
215 st.addMember(type, name); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
216 } |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
217 /* |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
218 else if (auto fd = cast(FuncDecl)decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
219 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
220 type = fd.type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
221 name = fd.identifier.get; |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
222 }*/ |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
223 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
224 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
225 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
226 override void visitInterfaceDecl(InterfaceDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
227 { |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
228 auto st = s.env.findType(s.identifier.get).asInterface; |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
229 s.sym = current.symbol.createMember( |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
230 s.identifier.get, |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
231 st, |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
163
diff
changeset
|
232 s.env.find(s.identifier.get)[0]); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
233 sf.put(s.sym, st); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
234 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
235 foreach (decl; s.decls) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
236 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
237 DType type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
238 char[] name; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
239 if (auto varDecl = cast(VarDecl)decl) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
240 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
241 type = typeOf(varDecl.varType, varDecl.env); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
242 name = varDecl.identifier.get; |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
243 st.addMember(type, name); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
244 } |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
245 /* |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
246 else if (auto fd = cast(FuncDecl)decl) |
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 type = fd.type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
249 name = fd.identifier.get; |
163
362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
Anders Johnsen <skabet@gmail.com>
parents:
162
diff
changeset
|
250 }*/ |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
251 } |
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 |
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:
45
diff
changeset
|
254 DType typeOf(Identifier id, Scope sc) |
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:
45
diff
changeset
|
255 { |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
256 if(auto i = cast(PointerTypeExp)id) |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
257 return (typeOf(i.pointerOf, sc)).getPointerTo(); |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
258 else if(auto i = cast(StaticArrayTypeExp)id) |
136 | 259 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
260 else if(auto i = cast(FunctionTypeExp)id) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
261 { |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
262 auto d = new DFunction(id); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
263 d.returnType = typeOf(i.returnType, sc); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
264 foreach (decl ; i.decls) |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
265 d.params ~= typeOf(decl.varType, sc); |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
266 return d.getPointerTo; |
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
172
diff
changeset
|
267 } |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
268 return sc.findType(id.get); |
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:
45
diff
changeset
|
269 } |
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
|
270 |
129 | 271 Module current; |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
272 SymbolFactory sf; |
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:
45
diff
changeset
|
273 } |
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:
45
diff
changeset
|
274 |
133
9c48871eb816
Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
Anders Johnsen <skabet@gmail.com>
parents:
132
diff
changeset
|
275 |
129 | 276 /** |
277 Add scopes to everything, and add all identifiers that correspond to types. | |
278 Types/Symbols are added by ForwardReference. | |
279 **/ | |
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:
45
diff
changeset
|
280 class ScopeBuilder : Visitor!(void) |
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:
45
diff
changeset
|
281 { |
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
|
282 static ModuleHandler mHandle; |
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
|
283 |
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
|
284 static this() |
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
|
285 { |
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
|
286 mHandle = new ModuleHandler; |
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
|
287 } |
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
|
288 |
1 | 289 this() |
290 { | |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
291 sf = new SymbolFactory(); |
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
|
292 } |
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
|
293 |
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
|
294 override void visit(Module[] modules) |
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
|
295 { |
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
|
296 foreach(m ; modules) |
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
|
297 visitModule(m); |
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
|
298 |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
299 auto fr = new ForwardReference(sf); |
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
|
300 |
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
|
301 fr.visit(modules); |
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
|
302 } |
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
|
303 |
129 | 304 private void registerBasicTypeTo(char[] n, DType t, Scope sc, Module m) |
305 { | |
306 sc.types[n] = t; | |
307 auto id = new Identifier(n); | |
308 id.env = sc; | |
309 auto decl = new DummyDecl(); | |
136 | 310 auto sym = m.symbol.createMember(n, t, decl); |
311 sym.decl = decl; | |
129 | 312 decl.sym = sym; |
313 decl.env = sc; | |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
314 sc.put(id.get, decl); |
129 | 315 } |
316 | |
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
|
317 override void visitModule(Module m) |
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
|
318 { |
129 | 319 auto root = new Scope; |
320 table ~= root; | |
321 | |
322 m.symbol = new Symbol; | |
1 | 323 |
129 | 324 registerBasicTypeTo("void", DType.Void, root, m); |
325 registerBasicTypeTo("bool", DType.Bool, root, m); | |
326 registerBasicTypeTo("byte", DType.Byte, root, m); | |
327 registerBasicTypeTo("ubyte", DType.UByte, root, m); | |
328 registerBasicTypeTo("short", DType.Short, root, m); | |
329 registerBasicTypeTo("ushort", DType.UShort, root, m); | |
330 registerBasicTypeTo("int", DType.Int, root, m); | |
331 registerBasicTypeTo("uint", DType.UInt, root, m); | |
332 registerBasicTypeTo("long", DType.Long, root, m); | |
333 registerBasicTypeTo("ulong", DType.ULong, root, m); | |
334 | |
335 registerBasicTypeTo("char", DType.Char, root, m); | |
336 registerBasicTypeTo("wchar", DType.WChar, root, m); | |
337 registerBasicTypeTo("dchar", DType.DChar, root, m); | |
338 | |
339 registerBasicTypeTo("float", DType.Float, root, m); | |
340 registerBasicTypeTo("double", DType.Double, root, m); | |
341 registerBasicTypeTo("real", DType.Real, root, m); | |
119
c0b531362ca6
Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
342 |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
343 current().inModule = m; |
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
|
344 current().mHandle = mHandle; |
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
|
345 mHandle.add(m); |
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
|
346 m.env = current(); |
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
|
347 super.visitModule(m); |
1 | 348 } |
349 | |
350 override void visitDecl(Decl d) | |
351 { | |
352 d.env = current(); | |
353 super.visitDecl(d); | |
354 } | |
355 | |
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
|
356 override void visitImportDecl(ImportDecl i) |
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
|
357 { |
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
|
358 i.env.imports ~= i; |
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
|
359 super.visitImportDecl(i); |
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
|
360 } |
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
|
361 |
1 | 362 override void visitStmt(Stmt s) |
363 { | |
364 s.env = current(); | |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
365 s.stmtIndex = s.env.stmtIndex; |
1 | 366 super.visitStmt(s); |
367 } | |
368 | |
369 override void visitExp(Exp e) | |
370 { | |
371 e.env = current(); | |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
372 e.stmtIndex = e.env.stmtIndex; |
1 | 373 super.visitExp(e); |
374 } | |
375 | |
376 override void visitFuncDecl(FuncDecl d) | |
377 { | |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
378 current().put(d.identifier.get, d); |
136 | 379 d.env = current(); |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
380 auto sc = push(); |
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:
45
diff
changeset
|
381 |
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:
59
diff
changeset
|
382 visitExp(d.returnType); |
2
ae5bbe4e7fd6
Lots of stuff, here are the git comments:
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
383 visitExp(d.identifier); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
384 sc.parentFunction = d; |
2
ae5bbe4e7fd6
Lots of stuff, here are the git comments:
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
385 foreach (arg; d.funcArgs) |
ae5bbe4e7fd6
Lots of stuff, here are the git comments:
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
386 visitDecl(arg); |
ae5bbe4e7fd6
Lots of stuff, here are the git comments:
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
387 foreach (stmt; d.statements) |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
388 { |
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
389 sc.currentStmtIndex++; |
2
ae5bbe4e7fd6
Lots of stuff, here are the git comments:
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
390 visitStmt(stmt); |
56
4ae365eff712
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents:
55
diff
changeset
|
391 } |
14 | 392 pop(sc); |
1 | 393 } |
394 | |
395 override void visitVarDecl(VarDecl d) | |
396 { | |
24 | 397 if (d.init) |
398 visitExp(d.init); | |
399 | |
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:
45
diff
changeset
|
400 if (need_push > 0 && current().parentFunction !is null) { |
24 | 401 push(); |
402 --need_push; | |
403 } | |
404 | |
180
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
405 if(d.identifier) |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
406 { |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
407 auto sc = current(); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
408 sc.put(d.identifier.get, d); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
409 d.env = sc; |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
410 visitExp(d.varType); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
411 visitExp(d.identifier); |
29324df1d649
Fixed a but that did't allow type-only params.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
412 } |
1 | 413 } |
414 | |
22 | 415 override void visitStructDecl(StructDecl s) |
416 { | |
417 auto sc = current(); | |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
418 sc.put(s.identifier.get, s); |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
419 s.env = sc; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
420 auto type = new DStruct(s.identifier); |
129 | 421 |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
27
diff
changeset
|
422 sc.types[s.identifier.get] = type; |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
423 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
424 sc = push(); |
22 | 425 super.visitStructDecl(s); |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
53
diff
changeset
|
426 pop(sc); |
22 | 427 } |
428 | |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
429 override void visitClassDecl(ClassDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
430 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
431 auto sc = current(); |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
432 sc.put(s.identifier.get, s); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
433 s.env = sc; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
434 auto type = new DClass(s.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
435 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
436 sc.types[s.identifier.get] = type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
437 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
438 sc = push(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
439 super.visitClassDecl(s); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
440 pop(sc); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
441 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
442 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
443 override void visitInterfaceDecl(InterfaceDecl s) |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
444 { |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
445 auto sc = current(); |
145
a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
Anders Johnsen <skabet@gmail.com>
parents:
144
diff
changeset
|
446 sc.put(s.identifier.get, s); |
144
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
447 s.env = sc; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
448 auto type = new DInterface(s.identifier); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
449 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
450 sc.types[s.identifier.get] = type; |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
451 |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
452 sc = push(); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
453 super.visitInterfaceDecl(s); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
454 pop(sc); |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
455 } |
6e6355fb5f0f
- Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents:
136
diff
changeset
|
456 |
14 | 457 override void visitDeclStmt(DeclStmt d) |
458 { | |
24 | 459 ++need_push; |
14 | 460 super.visitDeclStmt(d); |
461 } | |
24 | 462 private uint need_push = 0; |
14 | 463 |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
464 override void visitIfStmt(IfStmt s) |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
465 { |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
466 s.env = current(); |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
467 visitExp(s.cond); |
14 | 468 auto sc = push(); |
45 | 469 visitStmt(s.then_body); |
14 | 470 pop(sc); |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
471 |
45 | 472 if (s.else_body !is null) |
473 { | |
474 sc = push(); | |
475 visitStmt(s.else_body); | |
476 pop(sc); | |
477 } | |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
478 } |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
479 |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
480 override void visitWhileStmt(WhileStmt s) |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
481 { |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
482 s.env = current(); |
14 | 483 auto sc = push(); |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
484 super.visitWhileStmt(s); |
14 | 485 pop(sc); |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
486 } |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
2
diff
changeset
|
487 |
149
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
488 override void visitForStmt(ForStmt s) |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
489 { |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
490 s.env = current(); |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
491 auto sc = push(); |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
492 super.visitForStmt(s); |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
493 pop(sc); |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
494 } |
393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
Anders Johnsen <skabet@gmail.com>
parents:
145
diff
changeset
|
495 |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
496 override void visitCompoundStmt(CompoundStatement s) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
497 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
498 s.env = current(); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
499 auto sc = push(); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
500 super.visitCompoundStmt(s); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
501 pop(sc); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
502 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
503 |
1 | 504 private: |
505 Scope[] table; | |
172
01c2c49775ef
- Changed Parser to be more clean on type parsing.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
506 SymbolFactory sf; |
1 | 507 |
14 | 508 Scope push() |
1 | 509 { |
14 | 510 auto sc = new Scope(current()); |
511 table ~= sc; | |
512 return sc; | |
1 | 513 } |
514 | |
14 | 515 Scope pop(Scope sc = null) |
1 | 516 { |
14 | 517 if (sc !is null) |
518 { | |
519 table.length = table.find(sc); | |
520 return sc; | |
521 } | |
522 | |
1 | 523 auto res = table[$ - 1]; |
524 table.length = table.length - 1; | |
525 return res; | |
526 } | |
527 | |
528 Scope current() | |
529 { | |
530 return table[$ - 1]; | |
531 } | |
532 } | |
533 |