annotate dmd/Dsymbol.d @ 137:09c858522d55

merge
author Trass3r
date Mon, 13 Sep 2010 23:29:00 +0200
parents 010eb8f0e18d
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 99
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Package;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TemplateMixin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.ThisDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.FuncAliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.FuncLiteralDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.PostBlitDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.DtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.StaticCtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.StaticDtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.UnitTestDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.UnionDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.WithScopeSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.ArrayScopeSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.SymbolDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.OverloadSet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.DYNCAST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import dmd.backend.TYFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 import dmd.backend.LIST;
99
903b95002d4e Id and Macro are quite experimental currently
Trass3r
parents: 79
diff changeset
71 public import dmd.PASS;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 import core.stdc.string : strcmp, memcpy, strlen;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
74 version (Bug4054) import core.memory;
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
75 else import core.stdc.stdlib : alloca;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 // TODO: remove dependencies on these
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expression isExpression(Object o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 return cast(Expression)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 Dsymbol isDsymbol(Object o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 return cast(Dsymbol)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 Type isType(Object o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 return cast(Type)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
95 /***********************
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
96 * Try to get arg as a type.
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
97 */
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
98
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
99 Type getType(Object o)
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
100 {
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
101 Type t = isType(o);
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
102 if (!t)
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
103 { Expression e = isExpression(o);
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
104 if (e)
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
105 t = e.type;
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
106 }
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
107 return t;
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
108 }
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
109
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
110
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 Dsymbol getDsymbol(Object oarg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 Dsymbol sa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 Expression ea = isExpression(oarg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 { // Try to convert Expression to symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (ea.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 sa = (cast(VarExp)ea).var;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 else if (ea.op == TOK.TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 sa = (cast(FuncExp)ea).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 sa = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 { // Try to convert Type to symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 Type ta = isType(oarg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (ta)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 sa = ta.toDsymbol(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 sa = isDsymbol(oarg); // if already a symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 return sa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
135 alias Vector!Dsymbol Dsymbols;
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
136
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 class Dsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 Identifier c_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 Dsymbol parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 Symbol* csym; // symbol for code generator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 Symbol* isym; // import version of csym
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
144 string comment; // documentation comment for this Dsymbol
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Loc loc; // where defined
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 Scope scope_; // !=null means context to use for semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 // do nothing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 this(Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 string toChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 return ident ? ident.toChars() : "__anonymous";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 string locToChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 Module m = getModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (m && m.srcfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 loc.filename = m.srcfile.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 return loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 23
diff changeset
174 bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
58
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
176 Dsymbol s;
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
177
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
178 if (this is o)
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
179 return true;
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
180
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
181 s = cast(Dsymbol)(o);
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
182 if (s && ident.equals(s.ident))
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
183 return true;
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
184
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
185 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 bool isAnonymous()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 return ident ? 0 : 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (!global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if (p.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 p = locToChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (p.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 write("Error: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 writef("%s %s ", kind(), toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 //fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 //printf("Dsymbol.error()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if (!global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 if (p.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 write("Error: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 if (isAnonymous()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 writef("%s ", kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 writef("%s %s ", kind(), toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 //fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 void checkDeprecated(Loc loc, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (!global.params.useDeprecated && isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 // Don't complain if we're inside a deprecated symbol's scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 for (Dsymbol sp = sc.parent; sp; sp = sp.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (sp.isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 for (; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 if (sc.scopesym && sc.scopesym.isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 // If inside a StorageClassDeclaration that is deprecated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (sc.stc & STC.STCdeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 error(loc, "is deprecated");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 Module getModule()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 //printf("Dsymbol.getModule()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 Dsymbol s = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 while (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 //printf("\ts = '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 Module m = s.isModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 s = s.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 Dsymbol pastMixin()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 Dsymbol s = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 //printf("Dsymbol::pastMixin() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 while (s && s.isTemplateMixin())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 s = s.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 Dsymbol toParent()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 return parent ? parent.pastMixin() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 * Use this instead of toParent() when looking for the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 * 'this' pointer of the enclosing function/class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 Dsymbol toParent2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 Dsymbol s = parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 while (s && s.isTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 s = s.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 TemplateInstance inTemplateInstance()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 for (Dsymbol parent = this.parent; parent; parent = parent.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 TemplateInstance ti = parent.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 if (ti)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 return ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 DYNCAST dyncast() { return DYNCAST.DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 * Do syntax copy of an array of Dsymbol's.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 */
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
325 static Vector!Dsymbol arraySyntaxCopy(Vector!Dsymbol a)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
327 Vector!Dsymbol b = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 if (a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 b = a.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 for (int i = 0; i < b.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
333 auto s = b[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 s = s.syntaxCopy(null);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
336 b[i] = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 return b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 string toPrettyChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 //printf("Dsymbol.toPrettyChars() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 if (!parent) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 return toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 size_t len = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 for (Dsymbol p = this; p; p = p.parent) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 len += p.toChars().length + 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 --len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
355 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
356 char* s = cast(char*)GC.malloc(len);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
357 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 char* s = cast(char*)alloca(len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 char* q = s + len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 for (Dsymbol p = this; p; p = p.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 string t = p.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 size_t length = t.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 q -= length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 memcpy(q, t.ptr, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 if (q is s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 q--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 version (TARGET_NET) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 if (AggregateDeclaration ad = p.isAggregateDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (ad.isNested() && p.parent && p.parent.isAggregateDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 *q = '/';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 *q = '.';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 return s[0..len].idup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 string kind()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 /*********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 * If this symbol is really an alias for another,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 * return that other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 Dsymbol toAlias() // resolve real symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
402 bool addMember(Scope sc, ScopeDsymbol sd, bool memnum)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 //printf("Dsymbol.addMember('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 //printf("Dsymbol.addMember(this = %p, '%s' scopesym = '%s')\n", this, toChars(), sd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 assert(sd !is null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 parent = sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 if (!isAnonymous()) // no name, so can't add it to symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
410 if (!sd.symtabInsert(this)) // if name is already defined
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 Dsymbol s2 = sd.symtab.lookup(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 if (!s2.overloadInsert(this))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 sd.multiplyDefined(Loc(0), this, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 if (sd.isAggregateDeclaration() || sd.isEnumDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 if (ident is Id.__sizeof || ident is Id.alignof_ || ident is Id.mangleof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 error(".%s property cannot be redefined", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 void setScope(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 //printf("Dsymbol.setScope() %p %s\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 if (!sc.nofree)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 sc.setNoFree(); // may need it even after semantic() finishes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 scope_ = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
436
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
437 void importAll(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
438 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
439 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 void semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
443 error("%p has no semantic routine", this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 * Does semantic analysis on initializers and members of aggregates.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 void semantic2(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 // Most Dsymbols have no further semantic analysis needed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 * Does semantic analysis on function bodies.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 void semantic3(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 // Most Dsymbols have no further semantic analysis needed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 * Look for function inlining possibilities.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 void inlineScan()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 // Most Dsymbols aren't functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
470 /*********************************************
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
471 * Search for ident as member of s.
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
472 * Input:
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
473 * flags: 1 don't find private members
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
474 * 2 don't give error messages
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
475 * 4 return null if ambiguous
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
476 * Returns:
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
477 * null if not found
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
478 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 Dsymbol search(Loc loc, Identifier ident, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
481 //printf("Dsymbol.search(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
482 return null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 * Search for identifier id as a member of 'this'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 * id may be a template instance.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 * symbol found, null if not
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 */
56
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
491 Dsymbol searchX(Loc loc, Scope sc, Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 Dsymbol s = toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 Dsymbol sm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496
56
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
497 if (auto ident = cast(Identifier)o)
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
498 {
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
499 sm = s.search(loc, ident, 0);
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
500 }
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
501 else if (auto st = cast(Dsymbol)o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
56
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
503 // It's a template instance
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
504 //printf("\ttemplate instance id\n");
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
505 TemplateInstance ti = st.isTemplateInstance();
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
506 Identifier id = ti.name;
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
507 sm = s.search(loc, cast(Identifier)id, 0);
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
508 if (!sm)
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
509 {
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
510 error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.toChars());
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
511 return null;
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
512 }
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
513 sm = sm.toAlias();
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
514 TemplateDeclaration td = sm.isTemplateDeclaration();
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
515 if (!td)
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
516 {
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
517 error("%s is not a template, it is a %s", id.toChars(), sm.kind());
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
518 return null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
56
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
521 ti.tempdecl = td;
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
522 if (!ti.semanticRun)
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
523 ti.semantic(sc);
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
524
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
525 sm = ti.toAlias();
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
526 }
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
527 else
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
528 {
51605de93870 TupleExp.optimize
korDen
parents: 50
diff changeset
529 assert(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 return sm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 bool overloadInsert(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
539 version (_DH)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
540 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 char* toHChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 void toHBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 void toDocBuffer(OutBuffer buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
560
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
561 void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
562 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
563 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 uint size(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 int isforwardRef()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 void defineRef(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 AggregateDeclaration isThis() // is a 'this' required to access the member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
582 return null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 ClassDeclaration isClassMember() // are we a member of a class?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 Dsymbol parent = toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 if (parent && parent.isClassDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 return cast(ClassDeclaration)parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 bool isExport() // is Dsymbol exported?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 bool isImportedSymbol() // is Dsymbol imported?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 bool isDeprecated() // is Dsymbol deprecated?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 bool isOverloadable()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 LabelDsymbol isLabel() // is this a LabelDsymbol?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 AggregateDeclaration isMember() // is this symbol a member of an AggregateDeclaration?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 //printf("Dsymbol::isMember() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 Dsymbol parent = toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 //printf("parent is %s %s\n", parent.kind(), parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 return parent ? parent.isAggregateDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 Type getType() // is this a type?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 string mangle()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 string id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 printf("Dsymbol::mangle() '%s'", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 if (parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 printf(" parent = %s %s", parent.kind(), parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 id = ident ? ident.toChars() : toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 if (parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 string p = parent.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 if (p[0] == '_' && p[1] == 'D')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 p = p[2..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 buf.writestring(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 ///buf.printf("%zu%s", id.length, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 buf.printf("%d%s", id.length, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 id = buf.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 buf.data = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 bool needThis() // need a 'this' pointer?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 PROT prot()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 * Determine if this symbol is only one.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 * false, *ps = null: There are 2 or more symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 * true, *ps = null: There are zero symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 * true, *ps = symbol: The one and only one symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 bool oneMember(Dsymbol* ps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 //printf("Dsymbol::oneMember()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 *ps = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 * Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 */
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
692 static bool oneMembers(Dsymbols members, Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 //printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 Dsymbol s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
699 foreach(sx; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 bool x = sx.oneMember(ps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 if (!x)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 //printf("\tfalse 1\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 assert(*ps is null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 if (*ps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 if (s) // more than one symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 *ps = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 //printf("\tfalse 2\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 s = *ps;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 *ps = s; // s is the one symbol, null if none
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 //printf("\ttrue\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 * Is Dsymbol a variable that contains pointers?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 bool hasPointers()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 //printf("Dsymbol::hasPointers() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 void addLocalClass(ClassDeclarations) { }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 void checkCtorConstInit() { }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
739 // since comment is stored immutable string is correct here
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
740 void addComment(string comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 //if (comment)
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
743 //writef("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
745 if (this.comment is null)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
746 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 this.comment = comment;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
748 }
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
749 else
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
750 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
751 static if (true)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
752 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
753 if (comment !is null && comment != this.comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 { // Concatenate the two
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 this.comment = Lexer.combineComments(this.comment, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 void emitComment(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 void emitDitto(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 // Backend
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 Symbol* toSymbol() // to backend symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 void toObjFile(int multiobj) // compile to .obj file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 //printf("Dsymbol::toObjFile('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 // ignore
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 int cvMember(ubyte* p) // emit cv debug info for member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 /*********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 * Generate import symbol from symbol.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 Symbol* toImport() // to backend import symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 if (!isym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 if (!csym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 csym = toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 isym = toImport(csym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 return isym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 static Symbol* toImport(Symbol* sym) // to backend import symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 char* id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 char* n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 //printf("Dsymbol::toImport('%s')\n", sym->Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 n = sym.Sident.ptr;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
813 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
814 id = cast(char*) GC.malloc(6 + strlen(n) + 1 + (type_paramsize_i(sym.Stype)).sizeof*3 + 1);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
815 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 id = cast(char*) alloca(6 + strlen(n) + 1 + (type_paramsize_i(sym.Stype)).sizeof*3 + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 if (sym.Stype.Tmangle == mTYman_std && tyfunc(sym.Stype.Tty))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 sprintf(id, "_imp__%s@%lu", n, type_paramsize_i(sym.Stype));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 else if (sym.Stype.Tmangle == mTYman_d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 sprintf(id,"_imp_%s",n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 sprintf(id,"_imp__%s",n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 t = type_alloc(TYnptr | mTYconst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 t.Tnext = sym.Stype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 t.Tmangle = mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 s.Sclass = SCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 s.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 Symbol* toSymbolX(string prefix, int sclass, TYPE* t, string suffix) // helper
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 char* id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 string n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 size_t nlen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 //writef("Dsymbol::toSymbolX('%s', '%s')\n", prefix, this.classinfo.name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 n = mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 assert(n.length != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 nlen = n.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 if (nlen > 2 && n[0] == '_' && n[1] == 'D')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 nlen -= 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 n += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
858 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
859 id = cast(char*) GC.malloc(2 + nlen + size_t.sizeof * 3 + prefix.length + suffix.length + 1);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
860 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 id = cast(char*) alloca(2 + nlen + size_t.sizeof * 3 + prefix.length + suffix.length + 1);
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 58
diff changeset
862 sprintf(id, "_D%.*s%zu%.*s%.*s", n, prefix.length, prefix, suffix);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 if (global.params.isWindows && (type_mangle(t) == mTYman.mTYman_c || type_mangle(t) == mTYman.mTYman_std))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 id++; // Windows C mangling will put the '_' back in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 s = symbol_name(id, sclass, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 //printf("-Dsymbol::toSymbolX() %s\n", id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 // Eliminate need for dynamic_cast
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 Package isPackage() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 Module isModule() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 EnumMember isEnumMember() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 TemplateDeclaration isTemplateDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 TemplateInstance isTemplateInstance() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 TemplateMixin isTemplateMixin() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 Declaration isDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 ThisDeclaration isThisDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 TupleDeclaration isTupleDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 TypedefDeclaration isTypedefDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 AliasDeclaration isAliasDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 AggregateDeclaration isAggregateDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 FuncDeclaration isFuncDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 FuncAliasDeclaration isFuncAliasDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 FuncLiteralDeclaration isFuncLiteralDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 CtorDeclaration isCtorDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 PostBlitDeclaration isPostBlitDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 DtorDeclaration isDtorDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 StaticCtorDeclaration isStaticCtorDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 StaticDtorDeclaration isStaticDtorDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 InvariantDeclaration isInvariantDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 UnitTestDeclaration isUnitTestDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 NewDeclaration isNewDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 VarDeclaration isVarDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 ClassDeclaration isClassDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 StructDeclaration isStructDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 UnionDeclaration isUnionDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 InterfaceDeclaration isInterfaceDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 ScopeDsymbol isScopeDsymbol() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 WithScopeSymbol isWithScopeSymbol() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 ArrayScopeSymbol isArrayScopeSymbol() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 Import isImport() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 EnumDeclaration isEnumDeclaration() { return null; }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
908 version (_DH)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
909 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 DeleteDeclaration isDeleteDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 SymbolDeclaration isSymbolDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 AttribDeclaration isAttribDeclaration() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 OverloadSet isOverloadSet() { return null; }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
915 version (TARGET_NET)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
916 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 PragmaScope isPragmaScope() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
919 }