Add dmd as a lib callbacks for statement semantic#11092
Add dmd as a lib callbacks for statement semantic#11092dlang-bot merged 8 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @cristiancreteanu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#11092" |
|
Would make more sense maybe if these could be fields inside the Compiler structure. |
|
I have added a ScopeDsymbol to FuncDeclaration and ScopeStatement for a similar purpose, see rainers@bc9b1c7 The visitor to find the AST node for the caret is here: https://github.com/dlang/visuald/blob/master/vdc/dmdserver/semvisitor.d#L625 but there is also some additional machinery in place, e.g. remembering the original AST when it is modified during semantic analysis. |
Now that you mention this, maybe keeping them on a global level isn't such a good idea, but I would rather add them as static fields inside the Statement class, as I am thinking that, since they are used for the semantic analysis of Statement instances, that's where they would probably be suited to be. But, based on your experience, could you please tell me why it would be better to add them in the Compiler structure? |
Thanks! So I understand that VisualD uses your fork instead of the latest version of DMD. How come you haven't merged those changes to DMD? It would also solve my issue. |
Yes.
Mostly to avoid endless discussions and fighting with the CI;-) Not all changes might be uncontroversial, and some probably need polishing. #10846 was actually an attempt to start with creating small PRs, but that hit a road block because some tooling seems to depend on the current state, but it is outside the dlang repositories. |
There's already Compiler.onImport and Compiler.loadModule (which I want to get renamed to something like onModuleLoad) which both are similar callbacks from frontend to compiler driver. The dmd.compilur module is intended to be implemented independently by each glue frontend, so gdc and ldc can each implement their own actions if required. |
bce1375 to
482b81a
Compare
RazvanN7
left a comment
There was a problem hiding this comment.
Add a test and we are good to go.
Is anyone against this addition? This makes dmd as a library usable with DCD.
MoonlightSentinel
left a comment
There was a problem hiding this comment.
Please also hide the other changes behind version (Callback_API), they are unused when compiling without this version.
Otherwise LGTM
33ca641 to
8611dff
Compare
|
I separated the creation of a single module so that I could use the function as part of the compiler's interface, as it can be seen in the test. It was also possible to use the already existent |
f0c6a65 to
a43c1b2
Compare
a43c1b2 to
3844afb
Compare
MoonlightSentinel
left a comment
There was a problem hiding this comment.
The internal changes are fine by me. Cannot really comment on it's usefullness for DMD as a library though.
While trying to change the implementation of DCD to use DMD as a library, I have come across the need to retrieve the Scope of a Statement (namely the Statement at the location in the source file where the cursor is) without having too much of an impact on DMD's performance, but I couldn't find an easy way to do so by only using a visitor on the AST, as not all nodes had a Scope field or, if they did, it was null (in particular the _scope field of Dsymbol, which was null, except for field declarations). I took Basile's suggestions on the forum (https://forum.dlang.org/post/pinxxdclrvdnidpnxixr@forum.dlang.org).
With the current approach, however, I will not get results if the node whose Scope I am trying to find is a field declaration inside a class/struct/enum. To solve this problem, I could either use the same approach that I used for Statement and add delegates for Dsymbol in dsymbolsem or I could implement a custom visitor which traverses the AST and reaches the required node (which will be a Dsymbol whose _scope is set). What do you think is the best solution in this case?