changeset 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 20c065c46b38
children 8a8ee1f6b268
files dmd/mars.c dmd/mars.h dmd/module.c dmd/module.h gen/toobj.cpp
diffstat 5 files changed, 67 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mars.c	Fri Sep 05 23:02:18 2008 +0200
+++ b/dmd/mars.c	Sat Sep 06 12:27:27 2008 +0200
@@ -455,11 +455,11 @@
 			global.params.preservePaths = 1;
 			break;
 
-            case 'q':
-            if (p[3])
-                goto Lerror;
-            global.params.fqnPaths = 1;
-            break;
+		    case 'q':
+			if (p[3])
+			    goto Lerror;
+			global.params.fqnNames = 1;
+			break;
 
 		    case 0:
 			error("-o no longer supported, use -of or -od");
@@ -982,8 +982,6 @@
 	id = new Identifier(name, 0);
 	m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration);
 	modules.push(m);
-
-	global.params.objfiles->push(m->objfile->name->str);
     }
 
     // Read files, parse them
@@ -995,9 +993,10 @@
 	if (!Module::rootModule)
 	    Module::rootModule = m;
 	m->importedFrom = m;
-	m->deleteObjFile();
 	m->read(0);
 	m->parse();
+	m->buildTargetFiles();
+	m->deleteObjFile();
 	if (m->isDocFile)
 	{
 	    m->gendocfile();
@@ -1005,19 +1004,6 @@
 	    // Remove m from list of modules
 	    modules.remove(i);
 	    i--;
-
-	    // Remove m's object file from list of object files
-	    for (int j = 0; j < global.params.objfiles->dim; j++)
-	    {
-		if (m->objfile->name->str == global.params.objfiles->data[j])
-		{
-		    global.params.objfiles->remove(j);
-		    break;
-		}
-	    }
-
-	    if (global.params.objfiles->dim == 0)
-		global.params.link = 0;
 	}
     }
     if (global.errors)
@@ -1120,7 +1106,10 @@
 	if (global.params.verbose)
 	    printf("code      %s\n", m->toChars());
 	if (global.params.obj)
+	{
 	    m->genobjfile(0);
+	    global.params.objfiles->push(m->objfile->name->str);
+	}
 	if (global.errors)
 	    m->deleteObjFile();
 	else
--- a/dmd/mars.h	Fri Sep 05 23:02:18 2008 +0200
+++ b/dmd/mars.h	Sat Sep 06 12:27:27 2008 +0200
@@ -148,7 +148,7 @@
     char llvmInline;
     char llvmAnnotate;
     char useInlineAsm;
-    char fqnPaths; // use fully qualified object names
+    char fqnNames; // use fully qualified object names
 };
 
 struct Global
--- a/dmd/module.c	Fri Sep 05 23:02:18 2008 +0200
+++ b/dmd/module.c	Sat Sep 06 12:27:27 2008 +0200
@@ -58,12 +58,6 @@
 	: Package(ident)
 {
     FileName *srcfilename;
-    FileName *cfilename;
-    FileName *hfilename;
-    FileName *objfilename;
-    FileName *llfilename;
-    FileName *bcfilename;
-    FileName *symfilename;
 
 //    printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
     this->arg = filename;
@@ -95,7 +89,9 @@
     root = 0;
     importedFrom = NULL;
     srcfile = NULL;
+    objfile = NULL;
     docfile = NULL;
+    hdrfile = NULL;
 
     debuglevel = 0;
     debugids = NULL;
@@ -124,104 +120,59 @@
 	    fatal();
 	}
     }
-
-    char *argobj;
-    if (global.params.objname)
-	argobj = global.params.objname;
-    else if (global.params.preservePaths)
-	argobj = filename;
-    else
-	argobj = FileName::name(filename);
-    if (!FileName::absolute(argobj))
-    {
-	argobj = FileName::combine(global.params.objdir, argobj);
-    }
-
-    if (global.params.objname)
-	objfilename = new FileName(argobj, 0);
-    else
-    objfilename = FileName::forceExt(argobj, global.obj_ext);
-
-    llfilename = FileName::forceExt(argobj, global.ll_ext);
-    bcfilename = FileName::forceExt(argobj, global.bc_ext);
-
-    symfilename = FileName::forceExt(filename, global.sym_ext);
-
     srcfile = new File(srcfilename);
 
-    if (doDocComment)
-    {
-	setDocfile();
-    }
-
-    if (doHdrGen)
-    {
-	setHdrfile();
-    }
-
-    objfile = new File(objfilename);
-    bcfile = new File(bcfilename);
-    llfile = new File(llfilename);
-    symfile = new File(symfilename);
-    
     // LLVMDC
     llvmForceLogging = false;
 }
 
-void Module::setDocfile()
+File* Module::buildFilePath(char* forcename, char* path, char* ext)
 {
-    FileName *docfilename;
-    char *argdoc;
+    char *argobj;
+    if (forcename)
+	argobj = forcename;
+    else
+    {
+	if (global.params.preservePaths)
+	    argobj = (char*)this->arg;
+	else
+	    argobj = FileName::name((char*)this->arg);
 
-    if (global.params.docname)
-	argdoc = global.params.docname;
-    else if (global.params.preservePaths)
-	argdoc = (char *)arg;
-    else
-	argdoc = FileName::name((char *)arg);
-    if (!FileName::absolute(argdoc))
-    {	//FileName::ensurePathExists(global.params.docdir);
-	argdoc = FileName::combine(global.params.docdir, argdoc);
-    }
-    if (global.params.docname)
-	docfilename = new FileName(argdoc, 0);
-    else
-	docfilename = FileName::forceExt(argdoc, global.doc_ext);
+	if (global.params.fqnNames)
+	    if(md)
+		argobj = FileName::replaceName(argobj, md->toChars());
+	    else
+		argobj = FileName::replaceName(argobj, toChars());
 
-    if (docfilename->equals(srcfile->name))
-    {   error("Source file and documentation file have same name '%s'", srcfile->name->str);
-	fatal();
+	int clen = strlen(argobj);
+	char* tmp = (char *)alloca(clen + 2);
+	memcpy(tmp, argobj, clen);
+	tmp[clen] = '.';
+	tmp[clen+1] = 0;
+	argobj = tmp;
     }
 
-    docfile = new File(docfilename);
+    if (!FileName::absolute(argobj))
+    {
+	argobj = FileName::combine(path, argobj);
+    }
+
+    FileName::ensurePathExists(FileName::path(argobj));
+
+    if (global.params.objname)
+	return new File(argobj);
+    else
+	return new File(FileName::forceExt(argobj, ext));
 }
 
-void Module::setHdrfile()
+void Module::buildTargetFiles()
 {
-    FileName *hdrfilename;
-    char *arghdr;
+    if(objfile && docfile && hdrfile)
+	return;
 
-    if (global.params.hdrname)
-	arghdr = global.params.hdrname;
-    else if (global.params.preservePaths)
-	arghdr = (char *)arg;
-    else
-	arghdr = FileName::name((char *)arg);
-    if (!FileName::absolute(arghdr))
-    {	//FileName::ensurePathExists(global.params.hdrdir);
-	arghdr = FileName::combine(global.params.hdrdir, arghdr);
-    }
-    if (global.params.hdrname)
-	hdrfilename = new FileName(arghdr, 0);
-    else
-	hdrfilename = FileName::forceExt(arghdr, global.hdr_ext);
-
-    if (hdrfilename->equals(srcfile->name))
-    {   error("Source file and 'header' file have same name '%s'", srcfile->name->str);
-	fatal();
-    }
-
-    hdrfile = new File(hdrfilename);
+    objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
+    docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
+    hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext);
 }
 
 void Module::deleteObjFile()
