Architecture proposal #2
Labels
enhancement
New feature or request
frontend
The CLI interface or other user-facing issues
functionality
Core functionality and features
Milestone
I'd like to propose an architecture for this tool to be as versatile, easily extensible and testable as possible. This would involve decoupling the input language from the class hierarchy and transformations, and decoupling the output format from those as well.
The components would be:
In the following sections I'd like to detail these components slightly more.
Core library
Class hierarchy
The core could provide the model for the inheritance tree. It could look something like so (just a sketch):
Something like this wouldn't be too language-specific, but isn't too general either to be practically useless. Things like the type specification could be elaborated better, if needed. Also, read-write properties would be nicer for such an API, I only used records for the simple syntax.
Tree transformation
The key operation the core would provide is tree transformation. It would take a tree hierarchy as an input, apply a transformation that would result in a new tree hierarchy. This is how the passes would build up their trees. Transformations could optionally be applied on nodes matching a certain pattern. A possible API:
Built-in transformations we could provide (and we could extend later):
Built-in patterns we could provide (and we could extend later):
Rationale for the scope
I believe this is a well-testable and easily extensible component. The rest deal with input and output, which likely means mostly integration and end-to-end tests will apply to them. This component can be unit-tested to oblivion with all the patterns and transformations.
Input language libraries
These would be less interesting libraries, taking an input language and then transforming it to the core library representations, describing passes. Most likely it would invoke some existing language parser, like YAML or JSON, but it could also be some custom notation. I wouldn't focus on developing many of these "front-ends" until the core has a stable enough API. Note, that the input languages don't have to expose 100% of the core features. It's perfectly fine to only support the necessities.
Templating library
The templating library would wrap up the tree into a more redundant data structure that is more easily consumed by template engines. For example, these node wrappers would provide navigation to both the parent and children, or they could list all members, including the inherited ones. To stay language-agnostic, these should be generic wrappers, that the language-specific wrappers could re-use. For example, this library could ship a node wrapper something like this:
Output language libraries
The output language libraries would adapt the wrappers in the templating library to the destination language (this is why the wrappers are abstract and generic). For example, adapting it to C#:
The libraries would ship the required templates:
Optionally, the library would ship a language formatter, or have the knowledge to invoke a pre-installed language formatter.
The text was updated successfully, but these errors were encountered: