Skip to content
Merged
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
9 changes: 3 additions & 6 deletions src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,11 @@ extern (C++) final class Module : Package
/// syntactic parse
Module parse()
{
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
return parse!ASTCodegen(diagnosticReporter);
return parseModule!ASTCodegen();
}

/// ditto
extern (D) Module parse(AST)(DiagnosticReporter diagnosticReporter)
extern (D) Module parseModule(AST)()
{


Expand Down Expand Up @@ -989,13 +988,11 @@ extern (C++) final class Module : Package
isHdrFile = true;
}
{
scope p = new Parser!AST(this, buf, cast(bool) docfile, diagnosticReporter);
scope p = new Parser!AST(this, buf, cast(bool) docfile);
p.nextToken();
members = p.parseModule();
md = p.md;
numlines = p.scanloc.linnum;
if (p.errors)
++global.errors;
}
srcBuffer.destroy();
srcBuffer = null;
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -5253,8 +5253,8 @@ private void highlightCode3(Scope* sc, ref OutBuffer buf, const(char)* p, const(
private void highlightCode2(Scope* sc, Dsymbols* a, ref OutBuffer buf, size_t offset)
{
uint errorsave = global.startGagging();
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1, diagnosticReporter);

scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1);
OutBuffer res;
const(char)* lastp = cast(char*)buf[].ptr;
//printf("highlightCode2('%.*s')\n", cast(int)(buf.length - 1), buf[].ptr);
Expand Down
9 changes: 3 additions & 6 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2090,16 +2090,13 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(cd.loc, sc._module, str, false, diagnosticReporter);
scope p = new Parser!ASTCodegen(cd.loc, sc._module, str, false);
p.nextToken();

auto d = p.parseDeclDefs(0);
if (p.errors)
{
assert(global.errors != errors); // should have caught all these cases
if (global.errors != errors)
return null;
}

if (p.token.value != TOK.endOfFile)
{
cd.error("incomplete mixin declaration `%s`", str.ptr);
Expand Down
212 changes: 1 addition & 211 deletions src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,215 +24,6 @@ import dmd.utils;

nothrow:

/// Interface for diagnostic reporting.
abstract class DiagnosticReporter
{
nothrow:

/// Returns: the number of errors that occurred during lexing or parsing.
abstract int errorCount();

/// Returns: the number of warnings that occurred during lexing or parsing.
abstract int warningCount();

/// Returns: the number of deprecations that occurred during lexing or parsing.
abstract int deprecationCount();

/**
Reports an error message.

Params:
loc = Location of error
format = format string for error
... = format string arguments
*/
final void error(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
error(loc, format, args);
va_end(args);
}

/// ditto
abstract void error(const ref Loc loc, const(char)* format, va_list args);

/**
Reports additional details about an error message.

Params:
loc = Location of error
format = format string for supplemental message
... = format string arguments
*/
final void errorSupplemental(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
errorSupplemental(loc, format, args);
va_end(args);
}

/// ditto
abstract void errorSupplemental(const ref Loc loc, const(char)* format, va_list);

/**
Reports a warning message.

Params:
loc = Location of warning
format = format string for warning
... = format string arguments
*/
final void warning(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
warning(loc, format, args);
va_end(args);
}

/// ditto
abstract void warning(const ref Loc loc, const(char)* format, va_list args);

/**
Reports additional details about a warning message.

Params:
loc = Location of warning
format = format string for supplemental message
... = format string arguments
*/
final void warningSupplemental(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
warningSupplemental(loc, format, args);
va_end(args);
}

/// ditto
abstract void warningSupplemental(const ref Loc loc, const(char)* format, va_list);

/**
Reports a deprecation message.

Params:
loc = Location of the deprecation
format = format string for the deprecation
... = format string arguments
*/
final void deprecation(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
deprecation(loc, format, args);
va_end(args);
}

/// ditto
abstract void deprecation(const ref Loc loc, const(char)* format, va_list args);

/**
Reports additional details about a deprecation message.

Params:
loc = Location of deprecation
format = format string for supplemental message
... = format string arguments
*/
final void deprecationSupplemental(const ref Loc loc, const(char)* format, ...)
{
va_list args;
va_start(args, format);
deprecationSupplemental(loc, format, args);
va_end(args);
}

/// ditto
abstract void deprecationSupplemental(const ref Loc loc, const(char)* format, va_list);
}

/**
Diagnostic reporter which prints the diagnostic messages to stderr.

This is usually the default diagnostic reporter.
*/
final class StderrDiagnosticReporter : DiagnosticReporter
{
private const DiagnosticReporting useDeprecated;

private int errorCount_;
private int warningCount_;
private int deprecationCount_;

nothrow:

/**
Initializes this object.

Params:
useDeprecated = indicates how deprecation diagnostics should be
handled
*/
this(DiagnosticReporting useDeprecated)
{
this.useDeprecated = useDeprecated;
}

override int errorCount()
{
return errorCount_;
}

override int warningCount()
{
return warningCount_;
}

override int deprecationCount()
{
return deprecationCount_;
}

override void error(const ref Loc loc, const(char)* format, va_list args)
{
verror(loc, format, args);
errorCount_++;
}

override void errorSupplemental(const ref Loc loc, const(char)* format, va_list args)
{
verrorSupplemental(loc, format, args);
}

override void warning(const ref Loc loc, const(char)* format, va_list args)
{
vwarning(loc, format, args);
warningCount_++;
}

override void warningSupplemental(const ref Loc loc, const(char)* format, va_list args)
{
vwarningSupplemental(loc, format, args);
}

override void deprecation(const ref Loc loc, const(char)* format, va_list args)
{
vdeprecation(loc, format, args);

if (useDeprecated == DiagnosticReporting.error)
errorCount_++;
else
deprecationCount_++;
}

override void deprecationSupplemental(const ref Loc loc, const(char)* format, va_list args)
{
vdeprecationSupplemental(loc, format, args);
}
}

/**
* Color highlighting to classify messages
*/
Expand Down Expand Up @@ -782,8 +573,7 @@ private void colorHighlightCode(ref OutBuffer buf)
++nested;

auto gaggedErrorsSave = global.startGagging();
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1, diagnosticReporter);
scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1);
OutBuffer res;
const(char)* lastp = cast(char*)buf[].ptr;
//printf("colorHighlightCode('%.*s')\n", cast(int)(buf.length - 1), buf.data);
Expand Down
9 changes: 3 additions & 6 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5662,17 +5662,14 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
uint errors = global.errors;
const len = buf.length;
const str = buf.extractChars()[0 .. len];
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(exp.loc, sc._module, str, false, diagnosticReporter);
scope p = new Parser!ASTCodegen(exp.loc, sc._module, str, false);
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);

Expression e = p.parseExpression();
if (p.errors)
{
assert(global.errors != errors); // should have caught all these cases
if (global.errors != errors)
return null;
}

if (p.token.value != TOK.endOfFile)
{
exp.error("incomplete mixin expression `%s`", str.ptr);
Expand Down
Loading