annotate dmd/Import.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents af724d3510d7
children b0d41ff5e0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 98
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Array;
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
6 import dmd.ArrayTypes;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Package;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.StorageClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.ProtDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 void escapePath(OutBuffer buf, string fname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
28 foreach (char c; fname)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
29 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 case '(':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 case ')':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 buf.writebyte('\\');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 buf.writebyte(*fname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
40 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 class Import : Dsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
45 Identifiers packages; // array of Identifier's representing packages
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
46 Identifier id; // module Identifier
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
47 Identifier aliasId;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
48 int isstatic; // !=0 if static import
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
50 // Pairs of alias=name to bind into current namespace
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
51 Array names;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
52 Array aliases;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
54 Array aliasdecls; // AliasDeclarations for names/aliases
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
56 Module mod;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
57 Package pkg; // leftmost package/module
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
59 this(Loc loc, Identifiers packages, Identifier id, Identifier aliasId, int isstatic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
61 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 names = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 aliases = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 aliasdecls = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 assert(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 this.packages = packages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 this.id = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 this.aliasId = aliasId;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 this.isstatic = isstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 if (aliasId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 this.ident = aliasId;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 // Kludge to change Import identifier to first package
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 else if (packages && packages.dim)
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
79 this.ident = packages[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
81
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 void addAlias(Identifier name, Identifier alias_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 if (isstatic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 error("cannot have an import bind list");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (!aliasId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 this.ident = null; // make it an anonymous import
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 names.push(cast(void*)name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 aliases.push(cast(void*)alias_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
94 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 return isstatic ? "static import" : "import";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
99 override Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
104 void load(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 169
diff changeset
106 //writefln("Import::load('%s')", id.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 // See if existing module
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
109 DsymbolTable dst = Package.resolve(packages, null, &pkg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
111 Dsymbol s = dst.lookup(id);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
114 version (TARGET_NET)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
115 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 mod = cast(Module)s;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
117 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
118 else
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
119 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (s.isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 mod = cast(Module)s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 error("package and module have the same name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (!mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 // Load module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 mod = Module.load(loc, packages, id);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
131 dst.insert(id, mod); // id may be different from mod.ident,
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 // if so then insert alias
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (!mod.importedFrom)
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 128
diff changeset
134 mod.importedFrom = sc ? sc.module_.importedFrom : global.rootModule;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (!pkg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 pkg = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 //writef("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
143 override void importAll(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
144 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
145 if (!mod)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
146 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
147 load(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
148 mod.importAll(null);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
149
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
150 if (!isstatic && !aliasId && !names.dim)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
151 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
152 /* Default to private importing
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
153 */
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
154 PROT prot = sc.protection;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
155 if (!sc.explicitProtection)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
156 prot = PROT.PROTprivate;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
157 sc.scopesym.importScope(mod, prot);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
158 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
159 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
160 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
161
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
162 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 //writef("Import.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
166 // Load if not already done so
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
167 if (!mod)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
168 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
169 load(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
170 mod.importAll(null);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
171 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
175 static if (false)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
176 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 if (mod.loc.linnum != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 { /* If the line number is not 0, then this is not
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 * a 'root' module, i.e. it was not specified on the command line.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 mod.importedFrom = sc.module_.importedFrom;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 assert(mod.importedFrom);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 // Modules need a list of each imported module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 //printf("%s imports %s\n", sc.module.toChars(), mod.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 sc.module_.aimports.push(cast(void*)mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 if (!isstatic && !aliasId && !names.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 /* Default to private importing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 PROT prot = sc.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (!sc.explicitProtection)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 prot = PROT.PROTprivate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 sc.scopesym.importScope(mod, prot);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 mod.semantic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 if (mod.needmoduleinfo)
98
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
204 {
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
205 // writef("module4 %s because of %s\n", sc.module.toChars(), mod.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 sc.module_.needmoduleinfo = 1;
98
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
207 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 sc = sc.push(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 for (size_t i = 0; i < aliasdecls.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 Dsymbol s = cast(Dsymbol)aliasdecls.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 //writef("\tImport alias semantic('%s')\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 if (!mod.search(loc, cast(Identifier)names.data[i], 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 error("%s not found", (cast(Identifier)names.data[i]).toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 if (global.params.moduleDeps !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 /* The grammar of the file is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 * ImportDeclaration
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
227 * .= BasicImportDeclaration [ " : " ImportBindList ] [ " . "
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 * ModuleAliasIdentifier ] "\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 *
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 * BasicImportDeclaration
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
231 * .= ModuleFullyQualifiedName " (" FilePath ") : " Protection
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 * " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 *
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 * FilePath
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
235 * - any string with '(', ')' and '\' escaped with the '\' character
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 OutBuffer ob = global.params.moduleDeps;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 ob.writestring(sc.module_.toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 ob.writestring(" (");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 escapePath(ob, sc.module_.srcfile.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 ob.writestring(") : ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ProtDeclaration.protectionToCBuffer(ob, sc.protection);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (isstatic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 StorageClassDeclaration.stcToCBuffer(ob, STC.STCstatic);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 ob.writestring(": ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 if (packages)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
252 foreach (pid; packages)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 ob.printf("%s.", pid.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 ob.writestring(id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 ob.writestring(" (");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 if (mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 escapePath(ob, mod.srcfile.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 ob.writestring("???");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 ob.writebyte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 for (size_t i = 0; i < names.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 if (i == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 ob.writebyte(':');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 ob.writebyte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 Identifier name = cast(Identifier)names.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 Identifier alias_ = cast(Identifier)aliases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (!alias_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 ob.printf("%s", name.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 alias_ = name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 ob.printf("%s=%s", alias_.toChars(), name.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 if (aliasId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 ob.printf(" . %s", aliasId.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 ob.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 //printf("-Import.semantic('%s'), pkg = %p\n", toChars(), pkg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
294 override void semantic2(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 //printf("Import::semantic2('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 mod.semantic2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 if (mod.needmoduleinfo)
98
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
299 {
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
300 // writef("module5 %s because of %s\n", sc.module.toChars(), mod.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 sc.module_.needmoduleinfo = 1;
98
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
302 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
305 override Dsymbol toAlias()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 if (aliasId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 return mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 /*****************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 * Add import to sd's symbol table.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 */
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
315 override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 bool result = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (names.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 return Dsymbol.addMember(sc, sd, memnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (aliasId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 result = Dsymbol.addMember(sc, sd, memnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 /* Instead of adding the import to sd's symbol table,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 * add each of the alias=name pairs
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 for (size_t i = 0; i < names.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 Identifier name = cast(Identifier)names.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 Identifier alias_ = cast(Identifier)aliases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (!alias_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 alias_ = name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 TypeIdentifier tname = new TypeIdentifier(loc, name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 AliasDeclaration ad = new AliasDeclaration(loc, alias_, tname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 result |= ad.addMember(sc, sd, memnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 aliasdecls.push(cast(void*)ad);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
346 override Dsymbol search(Loc loc, Identifier ident, int flags)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 //printf("%s.Import.search(ident = '%s', flags = x%x)\n", toChars(), ident.toChars(), flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 if (!pkg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 load(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 mod.semantic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 // Forward it to the package/module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 return pkg.search(loc, ident, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
360 override bool overloadInsert(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 // Allow multiple imports of the same name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 return s.isImport() !is null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
366 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
371 override Import isImport() { return this; }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 13
diff changeset
372 }