Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 28, 2011
2 parents 91f4b71 + 6794fc2 commit 9faf674
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
24 changes: 16 additions & 8 deletions src/mars.c
Expand Up @@ -290,6 +290,7 @@ Usage:\n\
-odobjdir write object & library files to directory objdir\n\
-offilename name output file to filename\n\
-op do not strip paths from source file\n\
-oq use fully qualified module name for object filenames\n\
-profile profile runtime performance of generated code\n\
-quiet suppress unnecessary messages\n\
-release compile release version\n\
Expand Down Expand Up @@ -516,6 +517,12 @@ int main(int argc, char *argv[])
global.params.preservePaths = 1;
break;

case 'q':
if (p[3])
goto Lerror;
global.params.packagePaths = 1;
break;

case 0:
error("-o no longer supported, use -of or -od");
break;
Expand Down Expand Up @@ -952,7 +959,6 @@ int main(int argc, char *argv[])
// Create Modules
Array modules;
modules.reserve(files.dim);
int firstmodule = 1;
for (i = 0; i < files.dim; i++)
{
char *ext;
Expand Down Expand Up @@ -1069,11 +1075,6 @@ int main(int argc, char *argv[])
Identifier *id = Lexer::idPool(name);
m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration);
modules.push(m);

if (firstmodule)
{ global.params.objfiles->push(m->objfile->name->str);
firstmodule = 0;
}
}

#if WINDOWS_SEH
Expand Down Expand Up @@ -1102,6 +1103,7 @@ int main(int argc, char *argv[])

// Parse files
int anydocfiles = 0;
int firstmodule = 1;
for (i = 0; i < modules.dim; i++)
{
m = (Module *)modules.data[i];
Expand All @@ -1110,15 +1112,16 @@ int main(int argc, char *argv[])
if (!Module::rootModule)
Module::rootModule = m;
m->importedFrom = m;
if (!global.params.oneobj || i == 0 || m->isDocFile)
m->deleteObjFile();
#if ASYNCREAD
if (aw->read(i))
{
error("cannot read file %s", m->srcfile->name->toChars());
}
#endif
m->parse();
m->prepareObjfile();
if (!global.params.oneobj || i == 0 || m->isDocFile)
m->deleteObjFile();
if (m->isDocFile)
{
anydocfiles = 1;
Expand All @@ -1141,6 +1144,11 @@ int main(int argc, char *argv[])
if (global.params.objfiles->dim == 0)
global.params.link = 0;
}

if (firstmodule)
{ global.params.objfiles->push(m->objfile->name->str);
firstmodule = 0;
}
}
#if ASYNCREAD
AsyncRead::dispose(aw);
Expand Down
1 change: 1 addition & 0 deletions src/mars.h
Expand Up @@ -160,6 +160,7 @@ struct Param
char useInline; // inline expand functions
char release; // build release version
char preservePaths; // !=0 means don't strip path from source file
char packagePaths; // !=0 means use the fully qualified module name as object file output filename
char warnings; // 0: enable warnings
// 1: warnings as errors
// 2: informational warnings (no errors)
Expand Down
45 changes: 32 additions & 13 deletions src/module.c
Expand Up @@ -69,6 +69,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen

// printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
this->arg = filename;
orig_filename = filename;
md = NULL;
errors = 0;
numlines = 0;
Expand Down Expand Up @@ -138,6 +139,21 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
}
}

if (doDocComment)
setDocfile();

if (doHdrGen)
setHdrfile();

srcfile = new File(srcfilename);
}

void Module::prepareObjfile()
{
char *filename = orig_filename;
FileName *objfilename;
FileName *symfilename;

char *argobj;
if (global.params.objname)
argobj = global.params.objname;
Expand All @@ -155,6 +171,18 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
{
if (global.params.preservePaths)
argobj = filename;

else if (global.params.packagePaths) {
argobj = (char*)toPrettyChars();
//FileName::forceExt will think the last part of the package path is an extension
//argobj = argobj ~ '.' ~ global.obj_ext;
char* tmp = (char*)calloc(1, strlen(argobj) + strlen(global.obj_ext) + 2);
memcpy(tmp, argobj, strlen(argobj));
tmp[strlen(argobj)] = '.';
memcpy(tmp + strlen(argobj) + 1, global.obj_ext, strlen(global.obj_ext));
argobj = tmp;
}

else
argobj = FileName::name(filename);
if (!FileName::absolute(argobj))
Expand All @@ -171,18 +199,6 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen

symfilename = FileName::forceExt(filename, global.sym_ext);

srcfile = new File(srcfilename);

if (doDocComment)
{
setDocfile();
}

if (doHdrGen)
{
setHdrfile();
}

objfile = new File(objfilename);
symfile = new File(symfilename);
}
Expand Down Expand Up @@ -245,7 +261,7 @@ void Module::setHdrfile()

void Module::deleteObjFile()
{
if (global.params.obj)
if (global.params.obj && objfile)
objfile->remove();
if (docfile)
docfile->remove();
Expand Down Expand Up @@ -644,6 +660,9 @@ void Module::parse()
*/
if (!Lexer::isValidIdentifier(this->ident->toChars()))
error("has non-identifier characters in filename, use module declaration instead");

if (global.params.packagePaths)
error("has no module declaration; this is not allowed when using option -oq");
}

// Update global list of modules
Expand Down
3 changes: 3 additions & 0 deletions src/module.h
Expand Up @@ -58,6 +58,7 @@ struct Module : Package


const char *arg; // original argument name
char *orig_filename; //original filename (passed to Module ctor)
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
File *srcfile; // input source file
File *objfile; // output .obj file
Expand Down Expand Up @@ -114,6 +115,8 @@ struct Module : Package
Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen);
~Module();

void prepareObjfile();

static Module *load(Loc loc, Array *packages, Identifier *ident);

void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down

0 comments on commit 9faf674

Please sign in to comment.