Package ru.ispras.microtesk.test
Class LabelManager
- java.lang.Object
-
- ru.ispras.microtesk.test.LabelManager
-
public final class LabelManager extends java.lang.Object
The role of theLabelManager
class is resolving references to labels that have the same names, but are defined in different blocks. It stores all labels defined by a sequence and their relative positions grouped by name. When it is required to perform a jump to a label with a specific name, it chooses the most suitable label depending on the block from which the jump is performed. Here are the rules according to which the choice is made:- If there is only one such label (no other choice), choose it.
- Choose a label defined in the current block, if there is such a label defined in the current block.
- Choose a label defined in the closest child, if there are such labels defined in child blocks.
- Choose a label defined in the closest parent, if there are such labels defined in parent blocks.
- Choose a label defined in the closest sibling.
LabelManager.TargetDistance
class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LabelManager.Target
TheLabelManager.Target
class stores information about the target the specified label points to.
-
Constructor Summary
Constructors Constructor Description LabelManager()
Constructs a new label manager that stores no information about labels.LabelManager(LabelManager other)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLabel(Label label, long address)
Adds information about a label to the table of label targets.void
addLabel(Label label, long address, int sequenceIndex)
Adds information about label in the specified collection to the table of label targets.void
reset()
Clears all labels.LabelManager.Target
resolve(Label referenceLabel)
Resolves a reference to a label having a specific name from a specific block and returns the most suitable target (label and its position).java.lang.String
toString()
-
-
-
Constructor Detail
-
LabelManager
public LabelManager()
Constructs a new label manager that stores no information about labels.
-
LabelManager
public LabelManager(LabelManager other)
-
-
Method Detail
-
addLabel
public void addLabel(Label label, long address)
Adds information about a label to the table of label targets.- Parameters:
label
- Label to be registered.address
- Address associated with the label.- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
addLabel
public void addLabel(Label label, long address, int sequenceIndex)
Adds information about label in the specified collection to the table of label targets.- Parameters:
label
- Label to be registered.address
- Address the label point to.sequenceIndex
- Index of the sequence.- Throws:
java.lang.IllegalArgumentException
- if thelabel
parameter isnull
.java.lang.IllegalArgumentException
- if an object in thelabels
collection is not a Label object.
-
resolve
public LabelManager.Target resolve(Label referenceLabel)
Resolves a reference to a label having a specific name from a specific block and returns the most suitable target (label and its position). The most suitable target is chosen depending on the reference position (see theLabelManager
class comment). If there are several equally possible choices (ambiguity) a warning message is printed.- Parameters:
referenceLabel
- A Label object that describes a reference to a label that has a specific name from a specific block.- Returns:
- The most suitable target (label and its position) for the given reference or
null
if no label having such name is found. - Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
reset
public void reset()
Clears all labels.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-