Fix Issue 23838 - DMD lexer / parser examples might not compile (#15106)

This commit is contained in:
Razvan Nitu 2023-04-17 15:57:30 +03:00 committed by GitHub
parent 8f9e710ff9
commit dd4fbf43f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 22 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
/* This file contains an example on how to use the transitive visitor.
It implements a visitor which computes the average function length from
@ -10,7 +10,7 @@ dependency "dmd" path="../.."
module examples.avg;
import dmd.astbase;
import dmd.errors;
import dmd.errorsink;
import dmd.parse;
import dmd.target;
import dmd.transitivevisitor;
@ -60,8 +60,9 @@ void main()
auto id = Identifier.idPool(fname);
auto m = new ASTBase.Module(&(fname.dup)[0], id, false, false);
auto input = readText(fname);
input ~= '\0';
scope p = new Parser!ASTBase(m, input, false);
scope p = new Parser!ASTBase(m, input, false, new ErrorSinkStderr(), null, false);
p.nextToken();
m.members = p.parseModule();

View file

@ -1,6 +1,6 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
import std.stdio;

View file

@ -1,6 +1,6 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
import std.stdio;
import std.string : replace;

View file

@ -1,6 +1,6 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
import dmd.permissivevisitor;
@ -27,7 +27,7 @@ extern(C++) class ImportVisitor2(AST) : ParseTimeTransitiveVisitor!AST
printf("%s", imp.id.toChars());
if (imp.names.dim)
if (imp.names.length)
{
printf(" : ");
foreach (const i, const name; imp.names)
@ -82,12 +82,13 @@ void main()
import dmd.id;
import dmd.globals;
import dmd.identifier;
import dmd.errorsink;
import dmd.target;
import core.memory;
GC.disable();
string path = __FILE_FULL_PATH__.dirName.buildPath("../../../phobos/std/");
string path = __FILE_FULL_PATH__.dirName.buildPath("../../../../phobos/std/");
string regex = "*.d";
auto dFiles = dirEntries(path, regex, SpanMode.depth);
@ -106,9 +107,10 @@ void main()
auto id = Identifier.idPool(fn);
auto m = new ASTBase.Module(&(fn.dup)[0], id, false, false);
auto input = readText(fn);
input ~= '\0';
//writeln("Started parsing...");
scope p = new Parser!ASTBase(m, input, false);
scope p = new Parser!ASTBase(m, input, false, new ErrorSinkStderr(), null, false);
p.nextToken();
m.members = p.parseModule();
//writeln("Finished parsing. Starting transitive visitor");

View file

@ -1,12 +1,13 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
void main()
{
import dmd.globals;
import dmd.lexer;
import dmd.tokens;
import dmd.errorsink;
immutable expected = [
TOK.void_,
@ -18,7 +19,7 @@ void main()
];
immutable sourceCode = "void test() {} // foobar";
scope lexer = new Lexer("test", sourceCode.ptr, 0, sourceCode.length, 0, 0);
scope lexer = new Lexer("test", sourceCode.ptr, 0, sourceCode.length, 0, 0, 0, new ErrorSinkStderr);
lexer.nextToken;
TOK[] result;

View file

@ -1,13 +1,14 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
+/
void main()
{
import dmd.astbase;
import dmd.globals;
import dmd.parse;
import dmd.errorsink;
scope parser = new Parser!ASTBase(null, null, false);
scope parser = new Parser!ASTBase(null, null, false, new ErrorSinkStderr, null, false);
assert(parser !is null);
}

View file

@ -1,6 +1,6 @@
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" path="../.."
dependency "dmd" path="../../.."
versions "CallbackAPI"
+/
/*
@ -20,13 +20,13 @@ import std.path : dirName;
import dmd.errors;
import dmd.frontend;
import dmd.mars;
import dmd.console;
import dmd.arraytypes;
import dmd.compiler;
import dmd.dmodule;
import dmd.dsymbol;
import dmd.dsymbolsem;
import dmd.location;
import dmd.semantic2;
import dmd.semantic3;
import dmd.statement;
@ -77,14 +77,9 @@ int main()
global.gag = 1;
initDMD(diagnosticHandler);
Strings libmodules;
Module m = createModule((dirName(__FILE_FULL_PATH__) ~ "/testfiles/correct.d").ptr,
libmodules);
Module m = parseModule(__FILE_FULL_PATH__ ~ "/testfiles/correct.d").module_;
m.importedFrom = m; // m.isRoot() == true
m.read(Loc.initial);
m.parse();
CallbackHelper.cursorLoc = Loc(to!string(m.srcfile).ptr, 22, 10);
Compiler.onStatementSemanticStart = &CallbackHelper.statementSem;

View file

@ -31,7 +31,8 @@ subPackage {
"compiler/src/dmd/lexer.d" \
"compiler/src/dmd/location.d" \
"compiler/src/dmd/tokens.d" \
"compiler/src/dmd/utils.d"
"compiler/src/dmd/utils.d" \
"compiler/src/dmd/errorsink.d"
versions \
"CallbackAPI" \