Mercurial > projects > ldc
annotate dmd/module.c @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | a8fc855f156e |
children |
rev | line source |
---|---|
336 | 1 |
2 // Compiler implementation of the D programming language | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
3 // Copyright (c) 1999-2010 by Digital Mars |
336 | 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 |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
19 #if defined(_MSC_VER) || defined(__MINGW32__) |
336 | 20 #include <malloc.h> |
21 #endif | |
22 | |
23 #if IN_GCC | |
24 #include "gdc_alloca.h" | |
25 #endif | |
26 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
27 #include "rmem.h" |
336 | 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 | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
47 #if IN_LLVM |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
48 #include "llvm/Support/CommandLine.h" |
1564
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
49 #include <map> |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
50 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
51 static llvm::cl::opt<bool> preservePaths("op", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
52 llvm::cl::desc("Do not strip paths from source file"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
53 llvm::cl::ZeroOrMore); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
54 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
55 static llvm::cl::opt<bool> fqnNames("oq", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
56 llvm::cl::desc("Write object files with fully qualified names"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
57 llvm::cl::ZeroOrMore); |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
58 #endif |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
59 |
336 | 60 ClassDeclaration *Module::moduleinfo; |
61 | |
62 Module *Module::rootModule; | |
63 DsymbolTable *Module::modules; | |
64 Array Module::amodules; | |
65 | |
66 Array Module::deferred; // deferred Dsymbol's needing semantic() run on them | |
67 unsigned Module::dprogress; | |
68 | |
69 void Module::init() | |
70 { | |
71 modules = new DsymbolTable(); | |
72 } | |
73 | |
74 Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen) | |
75 : Package(ident) | |
76 { | |
77 FileName *srcfilename; | |
78 | |
79 // printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars()); | |
80 this->arg = filename; | |
81 md = NULL; | |
82 errors = 0; | |
83 numlines = 0; | |
84 members = NULL; | |
85 isHtml = 0; | |
86 isDocFile = 0; | |
87 needmoduleinfo = 0; | |
88 #ifdef IN_GCC | |
89 strictlyneedmoduleinfo = 0; | |
90 #endif | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
91 selfimports = 0; |
336 | 92 insearch = 0; |
93 searchCacheIdent = NULL; | |
94 searchCacheSymbol = NULL; | |
95 searchCacheFlags = 0; | |
96 semanticstarted = 0; | |
1587 | 97 semanticRun = 0; |
336 | 98 decldefs = NULL; |
99 vmoduleinfo = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
100 #if IN_DMD |
336 | 101 massert = NULL; |
102 marray = NULL; | |
103 sictor = NULL; | |
104 sctor = NULL; | |
105 sdtor = NULL; | |
106 stest = NULL; | |
107 sfilename = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
108 #endif |
336 | 109 root = 0; |
110 importedFrom = NULL; | |
111 srcfile = NULL; | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
112 objfile = NULL; |
336 | 113 docfile = NULL; |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
114 hdrfile = NULL; |
336 | 115 |
116 debuglevel = 0; | |
117 debugids = NULL; | |
118 debugidsNot = NULL; | |
119 versionlevel = 0; | |
120 versionids = NULL; | |
121 versionidsNot = NULL; | |
122 | |
123 macrotable = NULL; | |
124 escapetable = NULL; | |
1587 | 125 safe = FALSE; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
126 #if IN_DMD |
336 | 127 doppelganger = 0; |
128 cov = NULL; | |
129 covb = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
130 #endif |
336 | 131 |
132 srcfilename = FileName::defaultExt(filename, global.mars_ext); | |
133 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
|
134 !srcfilename->equalsExt(global.hdr_ext) && |
336 | 135 !srcfilename->equalsExt("dd")) |
136 { | |
137 if (srcfilename->equalsExt("html") || | |
138 srcfilename->equalsExt("htm") || | |
139 srcfilename->equalsExt("xhtml")) | |
140 isHtml = 1; | |
141 else | |
142 { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext); | |
143 fatal(); | |
144 } | |
145 } | |
146 srcfile = new File(srcfilename); | |
147 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
643
diff
changeset
|
148 // 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
|
149 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
|
150 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
|
151 this->doHdrGen = doHdrGen; |
336 | 152 } |
153 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
154 File* Module::buildFilePath(const char* forcename, const char* path, const char* ext) |
336 | 155 { |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
156 const char *argobj; |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
157 if (forcename) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
158 argobj = forcename; |
336 | 159 else |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
160 { |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
161 if (preservePaths) |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
162 argobj = (char*)this->arg; |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
163 else |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
164 argobj = FileName::name((char*)this->arg); |
336 | 165 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
957
diff
changeset
|
166 if (fqnNames) |
643 | 167 { |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
168 if(md) |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
169 argobj = FileName::replaceName((char*)argobj, md->toChars()); |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
170 else |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
171 argobj = FileName::replaceName((char*)argobj, toChars()); |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
172 |
643 | 173 // add ext, otherwise forceExt will make nested.module into nested.bc |
174 size_t len = strlen(argobj); | |
175 size_t extlen = strlen(ext); | |
176 char* s = (char *)alloca(len + 1 + extlen + 1); | |
177 memcpy(s, argobj, len); | |
178 s[len] = '.'; | |
179 memcpy(s + len + 1, ext, extlen + 1); | |
180 s[len+1+extlen] = 0; | |
181 argobj = s; | |
182 } | |
336 | 183 } |
184 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
185 if (!FileName::absolute(argobj)) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
186 { |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
187 argobj = FileName::combine(path, argobj); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
188 } |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
189 |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
190 FileName::ensurePathExists(FileName::path(argobj)); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
191 |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
192 // 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
|
193 // if (forcename) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
194 // 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
|
195 // else |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
196 // 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
|
197 #if _WIN32 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
198 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
|
199 && stricmp(FileName::ext(argobj), global.obj_ext_alt) == 0) |
1257
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1195
diff
changeset
|
200 return new File((char*)argobj); |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
201 #endif |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
202 return new File(FileName::forceExt(argobj, ext)); |
336 | 203 } |
204 | |
1564
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
205 // LDC |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
206 static void check_and_add_output_file(Module* NewMod, const std::string& str) |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
207 { |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
208 typedef std::map<std::string, Module*> map_t; |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
209 static map_t files; |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
210 |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
211 map_t::iterator i = files.find(str); |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
212 if (i != files.end()) |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
213 { |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
214 Module* ThisMod = i->second; |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
215 error("Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option", |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
216 str.c_str(), NewMod->toPrettyChars(), ThisMod->toPrettyChars()); |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
217 fatal(); |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
218 } |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
219 files.insert(std::make_pair(str, NewMod)); |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
220 } |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
221 |
1645
1d2d1aa16841
Don't error out with -singleobj, -of, and -c/-output-{bc,ll,o,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1640
diff
changeset
|
222 void Module::buildTargetFiles(bool singleObj) |
336 | 223 { |
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
|
224 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
|
225 (!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
|
226 (!doHdrGen || hdrfile)) |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
227 return; |
336 | 228 |
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
|
229 if(!objfile) |
1646
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
230 { |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
231 if (global.params.output_bc) |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
232 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext); |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
233 else if (global.params.output_ll) |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
234 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.ll_ext); |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
235 else if (global.params.output_s) |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
236 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext); |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
237 else |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
238 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext); |
a8fc855f156e
Don't remove an old .o with -output-{bc,ll,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1645
diff
changeset
|
239 } |
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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 |
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
245 // 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
|
246 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
|
247 { |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
248 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
|
249 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
|
250 } |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
251 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
|
252 { |
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
|
253 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
|
254 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
|
255 } |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
256 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
|
257 { |
a30fc28e8f23
Make creating and deleting of doc and hdr files dependent on whether doc and
Christian Kamm <kamm incasoftware de>
parents:
598
diff
changeset
|
258 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
|
259 fatal(); |
13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
Christian Kamm <kamm incasoftware de>
parents:
597
diff
changeset
|
260 } |
1564
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
261 |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
262 // LDC |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
263 // another safety check to make sure we don't overwrite previous output files |
1645
1d2d1aa16841
Don't error out with -singleobj, -of, and -c/-output-{bc,ll,o,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1640
diff
changeset
|
264 if (!singleObj) |
1d2d1aa16841
Don't error out with -singleobj, -of, and -c/-output-{bc,ll,o,s}.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1640
diff
changeset
|
265 check_and_add_output_file(this, objfile->name->str); |
1564
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
266 if (docfile) |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
267 check_and_add_output_file(this, docfile->name->str); |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
268 if (hdrfile) |
68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1257
diff
changeset
|
269 check_and_add_output_file(this, hdrfile->name->str); |
336 | 270 } |
271 | |
272 void Module::deleteObjFile() | |
273 { | |
274 if (global.params.obj) | |
275 objfile->remove(); | |
276 //if (global.params.llvmBC) | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
277 //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
|
278 if (doDocComment && docfile) |
336 | 279 docfile->remove(); |
280 } | |
281 | |
282 Module::~Module() | |
283 { | |
284 } | |
285 | |
286 const char *Module::kind() | |
287 { | |
288 return "module"; | |
289 } | |
290 | |
291 Module *Module::load(Loc loc, Array *packages, Identifier *ident) | |
292 { Module *m; | |
293 char *filename; | |
294 | |
295 //printf("Module::load(ident = '%s')\n", ident->toChars()); | |
296 | |
297 // Build module filename by turning: | |
298 // foo.bar.baz | |
299 // into: | |
300 // foo\bar\baz | |
301 filename = ident->toChars(); | |
302 if (packages && packages->dim) | |
303 { | |
304 OutBuffer buf; | |
305 int i; | |
306 | |
307 for (i = 0; i < packages->dim; i++) | |
308 { Identifier *pid = (Identifier *)packages->data[i]; | |
309 | |
310 buf.writestring(pid->toChars()); | |
311 #if _WIN32 | |
312 buf.writeByte('\\'); | |
313 #else | |
314 buf.writeByte('/'); | |
315 #endif | |
316 } | |
317 buf.writestring(filename); | |
318 buf.writeByte(0); | |
319 filename = (char *)buf.extractData(); | |
320 } | |
321 | |
322 m = new Module(filename, ident, 0, 0); | |
323 m->loc = loc; | |
324 | |
325 /* Search along global.path for .di file, then .d file. | |
326 */ | |
327 char *result = NULL; | |
328 FileName *fdi = FileName::forceExt(filename, global.hdr_ext); | |
329 FileName *fd = FileName::forceExt(filename, global.mars_ext); | |
330 char *sdi = fdi->toChars(); | |
331 char *sd = fd->toChars(); | |
332 | |
333 if (FileName::exists(sdi)) | |
334 result = sdi; | |
335 else if (FileName::exists(sd)) | |
336 result = sd; | |
337 else if (FileName::absolute(filename)) | |
338 ; | |
339 else if (!global.path) | |
340 ; | |
341 else | |
342 { | |
343 for (size_t i = 0; i < global.path->dim; i++) | |
344 { | |
345 char *p = (char *)global.path->data[i]; | |
346 char *n = FileName::combine(p, sdi); | |
347 if (FileName::exists(n)) | |
348 { result = n; | |
349 break; | |
350 } | |
351 mem.free(n); | |
352 n = FileName::combine(p, sd); | |
353 if (FileName::exists(n)) | |
354 { result = n; | |
355 break; | |
356 } | |
357 mem.free(n); | |
358 } | |
359 } | |
360 if (result) | |
361 m->srcfile = new File(result); | |
362 | |
363 if (global.params.verbose) | |
364 { | |
365 printf("import "); | |
366 if (packages) | |
367 { | |
368 for (size_t i = 0; i < packages->dim; i++) | |
369 { Identifier *pid = (Identifier *)packages->data[i]; | |
370 printf("%s.", pid->toChars()); | |
371 } | |
372 } | |
373 printf("%s\t(%s)\n", ident->toChars(), m->srcfile->toChars()); | |
374 } | |
375 | |
376 m->read(loc); | |
377 m->parse(); | |
378 | |
379 #ifdef IN_GCC | |
380 d_gcc_magic_module(m); | |
381 #endif | |
382 | |
383 return m; | |
384 } | |
385 | |
386 void Module::read(Loc loc) | |
387 { | |
388 //printf("Module::read('%s') file '%s'\n", toChars(), srcfile->toChars()); | |
389 if (srcfile->read()) | |
390 { error(loc, "cannot read file '%s'", srcfile->toChars()); | |
391 fatal(); | |
392 } | |
393 } | |
394 | |
395 inline unsigned readwordLE(unsigned short *p) | |
396 { | |
397 #if __I86__ | |
398 return *p; | |
399 #else | |
400 return (((unsigned char *)p)[1] << 8) | ((unsigned char *)p)[0]; | |
401 #endif | |
402 } | |
403 | |
404 inline unsigned readwordBE(unsigned short *p) | |
405 { | |
406 return (((unsigned char *)p)[0] << 8) | ((unsigned char *)p)[1]; | |
407 } | |
408 | |
409 inline unsigned readlongLE(unsigned *p) | |
410 { | |
411 #if __I86__ | |
412 return *p; | |
413 #else | |
414 return ((unsigned char *)p)[0] | | |
415 (((unsigned char *)p)[1] << 8) | | |
416 (((unsigned char *)p)[2] << 16) | | |
417 (((unsigned char *)p)[3] << 24); | |
418 #endif | |
419 } | |
420 | |
421 inline unsigned readlongBE(unsigned *p) | |
422 { | |
423 return ((unsigned char *)p)[3] | | |
424 (((unsigned char *)p)[2] << 8) | | |
425 (((unsigned char *)p)[1] << 16) | | |
426 (((unsigned char *)p)[0] << 24); | |
427 } | |
428 | |
429 #if IN_GCC | |
430 void Module::parse(bool dump_source) | |
431 #else | |
432 void Module::parse() | |
433 #endif | |
434 { char *srcname; | |
435 unsigned char *buf; | |
436 unsigned buflen; | |
437 unsigned le; | |
438 unsigned bom; | |
439 | |
440 //printf("Module::parse()\n"); | |
441 | |
442 srcname = srcfile->name->toChars(); | |
443 //printf("Module::parse(srcname = '%s')\n", srcname); | |
444 | |
445 buf = srcfile->buffer; | |
446 buflen = srcfile->len; | |
447 | |
448 if (buflen >= 2) | |
449 { | |
450 /* Convert all non-UTF-8 formats to UTF-8. | |
451 * BOM : http://www.unicode.org/faq/utf_bom.html | |
452 * 00 00 FE FF UTF-32BE, big-endian | |
453 * FF FE 00 00 UTF-32LE, little-endian | |
454 * FE FF UTF-16BE, big-endian | |
455 * FF FE UTF-16LE, little-endian | |
456 * EF BB BF UTF-8 | |
457 */ | |
458 | |
459 bom = 1; // assume there's a BOM | |
460 if (buf[0] == 0xFF && buf[1] == 0xFE) | |
461 { | |
462 if (buflen >= 4 && buf[2] == 0 && buf[3] == 0) | |
463 { // UTF-32LE | |
464 le = 1; | |
465 | |
466 Lutf32: | |
467 OutBuffer dbuf; | |
468 unsigned *pu = (unsigned *)(buf); | |
469 unsigned *pumax = &pu[buflen / 4]; | |
470 | |
471 if (buflen & 3) | |
472 { error("odd length of UTF-32 char source %u", buflen); | |
473 fatal(); | |
474 } | |
475 | |
476 dbuf.reserve(buflen / 4); | |
477 for (pu += bom; pu < pumax; pu++) | |
478 { unsigned u; | |
479 | |
480 u = le ? readlongLE(pu) : readlongBE(pu); | |
481 if (u & ~0x7F) | |
482 { | |
483 if (u > 0x10FFFF) | |
484 { error("UTF-32 value %08x greater than 0x10FFFF", 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 else | |
497 { // UTF-16LE (X86) | |
498 // Convert it to UTF-8 | |
499 le = 1; | |
500 | |
501 Lutf16: | |
502 OutBuffer dbuf; | |
503 unsigned short *pu = (unsigned short *)(buf); | |
504 unsigned short *pumax = &pu[buflen / 2]; | |
505 | |
506 if (buflen & 1) | |
507 { error("odd length of UTF-16 char source %u", buflen); | |
508 fatal(); | |
509 } | |
510 | |
511 dbuf.reserve(buflen / 2); | |
512 for (pu += bom; pu < pumax; pu++) | |
513 { unsigned u; | |
514 | |
515 u = le ? readwordLE(pu) : readwordBE(pu); | |
516 if (u & ~0x7F) | |
517 { if (u >= 0xD800 && u <= 0xDBFF) | |
518 { unsigned u2; | |
519 | |
520 if (++pu > pumax) | |
521 { error("surrogate UTF-16 high value %04x at EOF", u); | |
522 fatal(); | |
523 } | |
524 u2 = le ? readwordLE(pu) : readwordBE(pu); | |
525 if (u2 < 0xDC00 || u2 > 0xDFFF) | |
526 { error("surrogate UTF-16 low value %04x out of range", u2); | |
527 fatal(); | |
528 } | |
529 u = (u - 0xD7C0) << 10; | |
530 u |= (u2 - 0xDC00); | |
531 } | |
532 else if (u >= 0xDC00 && u <= 0xDFFF) | |
533 { error("unpaired surrogate UTF-16 value %04x", u); | |
534 fatal(); | |
535 } | |
536 else if (u == 0xFFFE || u == 0xFFFF) | |
537 { error("illegal UTF-16 value %04x", u); | |
538 fatal(); | |
539 } | |
540 dbuf.writeUTF8(u); | |
541 } | |
542 else | |
543 dbuf.writeByte(u); | |
544 } | |
545 dbuf.writeByte(0); // add 0 as sentinel for scanner | |
546 buflen = dbuf.offset - 1; // don't include sentinel in count | |
547 buf = (unsigned char *) dbuf.extractData(); | |
548 } | |
549 } | |
550 else if (buf[0] == 0xFE && buf[1] == 0xFF) | |
551 { // UTF-16BE | |
552 le = 0; | |
553 goto Lutf16; | |
554 } | |
555 else if (buflen >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 0xFE && buf[3] == 0xFF) | |
556 { // UTF-32BE | |
557 le = 0; | |
558 goto Lutf32; | |
559 } | |
560 else if (buflen >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) | |
561 { // UTF-8 | |
562 | |
563 buf += 3; | |
564 buflen -= 3; | |
565 } | |
566 else | |
567 { | |
568 /* There is no BOM. Make use of Arcane Jill's insight that | |
569 * the first char of D source must be ASCII to | |
570 * figure out the encoding. | |
571 */ | |
572 | |
573 bom = 0; | |
574 if (buflen >= 4) | |
575 { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0) | |
576 { // UTF-32LE | |
577 le = 1; | |
578 goto Lutf32; | |
579 } | |
580 else if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0) | |
581 { // UTF-32BE | |
582 le = 0; | |
583 goto Lutf32; | |
584 } | |
585 } | |
586 if (buflen >= 2) | |
587 { | |
588 if (buf[1] == 0) | |
589 { // UTF-16LE | |
590 le = 1; | |
591 goto Lutf16; | |
592 } | |
593 else if (buf[0] == 0) | |
594 { // UTF-16BE | |
595 le = 0; | |
596 goto Lutf16; | |
597 } | |
598 } | |
599 | |
600 // It's UTF-8 | |
601 if (buf[0] >= 0x80) | |
602 { error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]); | |
603 fatal(); | |
604 } | |
605 } | |
606 } | |
607 | |
608 #ifdef IN_GCC | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
609 // dump utf-8 encoded source |
336 | 610 if (dump_source) |
611 { // %% srcname could contain a path ... | |
612 d_gcc_dump_source(srcname, "utf-8", buf, buflen); | |
613 } | |
614 #endif | |
615 | |
616 /* If it starts with the string "Ddoc", then it's a documentation | |
617 * source file. | |
618 */ | |
619 if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0) | |
620 { | |
621 comment = buf + 4; | |
622 isDocFile = 1; | |
623 return; | |
624 } | |
625 if (isHtml) | |
626 { | |
627 OutBuffer *dbuf = new OutBuffer(); | |
628 Html h(srcname, buf, buflen); | |
629 h.extractCode(dbuf); | |
630 buf = dbuf->data; | |
631 buflen = dbuf->offset; | |
632 #ifdef IN_GCC | |
633 // dump extracted source | |
634 if (dump_source) | |
635 d_gcc_dump_source(srcname, "d.utf-8", buf, buflen); | |
636 #endif | |
637 } | |
638 Parser p(this, buf, buflen, docfile != NULL); | |
639 p.nextToken(); | |
640 members = p.parseModule(); | |
641 md = p.md; | |
642 numlines = p.loc.linnum; | |
643 | |
644 DsymbolTable *dst; | |
645 | |
646 if (md) | |
647 { this->ident = md->id; | |
648 dst = Package::resolve(md->packages, &this->parent, NULL); | |
649 } | |
650 else | |
651 { | |
652 dst = modules; | |
653 | |
654 /* Check to see if module name is a valid identifier | |
655 */ | |
656 if (!Lexer::isValidIdentifier(this->ident->toChars())) | |
657 error("has non-identifier characters in filename, use module declaration instead"); | |
658 } | |
659 | |
660 // Update global list of modules | |
661 if (!dst->insert(this)) | |
662 { | |
663 if (md) | |
664 error(loc, "is in multiple packages %s", md->toChars()); | |
665 else | |
666 error(loc, "is in multiple defined"); | |
667 } | |
668 else | |
669 { | |
670 amodules.push(this); | |
671 } | |
672 } | |
673 | |
1587 | 674 void Module::importAll(Scope *prevsc) |
675 { | |
676 //printf("+Module::importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent); | |
677 | |
678 if (scope) | |
679 return; // already done | |
680 | |
681 /* Note that modules get their own scope, from scratch. | |
682 * This is so regardless of where in the syntax a module | |
683 * gets imported, it is unaffected by context. | |
684 * Ignore prevsc. | |
685 */ | |
686 Scope *sc = Scope::createGlobal(this); // create root scope | |
687 | |
688 // Add import of "object" if this module isn't "object" | |
689 if (ident != Id::object) | |
690 { | |
691 if (members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object) | |
692 { | |
693 Import *im = new Import(0, NULL, Id::object, NULL, 0); | |
694 members->shift(im); | |
695 } | |
696 } | |
336 | 697 |
1587 | 698 if (!symtab) |
699 { | |
700 // Add all symbols into module's symbol table | |
701 symtab = new DsymbolTable(); | |
702 for (int i = 0; i < members->dim; i++) | |
703 { | |
704 Dsymbol *s = (Dsymbol *)members->data[i]; | |
705 s->addMember(NULL, sc->scopesym, 1); | |
706 } | |
707 } | |
708 // anything else should be run after addMember, so version/debug symbols are defined | |
709 | |
710 /* Set scope for the symbols so that if we forward reference | |
711 * a symbol, it can possibly be resolved on the spot. | |
712 * If this works out well, it can be extended to all modules | |
713 * before any semantic() on any of them. | |
714 */ | |
715 setScope(sc); // remember module scope for semantic | |
716 for (int i = 0; i < members->dim; i++) | |
717 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
718 s->setScope(sc); | |
719 } | |
720 | |
721 for (int i = 0; i < members->dim; i++) | |
722 { | |
723 Dsymbol *s = (Dsymbol *)members->data[i]; | |
724 s->importAll(sc); | |
725 } | |
726 | |
727 sc = sc->pop(); | |
728 sc->pop(); // 2 pops because Scope::createGlobal() created 2 | |
729 } | |
730 | |
731 void Module::semantic(Scope *unused_sc) | |
732 { | |
336 | 733 if (semanticstarted) |
734 return; | |
735 | |
736 //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); | |
737 semanticstarted = 1; | |
738 | |
739 // Note that modules get their own scope, from scratch. | |
740 // This is so regardless of where in the syntax a module | |
741 // gets imported, it is unaffected by context. | |
1587 | 742 Scope *sc = scope; // see if already got one from importAll() |
743 if (!sc) | |
744 { printf("test2\n"); | |
745 Scope::createGlobal(this); // create root scope | |
746 } | |
336 | 747 |
748 //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage); | |
749 | |
1587 | 750 #if 0 |
336 | 751 // Add import of "object" if this module isn't "object" |
752 if (ident != Id::object) | |
753 { | |
754 Import *im = new Import(0, NULL, Id::object, NULL, 0); | |
755 members->shift(im); | |
756 } | |
757 | |
758 // Add all symbols into module's symbol table | |
759 symtab = new DsymbolTable(); | |
1587 | 760 for (int i = 0; i < members->dim; i++) |
761 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
336 | 762 s->addMember(NULL, sc->scopesym, 1); |
763 } | |
764 | |
1587 | 765 /* Set scope for the symbols so that if we forward reference |
766 * a symbol, it can possibly be resolved on the spot. | |
767 * If this works out well, it can be extended to all modules | |
768 * before any semantic() on any of them. | |
769 */ | |
770 for (int i = 0; i < members->dim; i++) | |
771 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
772 s->setScope(sc); | |
773 } | |
774 #endif | |
775 | |
336 | 776 // Pass 1 semantic routines: do public side of the definition |
1587 | 777 for (int i = 0; i < members->dim; i++) |
778 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
336 | 779 |
780 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); | |
781 s->semantic(sc); | |
782 runDeferredSemantic(); | |
783 } | |
784 | |
1587 | 785 if (!scope) |
786 { sc = sc->pop(); | |
787 sc->pop(); // 2 pops because Scope::createGlobal() created 2 | |
788 } | |
789 semanticRun = semanticstarted; | |
336 | 790 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); |
791 } | |
792 | |
751
dc8b8b7ea0c1
Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
793 void Module::semantic2(Scope* unused_sc) |
336 | 794 { int i; |
795 | |
796 if (deferred.dim) | |
797 { | |
798 for (int i = 0; i < deferred.dim; i++) | |
799 { | |
800 Dsymbol *sd = (Dsymbol *)deferred.data[i]; | |
801 | |
802 sd->error("unable to resolve forward reference in definition"); | |
803 } | |
804 return; | |
805 } | |
806 //printf("Module::semantic2('%s'): parent = %p\n", toChars(), parent); | |
807 if (semanticstarted >= 2) | |
808 return; | |
809 assert(semanticstarted == 1); | |
810 semanticstarted = 2; | |
811 | |
812 // Note that modules get their own scope, from scratch. | |
813 // This is so regardless of where in the syntax a module | |
814 // gets imported, it is unaffected by context. | |
815 Scope *sc = Scope::createGlobal(this); // create root scope | |
816 //printf("Module = %p\n", sc.scopesym); | |
817 | |
818 // Pass 2 semantic routines: do initializers and function bodies | |
819 for (i = 0; i < members->dim; i++) | |
820 { Dsymbol *s; | |
821 | |
822 s = (Dsymbol *)members->data[i]; | |
823 s->semantic2(sc); | |
824 } | |
825 | |
826 sc = sc->pop(); | |
827 sc->pop(); | |
1587 | 828 semanticRun = semanticstarted; |
336 | 829 //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); |
830 } | |
831 | |
751
dc8b8b7ea0c1
Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
832 void Module::semantic3(Scope* unused_sc) |
336 | 833 { int i; |
834 | |
835 //printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent); | |
836 if (semanticstarted >= 3) | |
837 return; | |
838 assert(semanticstarted == 2); | |
839 semanticstarted = 3; | |
840 | |
841 // Note that modules get their own scope, from scratch. | |
842 // This is so regardless of where in the syntax a module | |
843 // gets imported, it is unaffected by context. | |
844 Scope *sc = Scope::createGlobal(this); // create root scope | |
845 //printf("Module = %p\n", sc.scopesym); | |
846 | |
847 // Pass 3 semantic routines: do initializers and function bodies | |
848 for (i = 0; i < members->dim; i++) | |
849 { Dsymbol *s; | |
850 | |
851 s = (Dsymbol *)members->data[i]; | |
852 //printf("Module %s: %s.semantic3()\n", toChars(), s->toChars()); | |
853 s->semantic3(sc); | |
854 } | |
855 | |
856 sc = sc->pop(); | |
857 sc->pop(); | |
1587 | 858 semanticRun = semanticstarted; |
336 | 859 } |
860 | |
861 void Module::inlineScan() | |
1587 | 862 { |
336 | 863 if (semanticstarted >= 4) |
864 return; | |
865 assert(semanticstarted == 3); | |
866 semanticstarted = 4; | |
867 | |
868 // Note that modules get their own scope, from scratch. | |
869 // This is so regardless of where in the syntax a module | |
870 // gets imported, it is unaffected by context. | |
871 //printf("Module = %p\n", sc.scopesym); | |
872 | |
1587 | 873 for (int i = 0; i < members->dim; i++) |
874 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
336 | 875 //if (global.params.verbose) |
876 //printf("inline scan symbol %s\n", s->toChars()); | |
877 | |
878 s->inlineScan(); | |
879 } | |
1587 | 880 semanticRun = semanticstarted; |
336 | 881 } |
882 | |
883 /**************************************************** | |
884 */ | |
885 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
886 // is this used anywhere? |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
887 /* |
336 | 888 void Module::gensymfile() |
889 { | |
890 OutBuffer buf; | |
891 HdrGenState hgs; | |
892 | |
893 //printf("Module::gensymfile()\n"); | |
894 | |
895 buf.printf("// Sym file generated from '%s'", srcfile->toChars()); | |
896 buf.writenl(); | |
897 | |
898 for (int i = 0; i < members->dim; i++) | |
899 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
900 | |
901 s->toCBuffer(&buf, &hgs); | |
902 } | |
903 | |
904 // Transfer image to file | |
905 symfile->setbuffer(buf.data, buf.offset); | |
906 buf.data = NULL; | |
907 | |
908 symfile->writev(); | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
909 }*/ |
336 | 910 |
911 /********************************** | |
912 * Determine if we need to generate an instance of ModuleInfo | |
913 * for this Module. | |
914 */ | |
915 | |
916 int Module::needModuleInfo() | |
917 { | |
1640 | 918 //printf("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov); |
550
cbe08531430f
Removed unimplemented switches.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
510
diff
changeset
|
919 return needmoduleinfo; |
336 | 920 } |
921 | |
922 Dsymbol *Module::search(Loc loc, Identifier *ident, int flags) | |
923 { | |
924 /* Since modules can be circularly referenced, | |
925 * need to stop infinite recursive searches. | |
1587 | 926 * This is done with the cache. |
336 | 927 */ |
928 | |
929 //printf("%s Module::search('%s', flags = %d) insearch = %d\n", toChars(), ident->toChars(), flags, insearch); | |
930 Dsymbol *s; | |
931 if (insearch) | |
932 s = NULL; | |
933 else if (searchCacheIdent == ident && searchCacheFlags == flags) | |
1587 | 934 { |
336 | 935 s = searchCacheSymbol; |
1587 | 936 //printf("%s Module::search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident->toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol->toChars() : "null"); |
937 } | |
336 | 938 else |
939 { | |
940 insearch = 1; | |
941 s = ScopeDsymbol::search(loc, ident, flags); | |
942 insearch = 0; | |
943 | |
944 searchCacheIdent = ident; | |
945 searchCacheSymbol = s; | |
946 searchCacheFlags = flags; | |
947 } | |
948 return s; | |
949 } | |
950 | |
1587 | 951 Dsymbol *Module::symtabInsert(Dsymbol *s) |
952 { | |
953 searchCacheIdent = 0; // symbol is inserted, so invalidate cache | |
954 return Package::symtabInsert(s); | |
955 } | |
956 | |
1640 | 957 void Module::clearCache() |
958 { | |
959 for (int i = 0; i < amodules.dim; i++) | |
960 { Module *m = (Module *)amodules.data[i]; | |
961 m->searchCacheIdent = NULL; | |
962 } | |
963 } | |
1587 | 964 |
336 | 965 /******************************************* |
966 * Can't run semantic on s now, try again later. | |
967 */ | |
968 | |
969 void Module::addDeferredSemantic(Dsymbol *s) | |
970 { | |
971 // Don't add it if it is already there | |
972 for (int i = 0; i < deferred.dim; i++) | |
973 { | |
974 Dsymbol *sd = (Dsymbol *)deferred.data[i]; | |
975 | |
976 if (sd == s) | |
977 return; | |
978 } | |
979 | |
980 //printf("Module::addDeferredSemantic('%s')\n", s->toChars()); | |
981 deferred.push(s); | |
982 } | |
983 | |
984 | |
985 /****************************************** | |
986 * Run semantic() on deferred symbols. | |
987 */ | |
988 | |
989 void Module::runDeferredSemantic() | |
990 { | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
991 if (dprogress == 0) |
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
992 return; |
336 | 993 |
994 static int nested; | |
995 if (nested) | |
996 return; | |
997 //if (deferred.dim) printf("+Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); | |
998 nested++; | |
999 | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1587
diff
changeset
|
1000 size_t len; |
336 | 1001 do |
1002 { | |
1003 dprogress = 0; | |
1004 len = deferred.dim; | |
1005 if (!len) | |
1006 break; | |
1007 | |
1008 Dsymbol **todo; | |
1009 Dsymbol *tmp; | |
1010 if (len == 1) | |
1011 { | |
1012 todo = &tmp; | |
1013 } | |
1014 else | |
1015 { | |
1016 todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *)); | |
1017 assert(todo); | |
1018 } | |
1019 memcpy(todo, deferred.data, len * sizeof(Dsymbol *)); | |
1020 deferred.setDim(0); | |
1021 | |
1022 for (int i = 0; i < len; i++) | |
1023 { | |
1024 Dsymbol *s = todo[i]; | |
1025 | |
1026 s->semantic(NULL); | |
1027 //printf("deferred: %s, parent = %s\n", s->toChars(), s->parent->toChars()); | |
1028 } | |
1029 //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress); | |
1030 } while (deferred.dim < len || dprogress); // while making progress | |
1031 nested--; | |
1032 //printf("-Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); | |
1033 } | |
1034 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1035 /************************************ |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1036 * 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
|
1037 * return TRUE if it imports m. |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1038 * Can be used to detect circular imports. |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1039 */ |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1040 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1041 int Module::imports(Module *m) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1042 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1043 //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
|
1044 int aimports_dim = aimports.dim; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1045 #if 0 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1046 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
|
1047 { Module *mi = (Module *)aimports.data[i]; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1048 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
|
1049 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1050 #endif |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1051 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
|
1052 { Module *mi = (Module *)aimports.data[i]; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1053 if (mi == m) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1054 return TRUE; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1055 if (!mi->insearch) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1056 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1057 mi->insearch = 1; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1058 int r = mi->imports(m); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1059 if (r) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1060 return r; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1061 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1062 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1063 return FALSE; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1064 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
1065 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1066 /************************************* |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1067 * Return !=0 if module imports itself. |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1068 */ |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1069 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1070 int Module::selfImports() |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1071 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1072 //printf("Module::selfImports() %s\n", toChars()); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1073 if (!selfimports) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1074 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1075 for (int i = 0; i < amodules.dim; i++) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1076 { Module *mi = (Module *)amodules.data[i]; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1077 //printf("\t[%d] %s\n", i, mi->toChars()); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1078 mi->insearch = 0; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1079 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1080 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1081 selfimports = imports(this) + 1; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1082 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1083 for (int i = 0; i < amodules.dim; i++) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1084 { Module *mi = (Module *)amodules.data[i]; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1085 //printf("\t[%d] %s\n", i, mi->toChars()); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1086 mi->insearch = 0; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1087 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1088 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1089 return selfimports - 1; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1090 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1091 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1092 |
336 | 1093 /* =========================== ModuleDeclaration ===================== */ |
1094 | |
1095 ModuleDeclaration::ModuleDeclaration(Array *packages, Identifier *id) | |
1096 { | |
1097 this->packages = packages; | |
1098 this->id = id; | |
1099 } | |
1100 | |
1101 char *ModuleDeclaration::toChars() | |
1102 { | |
1103 OutBuffer buf; | |
1104 int i; | |
1105 | |
1106 if (packages && packages->dim) | |
1107 { | |
1108 for (i = 0; i < packages->dim; i++) | |
1109 { Identifier *pid = (Identifier *)packages->data[i]; | |
1110 | |
1111 buf.writestring(pid->toChars()); | |
1112 buf.writeByte('.'); | |
1113 } | |
1114 } | |
1115 buf.writestring(id->toChars()); | |
1116 buf.writeByte(0); | |
1117 return (char *)buf.extractData(); | |
1118 } | |
1119 | |
1120 /* =========================== Package ===================== */ | |
1121 | |
1122 Package::Package(Identifier *ident) | |
1123 : ScopeDsymbol(ident) | |
1124 { | |
1125 } | |
1126 | |
1127 | |
1128 const char *Package::kind() | |
1129 { | |
1130 return "package"; | |
1131 } | |
1132 | |
1133 | |
1134 DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppkg) | |
1135 { | |
1136 DsymbolTable *dst = Module::modules; | |
1137 Dsymbol *parent = NULL; | |
1138 | |
1139 //printf("Package::resolve()\n"); | |
1140 if (ppkg) | |
1141 *ppkg = NULL; | |
1142 | |
1143 if (packages) | |
1144 { int i; | |
1145 | |
1146 for (i = 0; i < packages->dim; i++) | |
1147 { Identifier *pid = (Identifier *)packages->data[i]; | |
1148 Dsymbol *p; | |
1149 | |
1150 p = dst->lookup(pid); | |
1151 if (!p) | |
1152 { | |
1153 p = new Package(pid); | |
1154 dst->insert(p); | |
1155 p->parent = parent; | |
1156 ((ScopeDsymbol *)p)->symtab = new DsymbolTable(); | |
1157 } | |
1158 else | |
1159 { | |
1160 assert(p->isPackage()); | |
1587 | 1161 #if TARGET_NET //dot net needs modules and packages with same name |
1162 #else | |
336 | 1163 if (p->isModule()) |
1164 { p->error("module and package have the same name"); | |
1165 fatal(); | |
1166 break; | |
1167 } | |
1587 | 1168 #endif |
336 | 1169 } |
1170 parent = p; | |
1171 dst = ((Package *)p)->symtab; | |
1172 if (ppkg && !*ppkg) | |
1173 *ppkg = (Package *)p; | |
1174 } | |
1175 if (pparent) | |
1176 { | |
1177 *pparent = parent; | |
1178 } | |
1179 } | |
1180 return dst; | |
1181 } |