annotate dmd/Import.d @ 169:e7769d53e750

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