Mercurial > projects > dil
comparison trunk/src/dil/Scope.d @ 560:709e223a8eb9
Added code related to symbols.
Added class ScopeSymbol. Module inherits from ScopeSymbol now.
Added methods classScope() and moduleScope(), and member symbol to class Scope.
Added enum SYM. Added member sid to class Symbol.
Aggregate and Function inherit from ScopeSymbol now.
Added Error to struct Types.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 26 Dec 2007 14:17:01 +0100 |
parents | 50e64bab9c7a |
children | b0533550d64c |
comparison
equal
deleted
inserted
replaced
559:c4bb948e5cc1 | 560:709e223a8eb9 |
---|---|
1 /++ | 1 /++ |
2 Author: Aziz Köksal | 2 Author: Aziz Köksal |
3 License: GPL3 | 3 License: GPL3 |
4 +/ | 4 +/ |
5 module dil.Scope; | 5 module dil.Scope; |
6 | |
6 import dil.Symbol; | 7 import dil.Symbol; |
8 import dil.Symbols; | |
7 import dil.Information; | 9 import dil.Information; |
10 import dil.Messages; | |
11 import dil.Token; | |
8 import common; | 12 import common; |
9 | 13 |
10 class Scope | 14 class Scope |
11 { | 15 { |
12 Scope parent; /// The surrounding scope. | 16 Scope parent; /// The surrounding scope. |
13 InfoManager infoMan; /// Collects errors reported during the semantic phase. | 17 InfoManager infoMan; /// Collects errors reported during the semantic phase. |
18 | |
19 ScopeSymbol symbol; /// The current symbol with the symbol table. | |
14 | 20 |
15 this() | 21 this() |
16 { | 22 { |
17 } | 23 } |
18 | 24 |
50 auto sc = parent; | 56 auto sc = parent; |
51 // delete this; | 57 // delete this; |
52 return sc; | 58 return sc; |
53 } | 59 } |
54 | 60 |
55 import dil.Information; | 61 /// Search for the enclosing Class scope. |
56 import dil.Messages; | 62 Scope classScope() |
57 import dil.Token; | 63 { |
64 auto scop = this; | |
65 while (scop) | |
66 { | |
67 if (scop.symbol.sid == SYM.Class) | |
68 return scop; | |
69 scop = scop.parent; | |
70 } | |
71 return null; | |
72 } | |
73 | |
74 /// Search for the enclosing Module scope. | |
75 Scope moduleScope() | |
76 { | |
77 auto scop = this; | |
78 while (scop) | |
79 { | |
80 if (scop.symbol.sid == SYM.Module) | |
81 return scop; | |
82 scop = scop.parent; | |
83 } | |
84 return null; | |
85 } | |
86 | |
58 void error(Token* token, MID mid) | 87 void error(Token* token, MID mid) |
59 { | 88 { |
60 auto location = token.getLocation(); | 89 auto location = token.getLocation(); |
61 auto error = new SemanticError(location, GetMsg(mid)); | 90 auto error = new SemanticError(location, GetMsg(mid)); |
62 // infoMan.add(error); | 91 // infoMan.add(error); |