Mercurial > projects > dang
comparison sema/Symbol.d @ 136:2be29b296081
Lots of changes:
- Parsing classes and interfaces
- Fixed some seg faults in sema
- Supporting "private" to some extend
- And a lot of other small fixes
author | johnsen@johnsen-laptop |
---|---|
date | Fri, 11 Jul 2008 21:47:57 +0200 |
parents | 9869194de9b7 |
children | 57b0b4464a0b |
comparison
equal
deleted
inserted
replaced
135:9869194de9b7 | 136:2be29b296081 |
---|---|
2 | 2 |
3 import tango.text.convert.Integer : format; | 3 import tango.text.convert.Integer : format; |
4 import tango.io.Stdout; | 4 import tango.io.Stdout; |
5 | 5 |
6 import sema.DType; | 6 import sema.DType; |
7 | |
8 import ast.Decl; | |
7 | 9 |
8 /// | 10 /// |
9 class Symbol | 11 class Symbol |
10 { | 12 { |
11 /// Create a root symbol - representing a module | 13 /// Create a root symbol - representing a module |
47 if (possible.name == member) | 49 if (possible.name == member) |
48 return possible; | 50 return possible; |
49 return null; | 51 return null; |
50 } | 52 } |
51 | 53 |
54 /** | |
55 Get the members of the symbol | |
56 **/ | |
57 Symbol[] getMembers() | |
58 { | |
59 return actual.contained; | |
60 } | |
61 | |
52 void dump() | 62 void dump() |
53 { | 63 { |
54 Stdout("Symbol: "); | 64 Stdout("Symbol: "); |
55 Symbol p = parent; | 65 Symbol p = parent; |
56 while (p !is null) { | 66 while (p !is null) { |
59 } | 69 } |
60 Stdout.formatln("{}", name); | 70 Stdout.formatln("{}", name); |
61 } | 71 } |
62 | 72 |
63 /// Create a member with the given name and type | 73 /// Create a member with the given name and type |
64 Symbol createMember(char[] member, DType type) | 74 Symbol createMember(char[] member, DType type, Decl decl) |
65 { | 75 { |
66 auto res = new Symbol(member, type, this); | 76 auto res = new Symbol(member, type, this); |
77 res.decl = decl; | |
67 actual.contained ~= res; | 78 actual.contained ~= res; |
68 return res; | 79 return res; |
69 } | 80 } |
70 | 81 |
71 /** | 82 /** |
72 Create an alias of another symbol with the given name. | 83 Create an alias of another symbol with the given name. |
73 | 84 |
74 The target symbol can be a member of another symbol | 85 The target symbol can be a member of another symbol |
75 **/ | 86 **/ |
76 Symbol createAlias(char[] aliasedName, Symbol target) | 87 Symbol createAlias(char[] aliasedName, Symbol target, Decl decl) |
77 { | 88 { |
78 auto res = new Symbol(aliasedName, target, this); | 89 auto res = new Symbol(aliasedName, target, this); |
90 res.decl = decl; | |
79 actual.contained ~= res; | 91 actual.contained ~= res; |
80 return res; | 92 return res; |
81 } | 93 } |
82 | 94 |
83 // The type of this symbol | 95 // The type of this symbol |
84 DType type; | 96 DType type; |
97 // The declaration of this symbol | |
98 Decl decl; | |
99 // If the symbol is an alias, this will point to the actual symbol | |
100 Symbol actual; | |
101 // If this symbol is contained within a struct or similar this will point | |
102 // to that symbol | |
103 Symbol parent; | |
85 | 104 |
86 private: | 105 private: |
87 // Helper for getMangledFQN - gets the FQN without _D and the type | 106 // Helper for getMangledFQN - gets the FQN without _D and the type |
88 char[] internalFQN() | 107 char[] internalFQN() |
89 { | 108 { |
112 } | 131 } |
113 | 132 |
114 private: | 133 private: |
115 char[] name; | 134 char[] name; |
116 | 135 |
117 // If the symbol is an alias, this will point to the actual symbol | |
118 Symbol actual; | |
119 // If this symbol is contained within a struct or similar this will point | |
120 // to that symbol | |
121 Symbol parent; | |
122 // All the symbols contained within this symbol | 136 // All the symbols contained within this symbol |
123 Symbol[] contained; | 137 Symbol[] contained; |
124 | 138 |
125 // The module that contains this symbol (root of the parent-chain) | 139 // The module that contains this symbol (root of the parent-chain) |
126 // DModule mod; | 140 // DModule mod; |