diff --git a/changelog.md b/changelog.md index ebe2fab..5dc125d 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ * Added a flag, `--frontend-version`, which will print the version of the frontend DLP is using * Updated the D frontend DLP is using to DMD 2.085.0+ ([dd94ef465](https://github.com/dlang/dmd/commit/dd94ef465342d47a94f6c587638c49ce42f54590)) +* New formatting of locations ### `leaf-funcions` diff --git a/source/dlp/driver/commands/leaf_functions.d b/source/dlp/driver/commands/leaf_functions.d index 934d39b..a71de94 100644 --- a/source/dlp/driver/commands/leaf_functions.d +++ b/source/dlp/driver/commands/leaf_functions.d @@ -73,11 +73,9 @@ class LeafFunctions : Command!(Arguments) static void printResult(LeafFunction leafFunction) { - import std.string : fromStringz; - import std.stdio : writefln; + import std.stdio : writeln; - const location = leafFunction.location.toChars.fromStringz; - writefln("%s: %s", location, leafFunction.fullyQualifiedName); + writeln(leafFunction); } } @@ -87,6 +85,14 @@ private struct LeafFunction Loc location; string fullyQualifiedName; + + string toString() const pure + { + import std.format : format; + import dlp.driver.utility : toString; + + return format!"%s: %s"(location.toString, fullyQualifiedName); + } } version (unittest): diff --git a/source/dlp/driver/utility.d b/source/dlp/driver/utility.d index 07e7279..c707a0b 100644 --- a/source/dlp/driver/utility.d +++ b/source/dlp/driver/utility.d @@ -1,5 +1,7 @@ module dlp.driver.utility; +import dmd.globals : Loc; + class MissingArgumentException : Exception { this( @@ -22,3 +24,15 @@ class MissingArgumentException : Exception super(msg, file, line, nextInChain); } } + +string toString(const ref Loc location) pure +{ + import std.format : format; + import std.string : fromStringz; + + return format!"%s:%s:%s"( + location.filename.fromStringz, + location.linnum, + location.charnum + ); +}