comparison dmd/module.c @ 580:7824c21a58e3

Restructure path handling a bit. Fixes #66.
author Christian Kamm <kamm incasoftware de>
date Sat, 06 Sep 2008 12:27:27 +0200
parents cbe08531430f
children bbfb66c623e7
comparison
equal deleted inserted replaced
579:20c065c46b38 580:7824c21a58e3
56 56
57 Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen) 57 Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen)
58 : Package(ident) 58 : Package(ident)
59 { 59 {
60 FileName *srcfilename; 60 FileName *srcfilename;
61 FileName *cfilename;
62 FileName *hfilename;
63 FileName *objfilename;
64 FileName *llfilename;
65 FileName *bcfilename;
66 FileName *symfilename;
67 61
68 // printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars()); 62 // printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
69 this->arg = filename; 63 this->arg = filename;
70 md = NULL; 64 md = NULL;
71 errors = 0; 65 errors = 0;
93 stest = NULL; 87 stest = NULL;
94 sfilename = NULL; 88 sfilename = NULL;
95 root = 0; 89 root = 0;
96 importedFrom = NULL; 90 importedFrom = NULL;
97 srcfile = NULL; 91 srcfile = NULL;
92 objfile = NULL;
98 docfile = NULL; 93 docfile = NULL;
94 hdrfile = NULL;
99 95
100 debuglevel = 0; 96 debuglevel = 0;
101 debugids = NULL; 97 debugids = NULL;
102 debugidsNot = NULL; 98 debugidsNot = NULL;
103 versionlevel = 0; 99 versionlevel = 0;
122 else 118 else
123 { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext); 119 { error("source file name '%s' must have .%s extension", srcfilename->toChars(), global.mars_ext);
124 fatal(); 120 fatal();
125 } 121 }
126 } 122 }
127
128 char *argobj;
129 if (global.params.objname)
130 argobj = global.params.objname;
131 else if (global.params.preservePaths)
132 argobj = filename;
133 else
134 argobj = FileName::name(filename);
135 if (!FileName::absolute(argobj))
136 {
137 argobj = FileName::combine(global.params.objdir, argobj);
138 }
139
140 if (global.params.objname)
141 objfilename = new FileName(argobj, 0);
142 else
143 objfilename = FileName::forceExt(argobj, global.obj_ext);
144
145 llfilename = FileName::forceExt(argobj, global.ll_ext);
146 bcfilename = FileName::forceExt(argobj, global.bc_ext);
147
148 symfilename = FileName::forceExt(filename, global.sym_ext);
149
150 srcfile = new File(srcfilename); 123 srcfile = new File(srcfilename);
151 124
152 if (doDocComment)
153 {
154 setDocfile();
155 }
156
157 if (doHdrGen)
158 {
159 setHdrfile();
160 }
161
162 objfile = new File(objfilename);
163 bcfile = new File(bcfilename);
164 llfile = new File(llfilename);
165 symfile = new File(symfilename);
166
167 // LLVMDC 125 // LLVMDC
168 llvmForceLogging = false; 126 llvmForceLogging = false;
169 } 127 }
170 128
171 void Module::setDocfile() 129 File* Module::buildFilePath(char* forcename, char* path, char* ext)
172 { 130 {
173 FileName *docfilename; 131 char *argobj;
174 char *argdoc; 132 if (forcename)
175 133 argobj = forcename;
176 if (global.params.docname)
177 argdoc = global.params.docname;
178 else if (global.params.preservePaths)
179 argdoc = (char *)arg;
180 else 134 else
181 argdoc = FileName::name((char *)arg); 135 {
182 if (!FileName::absolute(argdoc)) 136 if (global.params.preservePaths)
183 { //FileName::ensurePathExists(global.params.docdir); 137 argobj = (char*)this->arg;
184 argdoc = FileName::combine(global.params.docdir, argdoc); 138 else
185 } 139 argobj = FileName::name((char*)this->arg);
186 if (global.params.docname) 140
187 docfilename = new FileName(argdoc, 0); 141 if (global.params.fqnNames)
142 if(md)
143 argobj = FileName::replaceName(argobj, md->toChars());
144 else
145 argobj = FileName::replaceName(argobj, toChars());
146
147 int clen = strlen(argobj);
148 char* tmp = (char *)alloca(clen + 2);
149 memcpy(tmp, argobj, clen);
150 tmp[clen] = '.';
151 tmp[clen+1] = 0;
152 argobj = tmp;
153 }
154
155 if (!FileName::absolute(argobj))
156 {
157 argobj = FileName::combine(path, argobj);
158 }
159
160 FileName::ensurePathExists(FileName::path(argobj));
161
162 if (global.params.objname)
163 return new File(argobj);
188 else 164 else
189 docfilename = FileName::forceExt(argdoc, global.doc_ext); 165 return new File(FileName::forceExt(argobj, ext));
190 166 }
191 if (docfilename->equals(srcfile->name)) 167
192 { error("Source file and documentation file have same name '%s'", srcfile->name->str); 168 void Module::buildTargetFiles()
193 fatal(); 169 {
194 } 170 if(objfile && docfile && hdrfile)
195 171 return;
196 docfile = new File(docfilename); 172
197 } 173 objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
198 174 docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
199 void Module::setHdrfile() 175 hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext);
200 {
201 FileName *hdrfilename;
202 char *arghdr;
203
204 if (global.params.hdrname)
205 arghdr = global.params.hdrname;
206 else if (global.params.preservePaths)
207 arghdr = (char *)arg;
208 else
209 arghdr = FileName::name((char *)arg);
210 if (!FileName::absolute(arghdr))
211 { //FileName::ensurePathExists(global.params.hdrdir);
212 arghdr = FileName::combine(global.params.hdrdir, arghdr);
213 }
214 if (global.params.hdrname)
215 hdrfilename = new FileName(arghdr, 0);
216 else
217 hdrfilename = FileName::forceExt(arghdr, global.hdr_ext);
218
219 if (hdrfilename->equals(srcfile->name))
220 { error("Source file and 'header' file have same name '%s'", srcfile->name->str);
221 fatal();
222 }
223
224 hdrfile = new File(hdrfilename);
225 } 176 }
226 177
227 void Module::deleteObjFile() 178 void Module::deleteObjFile()
228 { 179 {
229 if (global.params.obj) 180 if (global.params.obj)
230 objfile->remove(); 181 objfile->remove();
231 //if (global.params.llvmBC) 182 //if (global.params.llvmBC)
232 bcfile->remove(); 183 //bcfile->remove();
233 if (docfile) 184 if (docfile)
234 docfile->remove(); 185 docfile->remove();
235 } 186 }
236 187
237 Module::~Module() 188 Module::~Module()
573 */ 524 */
574 if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0) 525 if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0)
575 { 526 {
576 comment = buf + 4; 527 comment = buf + 4;
577 isDocFile = 1; 528 isDocFile = 1;
578 if (!docfile)
579 setDocfile();
580 return; 529 return;
581 } 530 }
582 if (isHtml) 531 if (isHtml)
583 { 532 {
584 OutBuffer *dbuf = new OutBuffer(); 533 OutBuffer *dbuf = new OutBuffer();
770 } 719 }
771 720
772 /**************************************************** 721 /****************************************************
773 */ 722 */
774 723
724 // is this used anywhere?
725 /*
775 void Module::gensymfile() 726 void Module::gensymfile()
776 { 727 {
777 OutBuffer buf; 728 OutBuffer buf;
778 HdrGenState hgs; 729 HdrGenState hgs;
779 730
791 // Transfer image to file 742 // Transfer image to file
792 symfile->setbuffer(buf.data, buf.offset); 743 symfile->setbuffer(buf.data, buf.offset);
793 buf.data = NULL; 744 buf.data = NULL;
794 745
795 symfile->writev(); 746 symfile->writev();
796 } 747 }*/
797 748
798 /********************************** 749 /**********************************
799 * Determine if we need to generate an instance of ModuleInfo 750 * Determine if we need to generate an instance of ModuleInfo
800 * for this Module. 751 * for this Module.
801 */ 752 */