Skip to content

Commit

Permalink
use ref's for json.d (#15515)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored Aug 8, 2023
1 parent 2e22eca commit e3e92ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dmd/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private immutable ddoc_decl_dd_e = ")\n";
* Params:
* m = Module
* ddocfiles = array of .ddoc files to read for macro definitions
* datetime = string returned by ctime()
* datetime = string returned by ctime()
* eSink = send error messages to eSink
*/
extern(C++) void gendocfile(Module m, const ref Array!(const(char)*) ddocfiles, const(char)* datetime, ErrorSink eSink)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8104,7 +8104,7 @@ extern Expression* resolveProperties(Scope* sc, Expression* e);

extern Expression* expressionSemantic(Expression* e, Scope* sc);

extern void json_generate(OutBuffer* buf, Array<Module* >* modules);
extern void json_generate(Array<Module* >& modules, OutBuffer& buf);

extern JsonFieldFlags tryParseJsonField(const char* fieldName);

Expand Down
23 changes: 13 additions & 10 deletions compiler/src/dmd/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,14 @@ public:
Params:
modules = array of the "root modules"
*/
private void generateModules(Modules* modules)
private void generateModules(ref Modules modules)
{
arrayStart();
if (modules)
foreach (m; modules)
{
foreach (m; *modules)
{
if (global.params.verbose)
message("json gen %s", m.toChars());
m.accept(this);
}
if (global.params.verbose)
message("json gen %s", m.toChars());
m.accept(this);
}
arrayEnd();
}
Expand Down Expand Up @@ -981,9 +978,15 @@ public:
}
}

extern (C++) void json_generate(OutBuffer* buf, Modules* modules)
/***********************************
* Generate json for the modules.
* Params:
* modules = array of Modules
* buf = write json output to buf
*/
extern (C++) void json_generate(ref Modules modules, ref OutBuffer buf)
{
scope ToJsonVisitor json = new ToJsonVisitor(buf);
scope ToJsonVisitor json = new ToJsonVisitor(&buf);
// write trailing newline
scope(exit) buf.writeByte('\n');

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
{
if (params.jsonFieldFlags)
{
generateJson(null);
Modules modules; // empty
generateJson(modules);
return EXIT_SUCCESS;
}
usage();
Expand Down Expand Up @@ -548,7 +549,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
// Generate output files
if (params.json.doOutput)
{
generateJson(&modules);
generateJson(modules);
}
if (!global.errors && params.ddoc.doOutput)
{
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ Where:
%.*s", cast(int)inifileCanon.length, inifileCanon.ptr, cast(int)help.length, &help[0]);
}

extern (C++) void generateJson(Modules* modules)
extern (C++) void generateJson(ref Modules modules)
{
OutBuffer buf;
json_generate(&buf, modules);
json_generate(modules, buf);

// Write buf to file
const(char)[] name = global.params.json.name;
Expand Down

0 comments on commit e3e92ea

Please sign in to comment.