Mercurial > projects > dang
annotate sema/Symbol.d @ 135:9869194de9b7
Removed some output
We have 15 tests that fail in release mode and 17 in debug - both from things
that are only handled by an assert.
One is a comments lexing test, that fails on an invalid location in debug
The other is returning a struct - it's cought in codegen by an assert, but
should be checked explicitly before that
author | Anders Halager <halager@gmail.com> |
---|---|
date | Wed, 09 Jul 2008 13:38:11 +0200 |
parents | 3635fc5428b1 |
children | 2be29b296081 |
rev | line source |
---|---|
129 | 1 module sema.Symbol; |
2 | |
3 import tango.text.convert.Integer : format; | |
4 import tango.io.Stdout; | |
5 | |
6 import sema.DType; | |
7 | |
8 /// | |
9 class Symbol | |
10 { | |
11 /// Create a root symbol - representing a module | |
12 this() { actual = this; } | |
13 | |
14 /// Get a simple human readable name (bar) | |
15 char[] getName() { return name; } | |
16 | |
17 /// Get a human readable name (foo.bar) | |
18 char[] getFQN() | |
19 { | |
20 char[] prefix; | |
21 if (parent !is null && parent.name !is null) | |
22 prefix ~= parent.getFQN() ~ "."; | |
23 return prefix ~ name; | |
24 } | |
25 | |
26 /// Get a machine readable name (_D3foo3barFZi) | |
27 char[] getMangledFQN() | |
28 { | |
29 char[] n = `_D`; | |
30 Symbol p = parent; | |
31 while (p !is null) { | |
32 n ~= p.internalFQN(); | |
33 p = p.parent; | |
34 } | |
35 n ~= internalFQN(); | |
36 n ~= type.mangle(); | |
37 return n; | |
38 } | |
39 | |
40 /** | |
41 Try to find a contained symbol with the given name - returns null if not | |
42 found | |
43 **/ | |
44 Symbol findMember(char[] member) | |
45 { | |
131
3635fc5428b1
Try and make aliases work
Anders Halager <halager@gmail.com>
parents:
129
diff
changeset
|
46 foreach (possible; actual.contained) |
129 | 47 if (possible.name == member) |
48 return possible; | |
49 return null; | |
50 } | |
51 | |
52 void dump() | |
53 { | |
54 Stdout("Symbol: "); | |
55 Symbol p = parent; | |
56 while (p !is null) { | |
57 Stdout.format("{}.", p.name); | |
58 p = p.parent; | |
59 } | |
60 Stdout.formatln("{}", name); | |
61 } | |
62 | |
63 /// Create a member with the given name and type | |
64 Symbol createMember(char[] member, DType type) | |
65 { | |
66 auto res = new Symbol(member, type, this); | |
131
3635fc5428b1
Try and make aliases work
Anders Halager <halager@gmail.com>
parents:
129
diff
changeset
|
67 actual.contained ~= res; |
129 | 68 return res; |
69 } | |
70 | |
71 /** | |
72 Create an alias of another symbol with the given name. | |
73 | |
74 The target symbol can be a member of another symbol | |
75 **/ | |
76 Symbol createAlias(char[] aliasedName, Symbol target) | |
77 { | |
78 auto res = new Symbol(aliasedName, target, this); | |
131
3635fc5428b1
Try and make aliases work
Anders Halager <halager@gmail.com>
parents:
129
diff
changeset
|
79 actual.contained ~= res; |
129 | 80 return res; |
81 } | |
82 | |
83 // The type of this symbol | |
84 DType type; | |
85 | |
86 private: | |
87 // Helper for getMangledFQN - gets the FQN without _D and the type | |
88 char[] internalFQN() | |
89 { | |
90 if (actual.name !is null && actual.name.length > 0) | |
91 { | |
92 char[32] len; | |
93 return format(len, actual.name.length) ~ actual.name; | |
94 } | |
95 return ""; | |
96 } | |
97 | |
98 this(char[] name, Symbol actual, Symbol parent) | |
99 { | |
100 this.name = name; | |
101 this.actual = actual; | |
102 this.parent = parent; | |
103 this.type = actual.type; | |
104 } | |
105 | |
106 this(char[] name, DType type, Symbol parent) | |
107 { | |
108 this.name = name; | |
109 this.actual = this; | |
110 this.parent = parent; | |
111 this.type = type; | |
112 } | |
113 | |
114 private: | |
115 char[] name; | |
116 | |
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 | |
123 Symbol[] contained; | |
124 | |
125 // The module that contains this symbol (root of the parent-chain) | |
126 // DModule mod; | |
127 } | |
128 |