Open bgrevelt opened 7 years ago
This is done, but I had to make a couple of hacks to get it to work. Changes should be reviewed.
Basically I delegated all of the type checking work to the value class, because we already have that logic there. It did not make sense to me to write the same logic again. This also meant that we no longer needed the QLType enumeration. Downside was that I needed to be able to default-construct the value types. This is also the source of two of my hacks. IntValue and DecimalValue will get a value of zero when they are default initialised. This poses some problems when we defer type checking to the value type for division. The class is not aware that we are only doing type checking, so it actually tries to do the division. Since both operands are zero, we get a division by zero error.
I now initialise the values to 1 when they are default initialised, but that's really ugly. Another option would be to accept division by zero errors in the semantic analysis, but that seems more like a workaround than a solution. Basically the problem we have here is that we get runtime behaviour at a time where we just want to do static checking. Maybe we can think of a way where we do not duplicate the logic, but still can make a distinction between runtime actions and type checking?
We have to discuss this tomorrow, this is horrible. I don't even understand why you needed the default constructor since you could just have passed 1 and 1.0 to the existing one. We now have magic numbers in the constructors.
See if runtime type information is an option (ask in lecture tomorrow).
This way we keep all the stuff related to types and operators together