Mercurial > projects > ldc
annotate dmd/module.c @ 956:369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
This fixes #210 by making sure that the static ctor always gets the same
number, regardless of the order of the modules given at the command line.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 15 Feb 2009 11:46:28 +0100 |
parents | 330f999ade44 |
children | 31bbc7f3b817 |
rev | line source |
---|---|
336 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2007 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <assert.h> | |
14 | |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
751
diff
changeset
|
15 #if (defined (__SVR4) && defined (__sun)) |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
751
diff
changeset
|
16 #include <alloca.h> |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
751
diff
changeset
|
17 #endif |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
751
diff
changeset
|
18 |
336 | 19 #if _MSC_VER || __MINGW32__ |
20 #include <malloc.h> | |
21 #endif | |
22 | |
23 #if IN_GCC | |
24 #include "gdc_alloca.h" | |
25 #endif | |
26 | |
27 #include "mem.h" | |
28 | |
29 #include "mars.h" | |
30 #include "module.h" | |
31 #include "parse.h" | |
32 #include "scope.h" | |
33 #include "identifier.h" | |
34 #include "id.h" | |
35 #include "import.h" | |
36 #include "dsymbol.h" | |
37 #include "hdrgen.h" | |
38 #include "lexer.h" | |
39 | |
40 #define MARS 1 | |
41 #include "html.h" | |
42 | |
43 #ifdef IN_GCC | |
44 #include "d-dmd-gcc.h" | |
45 #endif | |
46 | |
47 ClassDeclaration *Module::moduleinfo; | |
48 | |
49 Module *Module::rootModule; | |
50 DsymbolTable *Module::modules; | |
51 Array Module::amodules; | |
52 | |
53 Array Module::deferred; // deferred Dsymbol's needing semantic() run on them | |
54 unsigned Module::dprogress; | |
55 | |
56 void Module::init() | |
57 { | |
58 modules = new DsymbolTable(); | |
59 } | |
60 | |
61 Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen) | |
62 : Package(ident) | |
63 { | |
64 FileName *srcfilename; | |
65 | |
66 // printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars()); | |
67 this->arg = filename; | |
68 md = NULL; | |
69 errors = 0; | |
70 numlines = 0; | |
71 members = NULL; | |
72 isHtml = 0; | |
73 isDocFile = 0; | |
74 needmoduleinfo = 0; | |
75 #ifdef IN_GCC | |
76 strictlyneedmoduleinfo = 0; | |
77 #endif | |
78 insearch = 0; | |
79 searchCacheIdent = NULL; | |
80 searchCacheSymbol = NULL; | |
81 searchCacheFlags = 0; | |
82 semanticstarted = 0; | |
83 semanticdone = 0; | |
84 decldefs = NULL; | |
85 vmoduleinfo = NULL; | |
86 massert = NULL; | |
87 marray = NULL; | |
88 sictor = NULL; | |
89 sctor = NULL; | |
90 sdtor = NULL; | |
91 stest = NULL; | |
92 sfilename = NULL; | |
93 root = 0; | |
94 importedFrom = NULL; | |
95 srcfile = NULL; | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
96 objfile = NULL; |
336 | 97 docfile = NULL; |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
98 hdrfile = NULL; |
336 | 99 |
100 debuglevel = 0; | |
101 debugids = NULL; | |
102 debugidsNot = NULL; | |
103 versionlevel = 0; | |
104 versionids = NULL; | |
105 versionidsNot = NULL; | |
106 | |
107 macrotable = NULL; | |
108 escapetable = NULL; | |
109 doppelganger = 0; | |
110 cov = NULL; | |
111 covb = NULL; | |
112 | |
113 srcfilename = FileName::defaultExt(filename, global.mars_ext); | |
114 if (!srcfilename->equalsExt(global.mars_ext) && | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
115 !srcfilename->equalsExt(global.hdr_ext) && |
336 | 116 !srcfilename->equalsExt("dd")) |
117 { | |
118 if (srcfilename->equalsExt("html") || | |
119 srcfilename->equalsExt("htm") || | |
120 srcfilename->equalsExt("xhtml")) | |
121 isHtml = 1; | |
122 else | |
123 { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext); | |
124 fatal(); | |
125 } | |
126 } | |
127 srcfile = new File(srcfilename); | |
128 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
643
diff
changeset
|
129 // LDC |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
130 llvmForceLogging = false; |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
131 this->doDocComment = doDocComment; |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
132 this->doHdrGen = doHdrGen; |
956
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
133 uniqueId = 0; |
336 | 134 } |
135 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
136 File* Module::buildFilePath(char* forcename, char* path, char* ext) |
336 | 137 { |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
138 char *argobj; |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
139 if (forcename) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
140 argobj = forcename; |
336 | 141 else |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
142 { |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
143 if (global.params.preservePaths) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
144 argobj = (char*)this->arg; |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
145 else |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
146 argobj = FileName::name((char*)this->arg); |
336 | 147 |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
148 if (global.params.fqnNames) |
643 | 149 { |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
150 if(md) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
151 argobj = FileName::replaceName(argobj, md->toChars()); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
152 else |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
153 argobj = FileName::replaceName(argobj, toChars()); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
154 |
643 | 155 // add ext, otherwise forceExt will make nested.module into nested.bc |
156 size_t len = strlen(argobj); | |
157 size_t extlen = strlen(ext); | |
158 char* s = (char *)alloca(len + 1 + extlen + 1); | |
159 memcpy(s, argobj, len); | |
160 s[len] = '.'; | |
161 memcpy(s + len + 1, ext, extlen + 1); | |
162 s[len+1+extlen] = 0; | |
163 argobj = s; | |
164 } | |
336 | 165 } |
166 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
167 if (!FileName::absolute(argobj)) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
168 { |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
169 argobj = FileName::combine(path, argobj); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
170 } |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
171 |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
172 FileName::ensurePathExists(FileName::path(argobj)); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
173 |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
174 // always append the extension! otherwise hard to make output switches consistent |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
175 // if (forcename) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
176 // return new File(argobj); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
177 // else |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
178 // allow for .o and .obj on windows |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
179 #if _WIN32 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
180 if (ext == global.params.objdir && FileName::ext(argobj) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
181 && stricmp(FileName::ext(argobj), global.obj_ext_alt) == 0) |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
182 return new File(argobj); |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
183 #endif |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
184 return new File(FileName::forceExt(argobj, ext)); |
336 | 185 } |
186 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
187 void Module::buildTargetFiles() |
336 | 188 { |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
189 if(objfile && |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
190 (!doDocComment || docfile) && |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
191 (!doHdrGen || hdrfile)) |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
192 return; |
336 | 193 |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
194 if(!objfile) |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
664
diff
changeset
|
195 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext); |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
196 if(doDocComment && !docfile) |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
197 docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext); |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
198 if(doHdrGen && !hdrfile) |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
199 hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext); |
598
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
200 |
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
201 // safety check: never allow obj, doc or hdr file to have the source file's name |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
202 if(stricmp(FileName::name(objfile->name->str), FileName::name((char*)this->arg)) == 0) |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
203 { |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
204 error("Output object files with the same name as the source file are forbidden"); |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
205 fatal(); |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
206 } |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
207 if(docfile && stricmp(FileName::name(docfile->name->str), FileName::name((char*)this->arg)) == 0) |
598
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
208 { |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
209 error("Output doc files with the same name as the source file are forbidden"); |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
210 fatal(); |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
211 } |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
212 if(hdrfile && stricmp(FileName::name(hdrfile->name->str), FileName::name((char*)this->arg)) == 0) |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
213 { |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
214 error("Output header files with the same name as the source file are forbidden"); |
598
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
215 fatal(); |
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
216 } |
336 | 217 } |
218 | |
219 void Module::deleteObjFile() | |
220 { | |
221 if (global.params.obj) | |
222 objfile->remove(); | |
223 //if (global.params.llvmBC) | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
224 //bcfile->remove(); |
604
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
225 if (doDocComment && docfile) |
336 | 226 docfile->remove(); |
227 } | |
228 | |
229 Module::~Module() | |
230 { | |
231 } | |
232 | |
233 const char *Module::kind() | |
234 { | |
235 return "module"; | |
236 } | |
237 | |
238 Module *Module::load(Loc loc, Array *packages, Identifier *ident) | |
239 { Module *m; | |
240 char *filename; | |
241 | |
242 //printf("Module::load(ident = '%s')\n", ident->toChars()); | |
243 | |
244 // Build module filename by turning: | |
245 // foo.bar.baz | |
246 // into: | |
247 // foo\bar\baz | |
248 filename = ident->toChars(); | |
249 if (packages && packages->dim) | |
250 { | |
251 OutBuffer buf; | |
252 int i; | |
253 | |
254 for (i = 0; i < packages->dim; i++) | |
255 { Identifier *pid = (Identifier *)packages->data[i]; | |
256 | |
257 buf.writestring(pid->toChars()); | |
258 #if _WIN32 | |
259 buf.writeByte('\\'); | |
260 #else | |
261 buf.writeByte('/'); | |
262 #endif | |
263 } | |
264 buf.writestring(filename); | |
265 buf.writeByte(0); | |
266 filename = (char *)buf.extractData(); | |
267 } | |
268 | |
269 m = new Module(filename, ident, 0, 0); | |
270 m->loc = loc; | |
271 | |
272 /* Search along global.path for .di file, then .d file. | |
273 */ | |
274 char *result = NULL; | |
275 FileName *fdi = FileName::forceExt(filename, global.hdr_ext); | |
276 FileName *fd = FileName::forceExt(filename, global.mars_ext); | |
277 char *sdi = fdi->toChars(); | |
278 char *sd = fd->toChars(); | |
279 | |
280 if (FileName::exists(sdi)) | |
281 result = sdi; | |
282 else if (FileName::exists(sd)) | |
283 result = sd; | |
284 else if (FileName::absolute(filename)) | |
285 ; | |
286 else if (!global.path) | |
287 ; | |
288 else | |
289 { | |
290 for (size_t i = 0; i < global.path->dim; i++) | |
291 { | |
292 char *p = (char *)global.path->data[i]; | |
293 char *n = FileName::combine(p, sdi); | |
294 if (FileName::exists(n)) | |
295 { result = n; | |
296 break; | |
297 } | |
298 mem.free(n); | |
299 n = FileName::combine(p, sd); | |
300 if (FileName::exists(n)) | |
301 { result = n; | |
302 break; | |
303 } | |
304 mem.free(n); | |
305 } | |
306 } | |
307 if (result) | |
308 m->srcfile = new File(result); | |
309 | |
310 if (global.params.verbose) | |
311 { | |
312 printf("import "); | |
313 if (packages) | |
314 { | |
315 for (size_t i = 0; i < packages->dim; i++) | |
316 { Identifier *pid = (Identifier *)packages->data[i]; | |
317 printf("%s.", pid->toChars()); | |
318 } | |
319 } | |
320 printf("%s\t(%s)\n", ident->toChars(), m->srcfile->toChars()); | |
321 } | |
322 | |
323 m->read(loc); | |
324 m->parse(); | |
325 | |
326 #ifdef IN_GCC | |
327 d_gcc_magic_module(m); | |
328 #endif | |
329 | |
330 return m; | |
331 } | |
332 | |
333 void Module::read(Loc loc) | |
334 { | |
335 //printf("Module::read('%s') file '%s'\n", toChars(), srcfile->toChars()); | |
336 if (srcfile->read()) | |
337 { error(loc, "cannot read file '%s'", srcfile->toChars()); | |
338 fatal(); | |
339 } | |
340 } | |
341 | |
342 inline unsigned readwordLE(unsigned short *p) | |
343 { | |
344 #if __I86__ | |
345 return *p; | |
346 #else | |
347 return (((unsigned char *)p)[1] << 8) | ((unsigned char *)p)[0]; | |
348 #endif | |
349 } | |
350 | |
351 inline unsigned readwordBE(unsigned short *p) | |
352 { | |
353 return (((unsigned char *)p)[0] << 8) | ((unsigned char *)p)[1]; | |
354 } | |
355 | |
356 inline unsigned readlongLE(unsigned *p) | |
357 { | |
358 #if __I86__ | |
359 return *p; | |
360 #else | |
361 return ((unsigned char *)p)[0] | | |
362 (((unsigned char *)p)[1] << 8) | | |
363 (((unsigned char *)p)[2] << 16) | | |
364 (((unsigned char *)p)[3] << 24); | |
365 #endif | |
366 } | |
367 | |
368 inline unsigned readlongBE(unsigned *p) | |
369 { | |
370 return ((unsigned char *)p)[3] | | |
371 (((unsigned char *)p)[2] << 8) | | |
372 (((unsigned char *)p)[1] << 16) | | |
373 (((unsigned char *)p)[0] << 24); | |
374 } | |
375 | |
376 #if IN_GCC | |
377 void Module::parse(bool dump_source) | |
378 #else | |
379 void Module::parse() | |
380 #endif | |
381 { char *srcname; | |
382 unsigned char *buf; | |
383 unsigned buflen; | |
384 unsigned le; | |
385 unsigned bom; | |
386 | |
387 //printf("Module::parse()\n"); | |
388 | |
389 srcname = srcfile->name->toChars(); | |
390 //printf("Module::parse(srcname = '%s')\n", srcname); | |
391 | |
392 buf = srcfile->buffer; | |
393 buflen = srcfile->len; | |
394 | |
395 if (buflen >= 2) | |
396 { | |
397 /* Convert all non-UTF-8 formats to UTF-8. | |
398 * BOM : http://www.unicode.org/faq/utf_bom.html | |
399 * 00 00 FE FF UTF-32BE, big-endian | |
400 * FF FE 00 00 UTF-32LE, little-endian | |
401 * FE FF UTF-16BE, big-endian | |
402 * FF FE UTF-16LE, little-endian | |
403 * EF BB BF UTF-8 | |
404 */ | |
405 | |
406 bom = 1; // assume there's a BOM | |
407 if (buf[0] == 0xFF && buf[1] == 0xFE) | |
408 { | |
409 if (buflen >= 4 && buf[2] == 0 && buf[3] == 0) | |
410 { // UTF-32LE | |
411 le = 1; | |
412 | |
413 Lutf32: | |
414 OutBuffer dbuf; | |
415 unsigned *pu = (unsigned *)(buf); | |
416 unsigned *pumax = &pu[buflen / 4]; | |
417 | |
418 if (buflen & 3) | |
419 { error("odd length of UTF-32 char source %u", buflen); | |
420 fatal(); | |
421 } | |
422 | |
423 dbuf.reserve(buflen / 4); | |
424 for (pu += bom; pu < pumax; pu++) | |
425 { unsigned u; | |
426 | |
427 u = le ? readlongLE(pu) : readlongBE(pu); | |
428 if (u & ~0x7F) | |
429 { | |
430 if (u > 0x10FFFF) | |
431 { error("UTF-32 value %08x greater than 0x10FFFF", u); | |
432 fatal(); | |
433 } | |
434 dbuf.writeUTF8(u); | |
435 } | |
436 else | |
437 dbuf.writeByte(u); | |
438 } | |
439 dbuf.writeByte(0); // add 0 as sentinel for scanner | |
440 buflen = dbuf.offset - 1; // don't include sentinel in count | |
441 buf = (unsigned char *) dbuf.extractData(); | |
442 } | |
443 else | |
444 { // UTF-16LE (X86) | |
445 // Convert it to UTF-8 | |
446 le = 1; | |
447 | |
448 Lutf16: | |
449 OutBuffer dbuf; | |
450 unsigned short *pu = (unsigned short *)(buf); | |
451 unsigned short *pumax = &pu[buflen / 2]; | |
452 | |
453 if (buflen & 1) | |
454 { error("odd length of UTF-16 char source %u", buflen); | |
455 fatal(); | |
456 } | |
457 | |
458 dbuf.reserve(buflen / 2); | |
459 for (pu += bom; pu < pumax; pu++) | |
460 { unsigned u; | |
461 | |
462 u = le ? readwordLE(pu) : readwordBE(pu); | |
463 if (u & ~0x7F) | |
464 { if (u >= 0xD800 && u <= 0xDBFF) | |
465 { unsigned u2; | |
466 | |
467 if (++pu > pumax) | |
468 { error("surrogate UTF-16 high value %04x at EOF", u); | |
469 fatal(); | |
470 } | |
471 u2 = le ? readwordLE(pu) : readwordBE(pu); | |
472 if (u2 < 0xDC00 || u2 > 0xDFFF) | |
473 { error("surrogate UTF-16 low value %04x out of range", u2); | |
474 fatal(); | |
475 } | |
476 u = (u - 0xD7C0) << 10; | |
477 u |= (u2 - 0xDC00); | |
478 } | |
479 else if (u >= 0xDC00 && u <= 0xDFFF) | |
480 { error("unpaired surrogate UTF-16 value %04x", u); | |
481 fatal(); | |
482 } | |
483 else if (u == 0xFFFE || u == 0xFFFF) | |
484 { error("illegal UTF-16 value %04x", u); | |
485 fatal(); | |
486 } | |
487 dbuf.writeUTF8(u); | |
488 } | |
489 else | |
490 dbuf.writeByte(u); | |
491 } | |
492 dbuf.writeByte(0); // add 0 as sentinel for scanner | |
493 buflen = dbuf.offset - 1; // don't include sentinel in count | |
494 buf = (unsigned char *) dbuf.extractData(); | |
495 } | |
496 } | |
497 else if (buf[0] == 0xFE && buf[1] == 0xFF) | |
498 { // UTF-16BE | |
499 le = 0; | |
500 goto Lutf16; | |
501 } | |
502 else if (buflen >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 0xFE && buf[3] == 0xFF) | |
503 { // UTF-32BE | |
504 le = 0; | |
505 goto Lutf32; | |
506 } | |
507 else if (buflen >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) | |
508 { // UTF-8 | |
509 | |
510 buf += 3; | |
511 buflen -= 3; | |
512 } | |
513 else | |
514 { | |
515 /* There is no BOM. Make use of Arcane Jill's insight that | |
516 * the first char of D source must be ASCII to | |
517 * figure out the encoding. | |
518 */ | |
519 | |
520 bom = 0; | |
521 if (buflen >= 4) | |
522 { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0) | |
523 { // UTF-32LE | |
524 le = 1; | |
525 goto Lutf32; | |
526 } | |
527 else if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0) | |
528 { // UTF-32BE | |
529 le = 0; | |
530 goto Lutf32; | |
531 } | |
532 } | |
533 if (buflen >= 2) | |
534 { | |
535 if (buf[1] == 0) | |
536 { // UTF-16LE | |
537 le = 1; | |
538 goto Lutf16; | |
539 } | |
540 else if (buf[0] == 0) | |
541 { // UTF-16BE | |
542 le = 0; | |
543 goto Lutf16; | |
544 } | |
545 } | |
546 | |
547 // It's UTF-8 | |
548 if (buf[0] >= 0x80) | |
549 { error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]); | |
550 fatal(); | |
551 } | |
552 } | |
553 } | |
554 | |
555 #ifdef IN_GCC | |
556 // dump utf-8 encoded source | |
557 if (dump_source) | |
558 { // %% srcname could contain a path ... | |
559 d_gcc_dump_source(srcname, "utf-8", buf, buflen); | |
560 } | |
561 #endif | |
562 | |
563 /* If it starts with the string "Ddoc", then it's a documentation | |
564 * source file. | |
565 */ | |
566 if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0) | |
567 { | |
568 comment = buf + 4; | |
569 isDocFile = 1; | |
570 return; | |
571 } | |
572 if (isHtml) | |
573 { | |
574 OutBuffer *dbuf = new OutBuffer(); | |
575 Html h(srcname, buf, buflen); | |
576 h.extractCode(dbuf); | |
577 buf = dbuf->data; | |
578 buflen = dbuf->offset; | |
579 #ifdef IN_GCC | |
580 // dump extracted source | |
581 if (dump_source) | |
582 d_gcc_dump_source(srcname, "d.utf-8", buf, buflen); | |
583 #endif | |
584 } | |
585 Parser p(this, buf, buflen, docfile != NULL); | |
586 p.nextToken(); | |
587 members = p.parseModule(); | |
588 md = p.md; | |
589 numlines = p.loc.linnum; | |
590 | |
591 DsymbolTable *dst; | |
592 | |
593 if (md) | |
594 { this->ident = md->id; | |
595 dst = Package::resolve(md->packages, &this->parent, NULL); | |
596 } | |
597 else | |
598 { | |
599 dst = modules; | |
600 | |
601 /* Check to see if module name is a valid identifier | |
602 */ | |
603 if (!Lexer::isValidIdentifier(this->ident->toChars())) | |
604 error("has non-identifier characters in filename, use module declaration instead"); | |
605 } | |
606 | |
607 // Update global list of modules | |
608 if (!dst->insert(this)) | |
609 { | |
610 if (md) | |
611 error(loc, "is in multiple packages %s", md->toChars()); | |
612 else | |
613 error(loc, "is in multiple defined"); | |
614 } | |
615 else | |
616 { | |
617 amodules.push(this); | |
618 } | |
619 } | |
620 | |
751
dc8b8b7ea0c1
Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
621 void Module::semantic(Scope* unused_sc) |
336 | 622 { int i; |
623 | |
624 if (semanticstarted) | |
625 return; | |
626 | |
627 //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); | |
628 semanticstarted = 1; | |
629 | |
630 // Note that modules get their own scope, from scratch. | |
631 // This is so regardless of where in the syntax a module | |
632 // gets imported, it is unaffected by context. | |
633 Scope *sc = Scope::createGlobal(this); // create root scope | |
634 | |
635 //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage); | |
636 | |
637 // Add import of "object" if this module isn't "object" | |
638 if (ident != Id::object) | |
639 { | |
640 Import *im = new Import(0, NULL, Id::object, NULL, 0); | |
641 members->shift(im); | |
642 } | |
643 | |
644 // Add all symbols into module's symbol table | |
645 symtab = new DsymbolTable(); | |
646 for (i = 0; i < members->dim; i++) | |
647 { Dsymbol *s; | |
648 | |
649 s = (Dsymbol *)members->data[i]; | |
650 s->addMember(NULL, sc->scopesym, 1); | |
651 } | |
652 | |
653 // Pass 1 semantic routines: do public side of the definition | |
654 for (i = 0; i < members->dim; i++) | |
655 { Dsymbol *s; | |
656 | |
657 s = (Dsymbol *)members->data[i]; | |
658 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); | |
659 s->semantic(sc); | |
660 runDeferredSemantic(); | |
661 } | |
662 | |
663 sc = sc->pop(); | |
664 sc->pop(); | |
665 semanticdone = semanticstarted; | |
666 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); | |
667 } | |
668 | |
751
dc8b8b7ea0c1
Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
669 void Module::semantic2(Scope* unused_sc) |
336 | 670 { int i; |
671 | |
672 if (deferred.dim) | |
673 { | |
674 for (int i = 0; i < deferred.dim; i++) | |
675 { | |
676 Dsymbol *sd = (Dsymbol *)deferred.data[i]; | |
677 | |
678 sd->error("unable to resolve forward reference in definition"); | |
679 } | |
680 return; | |
681 } | |
682 //printf("Module::semantic2('%s'): parent = %p\n", toChars(), parent); | |
683 if (semanticstarted >= 2) | |
684 return; | |
685 assert(semanticstarted == 1); | |
686 semanticstarted = 2; | |
687 | |
688 // Note that modules get their own scope, from scratch. | |
689 // This is so regardless of where in the syntax a module | |
690 // gets imported, it is unaffected by context. | |
691 Scope *sc = Scope::createGlobal(this); // create root scope | |
692 //printf("Module = %p\n", sc.scopesym); | |
693 | |
694 // Pass 2 semantic routines: do initializers and function bodies | |
695 for (i = 0; i < members->dim; i++) | |
696 { Dsymbol *s; | |
697 | |
698 s = (Dsymbol *)members->data[i]; | |
699 s->semantic2(sc); | |
700 } | |
701 | |
702 sc = sc->pop(); | |
703 sc->pop(); | |
704 semanticdone = semanticstarted; | |
705 //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); | |
706 } | |
707 | |
751
dc8b8b7ea0c1
Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
708 void Module::semantic3(Scope* unused_sc) |
336 | 709 { int i; |
710 | |
711 //printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent); | |
712 if (semanticstarted >= 3) | |
713 return; | |
714 assert(semanticstarted == 2); | |
715 semanticstarted = 3; | |
716 | |
717 // Note that modules get their own scope, from scratch. | |
718 // This is so regardless of where in the syntax a module | |
719 // gets imported, it is unaffected by context. | |
720 Scope *sc = Scope::createGlobal(this); // create root scope | |
721 //printf("Module = %p\n", sc.scopesym); | |
722 | |
723 // Pass 3 semantic routines: do initializers and function bodies | |
724 for (i = 0; i < members->dim; i++) | |
725 { Dsymbol *s; | |
726 | |
727 s = (Dsymbol *)members->data[i]; | |
728 //printf("Module %s: %s.semantic3()\n", toChars(), s->toChars()); | |
729 s->semantic3(sc); | |
730 } | |
731 | |
732 sc = sc->pop(); | |
733 sc->pop(); | |
734 semanticdone = semanticstarted; | |
735 } | |
736 | |
737 void Module::inlineScan() | |
738 { int i; | |
739 | |
740 if (semanticstarted >= 4) | |
741 return; | |
742 assert(semanticstarted == 3); | |
743 semanticstarted = 4; | |
744 | |
745 // Note that modules get their own scope, from scratch. | |
746 // This is so regardless of where in the syntax a module | |
747 // gets imported, it is unaffected by context. | |
748 //printf("Module = %p\n", sc.scopesym); | |
749 | |
750 for (i = 0; i < members->dim; i++) | |
751 { Dsymbol *s; | |
752 | |
753 s = (Dsymbol *)members->data[i]; | |
754 //if (global.params.verbose) | |
755 //printf("inline scan symbol %s\n", s->toChars()); | |
756 | |
757 s->inlineScan(); | |
758 } | |
759 semanticdone = semanticstarted; | |
760 } | |
761 | |
762 /**************************************************** | |
763 */ | |
764 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
765 // is this used anywhere? |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
766 /* |
336 | 767 void Module::gensymfile() |
768 { | |
769 OutBuffer buf; | |
770 HdrGenState hgs; | |
771 | |
772 //printf("Module::gensymfile()\n"); | |
773 | |
774 buf.printf("// Sym file generated from '%s'", srcfile->toChars()); | |
775 buf.writenl(); | |
776 | |
777 for (int i = 0; i < members->dim; i++) | |
778 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
779 | |
780 s->toCBuffer(&buf, &hgs); | |
781 } | |
782 | |
783 // Transfer image to file | |
784 symfile->setbuffer(buf.data, buf.offset); | |
785 buf.data = NULL; | |
786 | |
787 symfile->writev(); | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
788 }*/ |
336 | 789 |
790 /********************************** | |
791 * Determine if we need to generate an instance of ModuleInfo | |
792 * for this Module. | |
793 */ | |
794 | |
795 int Module::needModuleInfo() | |
796 { | |
550
cbe08531430f
Removed unimplemented switches.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
510
diff
changeset
|
797 return needmoduleinfo; |
336 | 798 } |
799 | |
800 Dsymbol *Module::search(Loc loc, Identifier *ident, int flags) | |
801 { | |
802 /* Since modules can be circularly referenced, | |
803 * need to stop infinite recursive searches. | |
804 */ | |
805 | |
806 //printf("%s Module::search('%s', flags = %d) insearch = %d\n", toChars(), ident->toChars(), flags, insearch); | |
807 Dsymbol *s; | |
808 if (insearch) | |
809 s = NULL; | |
810 else if (searchCacheIdent == ident && searchCacheFlags == flags) | |
811 s = searchCacheSymbol; | |
812 else | |
813 { | |
814 insearch = 1; | |
815 s = ScopeDsymbol::search(loc, ident, flags); | |
816 insearch = 0; | |
817 | |
818 searchCacheIdent = ident; | |
819 searchCacheSymbol = s; | |
820 searchCacheFlags = flags; | |
821 } | |
822 return s; | |
823 } | |
824 | |
825 /******************************************* | |
826 * Can't run semantic on s now, try again later. | |
827 */ | |
828 | |
829 void Module::addDeferredSemantic(Dsymbol *s) | |
830 { | |
831 // Don't add it if it is already there | |
832 for (int i = 0; i < deferred.dim; i++) | |
833 { | |
834 Dsymbol *sd = (Dsymbol *)deferred.data[i]; | |
835 | |
836 if (sd == s) | |
837 return; | |
838 } | |
839 | |
840 //printf("Module::addDeferredSemantic('%s')\n", s->toChars()); | |
841 deferred.push(s); | |
842 } | |
843 | |
844 | |
845 /****************************************** | |
846 * Run semantic() on deferred symbols. | |
847 */ | |
848 | |
849 void Module::runDeferredSemantic() | |
850 { | |
851 size_t len; | |
852 | |
853 static int nested; | |
854 if (nested) | |
855 return; | |
856 //if (deferred.dim) printf("+Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); | |
857 nested++; | |
858 | |
859 do | |
860 { | |
861 dprogress = 0; | |
862 len = deferred.dim; | |
863 if (!len) | |
864 break; | |
865 | |
866 Dsymbol **todo; | |
867 Dsymbol *tmp; | |
868 if (len == 1) | |
869 { | |
870 todo = &tmp; | |
871 } | |
872 else | |
873 { | |
874 todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *)); | |
875 assert(todo); | |
876 } | |
877 memcpy(todo, deferred.data, len * sizeof(Dsymbol *)); | |
878 deferred.setDim(0); | |
879 | |
880 for (int i = 0; i < len; i++) | |
881 { | |
882 Dsymbol *s = todo[i]; | |
883 | |
884 s->semantic(NULL); | |
885 //printf("deferred: %s, parent = %s\n", s->toChars(), s->parent->toChars()); | |
886 } | |
887 //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress); | |
888 } while (deferred.dim < len || dprogress); // while making progress | |
889 nested--; | |
890 //printf("-Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); | |
891 } | |
892 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
893 /************************************ |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
894 * Recursively look at every module this module imports, |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
895 * return TRUE if it imports m. |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
896 * Can be used to detect circular imports. |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
897 */ |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
898 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
899 int Module::imports(Module *m) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
900 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
901 //printf("%s Module::imports(%s)\n", toChars(), m->toChars()); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
902 int aimports_dim = aimports.dim; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
903 #if 0 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
904 for (int i = 0; i < aimports.dim; i++) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
905 { Module *mi = (Module *)aimports.data[i]; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
906 printf("\t[%d] %s\n", i, mi->toChars()); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
907 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
908 #endif |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
909 for (int i = 0; i < aimports.dim; i++) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
910 { Module *mi = (Module *)aimports.data[i]; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
911 if (mi == m) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
912 return TRUE; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
913 if (!mi->insearch) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
914 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
915 mi->insearch = 1; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
916 int r = mi->imports(m); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
917 mi->insearch = 0; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
918 if (r) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
919 return r; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
920 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
921 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
922 return FALSE; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
923 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
924 |
336 | 925 /* =========================== ModuleDeclaration ===================== */ |
926 | |
927 ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id) | |
928 { | |
929 this->packages = packages; | |
930 this->id = id; | |
931 } | |
932 | |
933 char *ModuleDeclaration::toChars() | |
934 { | |
935 OutBuffer buf; | |
936 int i; | |
937 | |
938 if (packages && packages->dim) | |
939 { | |
940 for (i = 0; i < packages->dim; i++) | |
941 { Identifier *pid = (Identifier *)packages->data[i]; | |
942 | |
943 buf.writestring(pid->toChars()); | |
944 buf.writeByte('.'); | |
945 } | |
946 } | |
947 buf.writestring(id->toChars()); | |
948 buf.writeByte(0); | |
949 return (char *)buf.extractData(); | |
950 } | |
951 | |
952 /* =========================== Package ===================== */ | |
953 | |
954 Package::Package(Identifier *ident) | |
955 : ScopeDsymbol(ident) | |
956 { | |
957 } | |
958 | |
959 | |
960 const char *Package::kind() | |
961 { | |
962 return "package"; | |
963 } | |
964 | |
965 | |
966 DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppkg) | |
967 { | |
968 DsymbolTable *dst = Module::modules; | |
969 Dsymbol *parent = NULL; | |
970 | |
971 //printf("Package::resolve()\n"); | |
972 if (ppkg) | |
973 *ppkg = NULL; | |
974 | |
975 if (packages) | |
976 { int i; | |
977 | |
978 for (i = 0; i < packages->dim; i++) | |
979 { Identifier *pid = (Identifier *)packages->data[i]; | |
980 Dsymbol *p; | |
981 | |
982 p = dst->lookup(pid); | |
983 if (!p) | |
984 { | |
985 p = new Package(pid); | |
986 dst->insert(p); | |
987 p->parent = parent; | |
988 ((ScopeDsymbol *)p)->symtab = new DsymbolTable(); | |
989 } | |
990 else | |
991 { | |
992 assert(p->isPackage()); | |
993 if (p->isModule()) | |
994 { p->error("module and package have the same name"); | |
995 fatal(); | |
996 break; | |
997 } | |
998 } | |
999 parent = p; | |
1000 dst = ((Package *)p)->symtab; | |
1001 if (ppkg && !*ppkg) | |
1002 *ppkg = (Package *)p; | |
1003 } | |
1004 if (pparent) | |
1005 { | |
1006 *pparent = parent; | |
1007 } | |
1008 } | |
1009 return dst; | |
1010 } | |
956
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
1011 |
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
1012 Identifier* Module::generateId(Identifier* id) |
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
1013 { |
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
1014 return Identifier::generateId(id->string, uniqueId++); |
369996c08420
Change the numbering of static ctors/dtors to be module based instead of being global.
Christian Kamm <kamm incasoftware de>
parents:
875
diff
changeset
|
1015 } |