Skip to content

Commit

Permalink
Add visitor test plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen committed Jul 5, 2023
1 parent 9cf7d91 commit f1b38d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/plugins/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (config.plugins_supported):
'--d-version=IN_LLVM',
'-J' + config.ldc2_source_dir + '/dmd/res',
'--shared',
'--defaultlib=',
]
if (platform.system() == 'Darwin'):
plugin_compile_flags.append('-L-Wl,-undefined,dynamic_lookup')
Expand Down
51 changes: 51 additions & 0 deletions tests/plugins/visitor_example.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// REQUIRES: Plugins

// RUN: split-file %s %t --leading-lines
// RUN: %ldc -g %t/plugin.d %plugin_compile_flags -of=%t/plugin%so
// RUN: %ldc -wi -c -o- --plugin=%t/plugin%so %t/testcase.d 2>&1 | FileCheck %t/testcase.d

//--- plugin.d
import dmd.dmodule;
import dmd.errors;
import dmd.location;
import dmd.visitor;
import dmd.declaration;
import dmd.dsymbol;

extern(C++) class MyVisitor : SemanticTimeTransitiveVisitor {
alias visit = SemanticTimeTransitiveVisitor.visit;

override void visit(VarDeclaration vd) {
if (vd.aliasTuple)
warning(vd.loc, "It works!");
}
}

extern(C) void runSemanticAnalysis(Module m) {
scope v = new MyVisitor();
if (!m.members)
return;
m.members.foreachDsymbol((s) {
s.accept(v);
});
}

//--- testcase.d
alias AliasSeq(TList...) = TList;

int i = 0;
struct A {
~this() {
i *= 2;
}
}

void main() {
{
// CHECK: testcase.d([[@LINE+1]]): Warning:
AliasSeq!(A, A) params;
i = 1;
}

assert(i == 4);
}

0 comments on commit f1b38d7

Please sign in to comment.