-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[swift2objc] Visitor infra #1834
Conversation
@dcharkes @HosseinYousefi This is ready to go. PTAL |
|
||
final _logger = Logger('swift2objc.visitor'); | ||
|
||
/// Wrapper around [Visitation] to be used by callers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation could be improved.
If I understand it correctly, the visitor does the traversal, and the visitation contains the methods on what to modify for each node type.
"Wrapper" doesn't say what it's responsibility is and isn't.
I'd maybe call the the class that determines the traversal order the Traverser
. Or TraversalStrategy
(terminology taken from https://strategoxt.org/, which also explicitly separates the function applied to a node on visit, and the traversal strategy of traversing the whole tree).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I prefer to have the names of tightly coupled classes like this be closely related though. Visitor
and Visitation
makes them sound more related than Traverser
and Visitation
.
/// ## Creating a new type of [AstNode] | ||
/// | ||
/// For example, adding a class `Foo` which extends `Bar`, which somewhere up | ||
/// the heirarchy extends [AstNode]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// the heirarchy extends [AstNode]: | |
/// the hierarchy extends [AstNode]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/// distinction is why [Visitor] and [Visitation] are seperate classes. | ||
/// | ||
/// The `visitFoo` methods in this class should reflect the inheritance | ||
/// heirarchy of all AstNodes. Eg `visitChild` should default to calling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// heirarchy of all AstNodes. Eg `visitChild` should default to calling | |
/// hierarchy of all AstNodes. Eg `visitChild` should default to calling |
:P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
visitEnumDeclaration(node); | ||
|
||
/// Default behavior for all visit methods. | ||
void visitAstNode(AstNode node) => node..visitChildren(visitor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could also be node.visitChildren
instead of ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. A leftover from when this was a transformer that returned nodes.
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
This is the same infra as ffigen uses: #1638.
AstNode
classes etc from ffigenAstNode
, and implemented thevisit
andvisitChildren
methods.BuiltInDeclaration
had to be converted from an enum to a classDependencyVisitor
using theVisitation
classIdeally we'd share the
AstNode
,Visitor
, andVisitation
classes, but we don't really have a way of sharing internal code between native packages yet.Part of #1358