Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This needs to be done $(I before) calling any function.
*/
void initDMD()
{
import std.concurrency : initOnce;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not linking with Phobos - just druntime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses Phobos as it isn't part of the compiler.

import dmd.builtin : builtin_init;
import dmd.dmodule : Module;
import dmd.expression : Expression;
Expand All @@ -37,16 +38,21 @@ void initDMD()
import dmd.objc : Objc;
import dmd.target : Target;

global._init();
addDefaultVersionIdentifiers();

Type._init();
Id.initialize();
Module._init();
Target._init();
Expression._init();
Objc._init();
builtin_init();
static shared bool initialized;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The front end is not thread safe, no need to pretend it here.

initOnce!initialized((){
global._init();
addDefaultVersionIdentifiers();

Type._init();
Id.initialize();
Module._init();
Target._init();
Expression._init();
Objc._init();
builtin_init();

return true;
}());
}

/**
Expand All @@ -60,6 +66,8 @@ void addImport(string path)
import dmd.arraytypes : Strings;
import std.string : toStringz;

initDMD;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's not introduce a new style for calling functions - append the ().


if (global.path is null)
global.path = new Strings();

Expand All @@ -79,6 +87,8 @@ string findDMDConfig(string dmdFilePath)
import dmd.dinifile : findConfFile;
import std.string : fromStringz, toStringz;

initDMD;

auto f = findConfFile(dmdFilePath.toStringz, "dmd.conf");
if (f is null)
return null;
Expand Down Expand Up @@ -227,6 +237,8 @@ Module parseModule(string fileName, string code = null)
import dmd.tokens : TOK;
import std.string : toStringz;

initDMD;

auto parse(Module m, string code)
{
scope p = new Parser!ASTCodegen(m, code, false);
Expand Down
1 change: 0 additions & 1 deletion test/dub_package/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void main()
import dmd.frontend;
import std.algorithm : each;

initDMD;
findImportPaths.each!addImport;

auto m = parseModule("test.d", q{
Expand Down
1 change: 0 additions & 1 deletion test/dub_package/frontend_file.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void main()
import std.file : remove, tempDir, fwrite = write;
import std.path : buildPath;

initDMD;
findImportPaths.each!addImport;

auto fileName = tempDir.buildPath("d_frontend_test.d");
Expand Down