Hello and welcome, everybody.
And in this lecture, we're going to take our fix up functionality that we made in the last lecture,
and we're going to apply it to our puzzle.
So just head over to paths that dot see and scroll all the way up to current process.
We're going to add another structure in here.
Our fix up system that we created in our last lecture has a fix up, says, Well, call it now, head
over to your pause function.
And just in the paths of blank, no, we're going to say fix up positive fixed success equals fix up
sets new and then we'll create our new fix subsystem.
Okay.
Now, after we finish parsing, we need to run our resolve on it.
So we're going to say assert fix ups.
Resolve has a fix up system and that'll just resolve all of our fix ups and it will assert that it returns
true.
Now we need to register our fix ups.
That's the last thing we need to do.
And where would we do that and make variable node?
Of course, that's where it will be done because this is where all variable nodes get created.
So it's the perfect place to register a fixed sub for structure variables.
Okay.
So just by here we're going to say struck node var node equals no pop.
So we're going to pop off the node we created.
Now where would we register a fix up?
If we go back to the presentation, you'll see that I mentioned that the fix up should be created when
we cannot resolve the structure.
So if the structure is declared further down the file and our variable node that's using the structure
is above that structure declaration, that's when a fix is required.
So again, this only applies to structure variables.
So the first thing we're going to do, we're going to check that the variable type is a data type struct.
That's the first thing we're checking for.
Then we're going to check to see if no structure node is associated with it.
Because if the struct node is null, then that means that once this was registered, we couldn't actually
resolve the actual structure node in this data type.
When this data type was created, we couldn't actually resolve the structure node.
So there the two situations we care about and this needs to be dot type type.
So yeah, we only care about fixing variables that are data type of struct and that don't have a struct
node set.
And I know we're not taking into account unions here.
We can get back to that another time.
Okay.
So just above here, we need to create new structure, data type, struct node, fix private and this
will contain a node to fix.
Okay.
So now we're going to create an instance of that private data.
I'm just going to call it private.
So we declare some memory for that and we're going to say private node equals var node, and then we're
going to say fix up, register.
And then we have to provide system and a fix of config.
We haven't created fix of config yet on this line where I did know Pop actually needs to be no peek
or no, so just make sure you do that.
Okay.
So just above here, we're going to create our fix up function now because we need to create that before
we can call fix up register.
So we're going to say ball data, type, struct, node fix and this will give us a fix up.
Of course, we're just going to return through here to say that we was fixed successfully.
Now here we're going to say struct data type struck node fix private, private equals fix the private
fix up.
But I'm going to say struct data type de type equals and private node var dot type.
So we're fixing it now, right?
So we're going to say D type type equals data type struct de type size equals size of struct D type
type string.
So I re computing everything we would have done originally.
Okay.
After parsing completed d type struck node equals struck node for name column process d type type string.
Now, if we were still unable to resolve it, then we return false because there was no structure associated.
Like basically we use a structure that was never in existence and never existed throughout the entire
compile process.
So it's an error.
And now we're going to define our data type struct node end.
And all we're going to do here is free the fix up, private.
Okay, perfect.
So now the final thing to do is to use the fix it register.
So our system is parser fix subsystem.
Our config is a fix up config and we're going to say fix equals fix up.
What was it called fix ups.
Oh, no, it was data type struck.
No fix.
So data type struck, no fix.
Our end is data type struct node end and our private data is the private data OC.
So you should always be using a new configuration every time, because obviously we have to press the
private data.
So it needs to be a new instance of that every time.
I mean, the register function will copy it anyway.
So if you did use a pointer, but I recommend doing it the same way as I have and that should be it.
Let's see if it compiles.
So we can see there are some conflicting types.
So that's not a problem.
We're just going to have to fix it.
So that's going to fix the dot, see?
And I can see what we've done.
Firstly, we forgot to remove all of the actual structure information that we put in the header last
time.
So get rid of that and now we're going to try and make cleaning the make and there we go.
Everything works.
So type main, everything's fine.
Perfect.