@@ -229,7 +180,7 @@
     if (global.params.obj)
 	objfile->remove();
     //if (global.params.llvmBC)
-    bcfile->remove();
+    //bcfile->remove();
     if (docfile)
 	docfile->remove();
 }
@@ -575,8 +526,6 @@
     {
 	comment = buf + 4;
 	isDocFile = 1;
-	if (!docfile)
-	    setDocfile();
 	return;
     }
     if (isHtml)
@@ -772,6 +721,8 @@
 /****************************************************
  */
 
+// is this used anywhere?
+/*
 void Module::gensymfile()
 {
     OutBuffer buf;
@@ -793,7 +744,7 @@
     buf.data = NULL;
 
     symfile->writev();
-}
+}*/
 
 /**********************************
  * Determine if we need to generate an instance of ModuleInfo
--- a/dmd/module.h	Fri Sep 05 23:02:18 2008 +0200
+++ b/dmd/module.h	Sat Sep 06 12:27:27 2008 +0200
@@ -65,15 +65,11 @@
     const char *arg;	// original argument name
     ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
     File *srcfile;	// input source file
-    File *objfile;	// output .obj file
+
+    File *objfile; // output object file
+    File *docfile; // output doc file
+    File *hdrfile; // output hdr file
     
-    // LLVMDC
-    File *bcfile;  // output .bc file
-    File *llfile;  // output .ll file
-
-    File *hdrfile;	// 'header' file
-    File *symfile;	// output symbol file
-    File *docfile;	// output documentation file
     unsigned errors;	// if any errors in file
     unsigned numlines;	// number of lines in source file
     int isHtml;		// if it is an HTML file
@@ -121,7 +117,6 @@
 
     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
     const char *kind();
-    void setDocfile();	// set docfile member
     void read(Loc loc);	// read file
 #if IN_GCC
     void parse(bool dump_source = false);	// syntactic parse
@@ -132,12 +127,11 @@
     void semantic2();	// pass 2 semantic analysis
     void semantic3();	// pass 3 semantic analysis
     void inlineScan();	// scan for functions to inline
-    void setHdrfile();	// set hdrfile member
 #ifdef _DH
     void genhdrfile();  // generate D import file
 #endif
     void genobjfile(int multiobj);
-    void gensymfile();
+//    void gensymfile();
     void gendocfile();
     int needModuleInfo();
     Dsymbol *search(Loc loc, Identifier *ident, int flags);
@@ -173,6 +167,8 @@
     void genmoduleinfo();
 
     // LLVMDC
+    void buildTargetFiles();
+    File* buildFilePath(char* forcename, char* path, char* ext);
     Module *isModule() { return this; }
     
     bool llvmForceLogging;
--- a/gen/toobj.cpp	Fri Sep 05 23:02:18 2008 +0200
+++ b/gen/toobj.cpp	Sat Sep 06 12:27:27 2008 +0200
@@ -164,22 +164,10 @@
 
     // eventually do our own path stuff, dmd's is a bit strange.
     typedef llvm::sys::Path LLPath;
-    LLPath bcpath;
-    LLPath llpath;
-
-    if (global.params.fqnPaths)
-    {
-        bcpath = LLPath(mname);
-        bcpath.appendSuffix("bc");
-
-        llpath = LLPath(mname);
-        llpath.appendSuffix("ll");
-    }
-    else
-    {
-        bcpath = LLPath(bcfile->name->toChars());
-        llpath = LLPath(llfile->name->toChars());
-    }
+    LLPath bcpath = LLPath(objfile->name->toChars());
+    LLPath llpath = bcpath;
+    llpath.eraseSuffix();
+    llpath.appendSuffix(std::string(global.ll_ext));
 
     // write bytecode
     {
@@ -190,7 +178,7 @@
 
     // disassemble ?
     if (global.params.disassemble) {
-        Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars());
+        Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
         std::ofstream aos(llpath.c_str());
         ir.module->print(aos, NULL);
     }