mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Refactor use of Loc/SourceLoc (#20785)
This commit is contained in:
parent
b2c9da1337
commit
b289b6a6dc
19 changed files with 101 additions and 80 deletions
|
@ -67,7 +67,7 @@ int main()
|
|||
global.path.push((dmdParentDir ~ "/druntime/import" ~ '\0').ptr);
|
||||
|
||||
// comment for error output in parsing & semantic
|
||||
diagnosticHandler = (const ref Loc location,
|
||||
diagnosticHandler = (const ref SourceLoc location,
|
||||
Color headerColor,
|
||||
const(char)* header,
|
||||
const(char)* messageFormat,
|
||||
|
|
|
@ -115,7 +115,7 @@ unittest
|
|||
|
||||
string[] diagnosticMessages;
|
||||
|
||||
nothrow bool diagnosticHandler(const ref Loc loc, Color headerColor, const(char)* header,
|
||||
nothrow bool diagnosticHandler(const ref SourceLoc loc, Color headerColor, const(char)* header,
|
||||
const(char)* format, va_list ap, const(char)* p1, const(char)* p2)
|
||||
{
|
||||
OutBuffer tmp;
|
||||
|
@ -251,7 +251,7 @@ unittest
|
|||
|
||||
string[] diagnosticMessages;
|
||||
|
||||
nothrow bool diagnosticHandler(const ref Loc loc, Color headerColor, const(char)* header,
|
||||
nothrow bool diagnosticHandler(const ref SourceLoc loc, Color headerColor, const(char)* header,
|
||||
const(char)* format, va_list ap, const(char)* p1, const(char)* p2)
|
||||
{
|
||||
OutBuffer tmp;
|
||||
|
@ -368,7 +368,7 @@ unittest
|
|||
|
||||
string[] diagnosticMessages;
|
||||
|
||||
nothrow bool diagnosticHandler(const ref Loc loc, Color headerColor, const(char)* header,
|
||||
nothrow bool diagnosticHandler(const ref SourceLoc loc, Color headerColor, const(char)* header,
|
||||
const(char)* format, va_list ap, const(char)* p1, const(char)* p2)
|
||||
{
|
||||
OutBuffer tmp;
|
||||
|
|
|
@ -45,7 +45,7 @@ import support : afterEach, beforeEach, compiles, stripDelimited, Diagnostic;
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: class test.Bar interface function void foo() is not implemented";
|
||||
const expected = Diagnostic(Loc(filename, 6, 1), message);
|
||||
const expected = Diagnostic(SourceLoc(filename, 6, 1), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
@ -67,7 +67,7 @@ import support : afterEach, beforeEach, compiles, stripDelimited, Diagnostic;
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: class test.Bar interface function void foo() is not implemented";
|
||||
const expected = Diagnostic(Loc(filename, 6, 1), message);
|
||||
const expected = Diagnostic(SourceLoc(filename, 6, 1), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
@ -94,7 +94,7 @@ import support : afterEach, beforeEach, compiles, stripDelimited, Diagnostic;
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: class test.Bar interface function void foo() is not implemented";
|
||||
const expected = Diagnostic(Loc(filename, 11, 1), message);
|
||||
const expected = Diagnostic(SourceLoc(filename, 11, 1), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
@ -123,7 +123,7 @@ import support : afterEach, beforeEach, compiles, stripDelimited, Diagnostic;
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: class test.B interface function void foo() is not implemented";
|
||||
const expected = Diagnostic(Loc(filename, 11, 1), message);
|
||||
const expected = Diagnostic(SourceLoc(filename, 11, 1), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
|
|
@ -23,7 +23,7 @@ unittest
|
|||
{
|
||||
int errorCount;
|
||||
|
||||
override bool error(const ref Loc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
override bool error(const ref SourceLoc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
{
|
||||
errorCount++;
|
||||
return true;
|
||||
|
|
|
@ -245,7 +245,7 @@ unittest
|
|||
import dmd.errors;
|
||||
|
||||
const(char)[][2][] diagnosticMessages;
|
||||
nothrow bool diagnosticHandler(const ref Loc loc, Color headerColor, const(char)* header,
|
||||
nothrow bool diagnosticHandler(const ref SourceLoc loc, Color headerColor, const(char)* header,
|
||||
const(char)* format, va_list ap, const(char)* p1, const(char)* p2)
|
||||
{
|
||||
OutBuffer tmp;
|
||||
|
|
|
@ -41,7 +41,7 @@ unittest
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: class test.Bar interface function extern (Objective-C) static void foo() is not implemented";
|
||||
auto expected = Diagnostic(Loc(filename, 8, 1), message);
|
||||
auto expected = Diagnostic(SourceLoc(filename, 8, 1), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
@ -65,7 +65,7 @@ unittest
|
|||
}.stripDelimited;
|
||||
|
||||
enum message = "Error: function test.Foo.foo function body only allowed in final functions in interface Foo";
|
||||
auto expected = Diagnostic(Loc(filename, 4, 17), message);
|
||||
auto expected = Diagnostic(SourceLoc(filename, 4, 17), message);
|
||||
|
||||
const diagnostics = compiles(code, filename);
|
||||
assert(diagnostics == [expected], "\n" ~ diagnostics.toString);
|
||||
|
|
|
@ -129,7 +129,7 @@ unittest
|
|||
}
|
||||
}.stripDelimited;
|
||||
|
||||
Loc loc = Loc(filename, 5, 20);
|
||||
SourceLoc loc = SourceLoc(filename, 5, 20);
|
||||
enum message = "Error: function test.Foo.foo only functions with Objective-C linkage can be declared as optional";
|
||||
enum supplemental = "function is declared with D linkage";
|
||||
auto expected = [Diagnostic(loc, message), Diagnostic(loc, supplemental)];
|
||||
|
@ -154,7 +154,7 @@ unittest
|
|||
}
|
||||
}.stripDelimited;
|
||||
|
||||
Loc loc = Loc(filename, 6, 30);
|
||||
SourceLoc loc = SourceLoc(filename, 6, 30);
|
||||
enum message = "Error: function test.Foo.foo can only declare a function as optional once";
|
||||
auto expected = Diagnostic(loc, message);
|
||||
|
||||
|
@ -184,15 +184,13 @@ unittest
|
|||
}
|
||||
}.stripDelimited;
|
||||
|
||||
Loc loc = Loc(filename, 6, 20);
|
||||
|
||||
auto expected = [
|
||||
Diagnostic(
|
||||
Loc(filename, 6, 20),
|
||||
SourceLoc(filename, 6, 20),
|
||||
"Error: function test.Foo.foo!().foo template cannot be optional"
|
||||
),
|
||||
Diagnostic(
|
||||
Loc(filename, 12, 10),
|
||||
SourceLoc(filename, 12, 10),
|
||||
"Error: template instance test.Foo.foo!() error instantiating"
|
||||
)
|
||||
];
|
||||
|
@ -223,7 +221,7 @@ unittest
|
|||
}
|
||||
}.stripDelimited;
|
||||
|
||||
Loc loc = Loc(filename, 6, 20);
|
||||
SourceLoc loc = SourceLoc(filename, 6, 20);
|
||||
enum message = "Error: function test.Foo.foo only functions declared inside interfaces can be optional";
|
||||
enum supplemental = "function is declared inside class";
|
||||
auto expected = [Diagnostic(loc, message), Diagnostic(loc, supplemental)];
|
||||
|
|
|
@ -29,7 +29,7 @@ unittest
|
|||
{
|
||||
int errorCount;
|
||||
|
||||
override bool error(const ref Loc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
override bool error(const ref SourceLoc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
{
|
||||
errorCount++;
|
||||
return true;
|
||||
|
@ -52,7 +52,7 @@ unittest
|
|||
{
|
||||
int supplementalCount;
|
||||
|
||||
override bool errorSupplemental(const ref Loc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
override bool errorSupplemental(const ref SourceLoc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
{
|
||||
supplementalCount++;
|
||||
return true;
|
||||
|
@ -79,7 +79,7 @@ unittest
|
|||
{
|
||||
int warningCount;
|
||||
|
||||
override bool warning(const ref Loc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
override bool warning(const ref SourceLoc, const(char)*, va_list, const(char)*, const(char)*)
|
||||
{
|
||||
warningCount++;
|
||||
return true;
|
||||
|
|
|
@ -115,19 +115,19 @@ class NoopDiagnosticReporter : DiagnosticReporter
|
|||
override int errorCount() { return 0; }
|
||||
override int warningCount() { return 0; }
|
||||
override int deprecationCount() { return 0; }
|
||||
override bool error(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool errorSupplemental(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool warning(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool warningSupplemental(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool deprecation(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool deprecationSupplemental(const ref Loc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool error(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool errorSupplemental(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool warning(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool warningSupplemental(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool deprecation(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
override bool deprecationSupplemental(const ref SourceLoc loc, const(char)* format, va_list, const(char)* p1, const(char)* p2) { return true; }
|
||||
}
|
||||
|
||||
/// A single diagnostic.
|
||||
const struct Diagnostic
|
||||
{
|
||||
/// The location of the diagnostic.
|
||||
Loc location;
|
||||
SourceLoc location;
|
||||
|
||||
/// The diagnostic message.
|
||||
string message;
|
||||
|
@ -157,7 +157,7 @@ struct DiagnosticCollector
|
|||
|
||||
/// Handles a diagnostic.
|
||||
bool handleDiagnostic (
|
||||
const ref Loc location,
|
||||
const ref SourceLoc location,
|
||||
Color headerColor,
|
||||
const(char)* header,
|
||||
const(char)* messageFormat,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue