Skip to content

Group scattered AST visitors into a visitors package#7639

Closed
wilzbach wants to merge 5 commits intodlang:masterfrom
wilzbach:move-visitors
Closed

Group scattered AST visitors into a visitors package#7639
wilzbach wants to merge 5 commits intodlang:masterfrom
wilzbach:move-visitors

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Jan 8, 2018

I started off by moving the four visitors (parsetime, permissive, strict, transitive)
to their own package.
Then visitor.d and visitors looked a bit strange, so I moved visitor.d to visitors/package.d

As there is also astXXXX, dmd.ast.visitors would work too.

CC @RazvanN7

@dlang-bot
Copy link
Contributor

dlang-bot commented Jan 8, 2018

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

#include "tokens.h"
#include "version.h"
#include "visitor.h"
#include "visitors/package.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be kept in toplevel? I'd be ok with a rename to visitors.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I wasn't fully sure about this anyways (that's why I kept this change as a separate commit).

@wilzbach wilzbach added Review:WIP Work In Progress - not ready for review or pulling and removed Severity:Bug Fix labels Jan 8, 2018
@wilzbach wilzbach removed the Review:WIP Work In Progress - not ready for review or pulling label Jan 8, 2018
@WalterBright
Copy link
Member

A little exposition on how this improves encapsulation would be nice. It's hard to tell from the diffs.

@wilzbach
Copy link
Contributor Author

wilzbach commented Jan 9, 2018

A little exposition on how this improves encapsulation would be nice. It's hard to tell from the diffs.

This group all the various visitors in the codebase neatly together, s.t. they are easy to find for an reader looking to learn more about DMD's visitors:

image

  • the dmd.visitors module package is now the go-to place on the documentation and can e.g. contain a class hierarchy diagram (see below) and further explanations
  • it highlights that dmd.visitors.strict is currently unused

Hierarchy in dmd.visitors

extern (C++) class ParseTimeVisitor(AST)

  • extern (C++) class Visitor : ParseTimeVisitor!ASTCodegen
    • extern (C++) class StoppableVisitor : Visitor
  • extern (C++) class SemanticTimePermissiveVisitor : Visitor
    • extern (C++) class SemanticTimeTransitiveVisitor : SemanticTimePermissiveVisitor
  • class PermissiveVisitor(AST): ParseTimeVisitor!AST
    • ParseTimeTransitiveVisitor(AST) : PermissiveVisitor!AST
      • StrictVisitor(AST) : ParseTimeVisitor!AST

(simplified)

There's probably a lot more on @RazvanN7's mind.

@wilzbach wilzbach changed the title Move AST visitors visitors Group scattered AST visitors into a visitors package Jan 9, 2018
dub.sdl Outdated
"src/dmd/strictvisitor.d"
"src/dmd/visitors/transitive.d" \
"src/dmd/visitors/permissive.d" \
"src/dmd/visitors/strict.d"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "src/dmd/visitors/package.d"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also parsetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why it didn't break, is because this package isn't used anymore. There's frontend now...

@PetarKirov
Copy link
Member

BTW, the convention for naming modules composed of two or more words is to separate the parts with an underscore. So how about renaming parsetime to parse_time?

- semantic.d
- stoppable.d
- permissive.d
- transitive.d
@wilzbach
Copy link
Contributor Author

(rebased)

Andrei: There seems to be merit in putting the entire visitation hierarchy in a separate package.

@andralex @WalterBright so can we move forward here? It looks like the PR is blocked on your approval.

@WalterBright
Copy link
Member

This PR is just the start of a cleanup series :)

Oh gawd, please no. No packages, no glorious shuffling everything around.

@WalterBright
Copy link
Member

Let's close this.

I've pointed out several times a list of things that will substantively improve DMD's encapsulation, readability, maintainability, etc. I will prepare a better list and post it to the n.g. That's what we should be spending time on.

@wilzbach
Copy link
Contributor Author

I've pointed out several times a list of things that will substantively improve DMD's encapsulation, readability, maintainability, etc. I will prepare a better list and post it to the n.g. That's what we should be spending time on.

Fair enough. Looking forward to the list!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants