annotate dmd/Import.d @ 187:b0d41ff5e0df

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