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
4 changes: 3 additions & 1 deletion src/dmd/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dmd.globals;
import dmd.id;
import dmd.identifier;
import dmd.mtype;
import dmd.lexer;
import dmd.parse;
import dmd.root.array;
import dmd.root.ctfloat;
Expand Down Expand Up @@ -86,7 +87,8 @@ struct Compiler
};
Identifier id = Id.entrypoint;
auto m = new Module("__entrypoint.d", id, 0, 0);
scope p = new Parser!ASTCodegen(m, cmaincode, false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(m, cmaincode, false, diagnosticReporter);
p.scanloc = Loc.initial;
p.nextToken();
m.members = p.parseModule();
Expand Down
4 changes: 3 additions & 1 deletion src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import dmd.expressionsem;
import dmd.globals;
import dmd.id;
import dmd.identifier;
import dmd.lexer;
import dmd.parse;
import dmd.root.file;
import dmd.root.filename;
Expand Down Expand Up @@ -850,7 +851,8 @@ extern (C++) final class Module : Package
isHdrFile = true;
}
{
scope p = new Parser!ASTCodegen(this, buf[0 .. buflen], docfile !is null);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(this, buf[0 .. buflen], docfile !is null, diagnosticReporter);
p.nextToken();
members = p.parseModule();
md = p.md;
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -3480,7 +3480,8 @@ private void highlightCode3(Scope* sc, OutBuffer* buf, const(char)* p, const(cha
private void highlightCode2(Scope* sc, Dsymbols* a, OutBuffer* buf, size_t offset)
{
uint errorsave = global.startGagging();
scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1, diagnosticReporter);
OutBuffer res;
const(char)* lastp = cast(char*)buf.data;
//printf("highlightCode2('%.*s')\n", cast(int)(buf.offset - 1), buf.data);
Expand Down
4 changes: 3 additions & 1 deletion src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import dmd.identifier;
import dmd.init;
import dmd.initsem;
import dmd.hdrgen;
import dmd.lexer;
import dmd.mtype;
import dmd.nogc;
import dmd.nspace;
Expand Down Expand Up @@ -1880,7 +1881,8 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
const errors = global.errors;
const len = buf.offset;
const str = buf.extractString()[0 .. len];
scope p = new Parser!ASTCodegen(cd.loc, sc._module, str, false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(cd.loc, sc._module, str, false, diagnosticReporter);
p.nextToken();

auto d = p.parseDeclDefs(0);
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ private void colorHighlightCode(OutBuffer* buf)
++nested;

auto gaggedErrorsSave = global.startGagging();
scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1, diagnosticReporter);
OutBuffer res;
const(char)* lastp = cast(char*)buf.data;
//printf("colorHighlightCode('%.*s')\n", cast(int)(buf.offset - 1), buf.data);
Expand Down
4 changes: 3 additions & 1 deletion src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dmd.identifier;
import dmd.imphint;
import dmd.inline;
import dmd.intrange;
import dmd.lexer;
import dmd.mtype;
import dmd.nspace;
import dmd.opover;
Expand Down Expand Up @@ -5435,7 +5436,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
uint errors = global.errors;
const len = buf.offset;
const str = buf.extractString()[0 .. len];
scope p = new Parser!ASTCodegen(exp.loc, sc._module, str, false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(exp.loc, sc._module, str, false, diagnosticReporter);
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);

Expand Down
29 changes: 25 additions & 4 deletions src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
module dmd.frontend;

import dmd.dmodule : Module;
import dmd.lexer : DiagnosticReporter;

import std.range.primitives : isInputRange, ElementType;
import std.traits : isNarrowString;
import std.typecons : Tuple;
Expand Down Expand Up @@ -271,10 +273,21 @@ Parse a module from a string.
Params:
fileName = file to parse
code = text to use instead of opening the file
diagnosticReporter = the diagnostic reporter to use. By default a
diagnostic reporter which prints to stderr will be used

Returns: the parsed module object
*/
Tuple!(Module, "module_", Diagnostics, "diagnostics") parseModule(const(char)[] fileName, const(char)[] code = null)
Tuple!(Module, "module_", Diagnostics, "diagnostics") parseModule(
const(char)[] fileName,
const(char)[] code = null,
DiagnosticReporter diagnosticReporter = defaultDiagnosticReporter
)
in
{
assert(diagnosticReporter !is null);
}
body
{
import dmd.astcodegen : ASTCodegen;
import dmd.globals : Loc, global;
Expand All @@ -284,9 +297,9 @@ Tuple!(Module, "module_", Diagnostics, "diagnostics") parseModule(const(char)[]
import std.string : toStringz;
import std.typecons : tuple;

static auto parse(Module m, const(char)[] code)
static auto parse(Module m, const(char)[] code, DiagnosticReporter diagnosticReporter)
{
scope p = new Parser!ASTCodegen(m, code, false);
scope p = new Parser!ASTCodegen(m, code, false, diagnosticReporter);
p.nextToken; // skip the initial token
auto members = p.parseModule;
if (p.errors)
Expand All @@ -297,7 +310,7 @@ Tuple!(Module, "module_", Diagnostics, "diagnostics") parseModule(const(char)[]
Identifier id = Identifier.idPool(fileName);
auto m = new Module(fileName.toStringz, id, 0, 0);
if (code !is null)
m.members = parse(m, code);
m.members = parse(m, code, diagnosticReporter);
else
{
m.read(Loc.initial);
Expand Down Expand Up @@ -350,3 +363,11 @@ string prettyPrint(Module m)
auto generated = buf.extractData.fromStringz.replace("\t", " ");
return generated.assumeUnique;
}

private DiagnosticReporter defaultDiagnosticReporter()
{
import dmd.globals : global;
import dmd.lexer : StderrDiagnosticReporter;

return new StderrDiagnosticReporter(global.params.useDeprecated);
}
10 changes: 7 additions & 3 deletions src/dmd/iasmgcc.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import dmd.expression;
import dmd.expressionsem;
import dmd.identifier;
import dmd.globals;
import dmd.lexer;
import dmd.parse;
import dmd.tokens;
import dmd.statement;
Expand Down Expand Up @@ -283,7 +284,8 @@ Ldone:
public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
{
//printf("GccAsmStatement.semantic()\n");
scope p = new Parser!ASTCodegen(sc._module, ";", false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(sc._module, ";", false, diagnosticReporter);

// Make a safe copy of the token list before parsing.
Token *toklist = null;
Expand Down Expand Up @@ -369,7 +371,8 @@ unittest
static int semanticAsm(Token* tokens)
{
scope gas = new GccAsmStatement(Loc.initial, tokens);
scope p = new Parser!ASTCodegen(null, ";", false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(null, ";", false, diagnosticReporter);
p.token = *tokens;
p.parseGccAsm(gas);
return p.errors;
Expand All @@ -379,7 +382,8 @@ unittest
static void parseAsm(string input, bool expectError)
{
// Generate tokens from input test.
scope p = new Parser!ASTCodegen(null, input, false);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(null, input, false, diagnosticReporter);
p.nextToken();

Token* toklist = null;
Expand Down
Loading