Skip to content

Commit

Permalink
continue with removing errors.d from mars.d
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed Jun 7, 2024
1 parent 2df43f9 commit 26913d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
6 changes: 5 additions & 1 deletion compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
buildPath(params.fileImppath, global.filePath);

// Create Modules
Modules modules = createModules(files, libmodules, target);
Modules modules;
modules.reserve(files.length);
if (createModules(files, libmodules, target, global.errorSink, modules))
fatal();

// Read files
foreach (m; modules)
{
Expand Down
56 changes: 29 additions & 27 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import dmd.dsymbol;
import dmd.dsymbolsem;
import dmd.dtemplate;
import dmd.dtoh;
import dmd.errors;
import dmd.errorsink;
import dmd.expression;
import dmd.globals;
Expand Down Expand Up @@ -1766,12 +1765,12 @@ Params:
libmodules = Array to which binaries (shared/static libs and object files)
will be appended
target = target system
m = created Module
Returns:
A D module
true on error
*/
private
Module createModule(const(char)* file, ref Strings libmodules, const ref Target target)
bool createModule(const(char)* file, ref Strings libmodules, const ref Target target, ErrorSink eSink, out Module m)
{
version (Windows)
{
Expand All @@ -1783,11 +1782,12 @@ Module createModule(const(char)* file, ref Strings libmodules, const ref Target
{
if (!p.length)
{
error(Loc.initial, "invalid file name '%s'", file);
fatal();
eSink.error(Loc.initial, "invalid file name '%s'", file);
return true;
}
auto id = Identifier.idPool(p);
return new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
m = new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
return false;
}

/* Deduce what to do with a file based on its extension
Expand All @@ -1796,50 +1796,50 @@ Module createModule(const(char)* file, ref Strings libmodules, const ref Target
{
global.params.objfiles.push(file);
libmodules.push(file);
return null;
return false;
}
if (FileName.equals(ext, target.lib_ext))
{
global.params.libfiles.push(file);
libmodules.push(file);
return null;
return false;
}
if (target.os & (Target.OS.linux | Target.OS.OSX| Target.OS.FreeBSD | Target.OS.OpenBSD | Target.OS.Solaris | Target.OS.DragonFlyBSD))
{
if (FileName.equals(ext, target.dll_ext))
{
global.params.dllfiles.push(file);
libmodules.push(file);
return null;
return false;
}
}
if (FileName.equals(ext, ddoc_ext))
{
global.params.ddoc.files.push(file);
return null;
return false;
}
if (FileName.equals(ext, json_ext))
{
global.params.json.doOutput = true;
global.params.json.name = file.toDString;
return null;
return false;
}
if (FileName.equals(ext, map_ext))
{
global.params.mapfile = file.toDString;
return null;
return false;
}
if (target.os == Target.OS.Windows)
{
if (FileName.equals(ext, "res"))
{
global.params.resfile = file.toDString;
return null;
return false;
}
if (FileName.equals(ext, "def"))
{
global.params.deffile = file.toDString;
return null;
return false;
}
if (FileName.equals(ext, "exe"))
{
Expand All @@ -1859,19 +1859,19 @@ Module createModule(const(char)* file, ref Strings libmodules, const ref Target
const(char)[] name = p[0 .. p.length - ext.length - 1]; // -1 for the .
if (!name.length || name == ".." || name == ".")
{
error(Loc.initial, "invalid file name '%s'", file);
fatal();
eSink.error(Loc.initial, "invalid file name '%s'", file);
return true;
}
/* name is the D source file name stripped of
* its path and extension.
*/
auto id = Identifier.idPool(name);

return new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
m = new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput);
return false;
}
error(Loc.initial, "unrecognized file extension %.*s", cast(int)ext.length, ext.ptr);
fatal();
assert(0);
eSink.error(Loc.initial, "unrecognized file extension %.*s", cast(int)ext.length, ext.ptr);
return true;
}

/**
Expand All @@ -1887,18 +1887,20 @@ Params:
libmodules = Array to which binaries (shared/static libs and object files)
will be appended
target = target system
eSink = error message sink
modules = empty array of modules to be filled in
Returns:
An array of path to D modules
true on error
*/
Modules createModules(ref Strings files, ref Strings libmodules, const ref Target target)
bool createModules(ref Strings files, ref Strings libmodules, const ref Target target, ErrorSink eSink, ref Modules modules)
{
Modules modules;
modules.reserve(files.length);
bool firstmodule = true;
foreach(file; files)
{
auto m = createModule(file, libmodules, target);
Module m;
if (createModule(file, libmodules, target, eSink, m))
return true;

if (m is null)
continue;
Expand All @@ -1910,7 +1912,7 @@ Modules createModules(ref Strings files, ref Strings libmodules, const ref Targe
firstmodule = false;
}
}
return modules;
return false;
}

/// Returns: a compiled module (semantic3) containing an empty main() function, for the -main flag
Expand Down

0 comments on commit 26913d3

Please sign in to comment.