fixes tagof behaviour on default values #274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, if the tagof operator was used on an argument with default value, the tag identifier recorded would be 0 in case the default value was used.
In the above code, the argument
a
would have the value123
butb
would have0
.This commit patches the bug. The value of
b
will be the tag identifier of the default argument.This commit patches for two cases: default argument is a reference and default argument is a variable.
The case of reference arrays is not handled correctly as the tag of the default reference array is not well defined.
Implementation details:
The compiler first processes arguments which are not taking default values (including
tagof
andsizeof
parameters). The compiler does a second pass on the list of all formal parameters and processes the default values. The compiler then does a final pass on the list of formal parameters and processessizeof
andtagof
parameters.The compiler maintains a list of tags of all the arguments in a
constvalue
list calledtaglst
as it processes the arguments.The name field of the members of the tag list is the argument name and the tag field stores the tag identifier of that argument (tag identifier of the actual parameter).
In the first pass where the expclit arguments are being processed, the compiler checks the argument's tag and adds the tag along with the formal parameter name (can be thought of as ) to the tag list if the tag identifier is NOT zero.
In the second pass where the default values are being handled, the compiler does not modify the tag list (source of the bug).
After all the arguments other than
sizeof
andtagof
have been handled othe, the compiler iterates through the list of arguments and takes care ofsizeof
andtagof
arguments.Here it checks to which formal parameter (say F) the
tagof
parameter (say T) points to. It then checks the tag list for that symbol F, if an entry is found, it uses the tag identifier associated with that argument. If not found, it defaults to 0.Since the tags of default arguments along with it's formal name is not added to the tag list, the third pass won't be aware of any tag associated with the default values and assumes 0.
This commit adds code to add the tags of the default values to the tag list so that the compiler is aware of the tag of the default values in the final pass.
Fixes #268
Basic tests:
Output: