-
Notifications
You must be signed in to change notification settings - Fork 467
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
Refactor to remove Context
dependency from To_String
and others
#1754
Conversation
f95d2bf
to
8ddd005
Compare
489ec90
to
580bf8a
Compare
Ensures we always have a valid object by not allowing NULL to be passed to the constructor.
Stores `Memory_Manager` instead of `Context` on `Listize`
Ruby sass often uses inspect internally, which can produce different results than with any other output mode. So far I was not really aware of that fact. This should allow us to match ruby sass output better and not produce to much code duplication. Ultimately we should only have one `inspect` visitor class.
6b3f8ca
to
e027ce7
Compare
Once green this is also ready to be merged. It's the base work to reunite all stringification functions again. They deviated because I often could not use the visitor classes due to the dependency on context. With this now gone, we can implement a visitor class that only has a bare minimum of internal dependecies (bascially what inspect visitor class is now with the new option for ruby inspect). |
Refactor to remove `Context` dependency from `To_String` and others
Keen in mind we should aim to have two stringification functions. One for |
We don't want to have two visitor classes for this, so we need one option to pass to one visitor class. I added an additional "output style" for that puropse. We have 4 Reason we do not want to have 2 visitor classes: Once we fall back from to_css to inspect all further calls are within inspect. So one visitor class fits bests, and with that 5th option we have everything covered. |
For that purpose I introduced |
Also worth noting: the approach I chose with adding virtual |
I hope that makes sense, I do not take these changes lightly either! |
To clarify the goal: We should have one |
This is a continuation #1736.
Premise: The Context is the main Object which manages and abstracts all internas for parsing and compiling. It takes an option C struct to construct and implements the
parse
andcompile
methods. It also serves as main lifecycle for created objects (as in Ast Nodes).Currently we have still a lot of places which need the main
Context
(akactx
) instance to be around, which makes it often impossible to call certain functions (likeTo_String
visitor) from methods that simply don't have any direct connection to the mainContext
(and therefore don't have access to it).In the past we mostly just passed around and stored the
ctx
everywhere. This worked as long as we lived inside our own execution path, but this first bit me when I wanted to expose operations and stringification on the C-API. It's absolutely legal to create two Sass Values outside of any actual Context and then call an operation on them. This is just one example where we need thectx
for mainly two reasons.a) accessing the options (output style, precision and others)
b) to create object with a managed life-cycle
This PR will be a first round to finally decouple those two needs from
class Context
. I already have refactored theMemory_Manager
at an earlier point to make this feasible, since we can now create life-cycles on demand when needed (first use case was the exposure of sass operations). So the second problem is pretty much already solved.I also made quite a few refactorings to have the options decoupled from context already. The
to_string
methods on Ast Nodes of the baseclass Value
takes two arguments (output style and precision), since they never need any other. We also haveTo_String
CRTP vistors, which pretty much do the same, but for all Ast Nodes, but as already mentioned they need access toctx
.I hope this explains the motivations behind this refactoring. I'm aware that this will not be the perfect solution and will probably require more refactorings, until also the internal API gets more and more sane.
I will now create meaningfull commits out of my now passing local branch ... could take some time.