annotate trunk/src/dil/semantic/Scope.d @ 798:c24be8d4f6ab

Added documentation comments.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 01 Mar 2008 02:53:06 +0100
parents d33895f679eb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
592
b8dd677e0ace Moved dil.Scope to dil.semantic.Scope.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 590
diff changeset
5 module dil.semantic.Scope;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
6
589
de365ddcfbd4 Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 574
diff changeset
7 import dil.semantic.Symbol;
590
641041912670 Moved dil.Symbols to dil.semantic.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 589
diff changeset
8 import dil.semantic.Symbols;
611
6d449e777f5d Added semantic code to insert symbols into the scope.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
9 import dil.lexer.Identifier;
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
10 import common;
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
11
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
12 /// Builds a hierarchy of environments.
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
13 class Scope
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
14 {
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
15 Scope parent; /// The surrounding scope, or null if this is the root scope.
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
16
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
17 ScopeSymbol symbol; /// The current symbol with the symbol table.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
18
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
19 this(Scope parent, ScopeSymbol symbol)
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
20 {
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
21 this.parent = parent;
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
22 this.symbol = symbol;
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
23 }
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
24
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
25 /// Find a symbol in this scope.
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
26 /// Params:
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
27 /// name = the name of the symbol.
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
28 Symbol lookup(Identifier* name)
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
29 {
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
30 return symbol.lookup(name);
562
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
31 }
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
32
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
33 /// Create a new inner scope and return that.
620
f15b054bb27e Renamed Scope.push/pop to Scope.enter/exit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 611
diff changeset
34 Scope enter(ScopeSymbol symbol)
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
35 {
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
36 return new Scope(this, symbol);
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
37 }
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
38
798
c24be8d4f6ab Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 692
diff changeset
39 /// Destroy this scope and return the outer scope.
620
f15b054bb27e Renamed Scope.push/pop to Scope.enter/exit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 611
diff changeset
40 Scope exit()
430
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
41 {
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
42 auto sc = parent;
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
43 // delete this;
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
44 return sc;
e6c759e151cd Fixed a few things regarding encoding/decoding UTF-8 sequences.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
45 }
490
47be6bfe39cd Refactored code and added new modules.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 486
diff changeset
46
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
47 /// Search for the enclosing Class scope.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
48 Scope classScope()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
49 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
50 auto scop = this;
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
51 do
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
52 {
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 565
diff changeset
53 if (scop.symbol.isClass)
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
54 return scop;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
55 scop = scop.parent;
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
56 } while (scop)
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
57 return null;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
58 }
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
59
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
60 /// Search for the enclosing Module scope.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
61 Scope moduleScope()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
62 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
63 auto scop = this;
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
64 do
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
65 {
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 565
diff changeset
66 if (scop.symbol.isModule)
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
67 return scop;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
68 scop = scop.parent;
692
d33895f679eb Tidied up the class Scope a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
69 } while (scop)
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
70 return null;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
71 }
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
72 }