Closed
Description
The AST to ASR has to do something like the following.
- Maintain a hashtable/mapping of labels (strings) -> (unique IDs, bool declared); initialize it as empty when entering a new function
- Every time you encounger a "goto label", lookup the label in the mapping, two cases can happen:
- if it is already there, use the ID from the mapping and create GoTo(ID)
- if it is not there, add it to the mapping, and note that it has not been declared yet, and assign a unique ID to it; then use that unique ID in GoTo(ID)
- Every time you encounter "label label", lookup the label in the mapping, two cases can happen:
- if it is there, change declared to yes, use the ID in GoToTarget(ID)
- if it is not there, create a new label in the mapping, assign unique ID and declared as yes, then use that ID in GoToTarget(ID)
- at the end of the function, go over this mapping and check that each label has been declared. If there is one or more labels that has not been declared, raise a compiler error. This corresponds to the case of using a "goto label" without having the corresponding "label label" statement.
Metadata
Metadata
Assignees
Labels
No labels
Activity
czgdp1807 commentedon Sep 23, 2022
czgdp1807 commentedon Sep 23, 2022
Will we allow something like,
If we are going to allow the above case, then will we generate hash maps for
fandgseparately? Willgotoinfbe allowed to jump to label defined insideg?certik commentedon Sep 23, 2022
I think so. We can handle this case later.
I don't think so.