Class LabelManager


  • public final class LabelManager
    extends java.lang.Object
    The role of the LabelManager 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:
    1. If there is only one such label (no other choice), choose it.
    2. Choose a label defined in the current block, if there is such a label defined in the current block.
    3. Choose a label defined in the closest child, if there are such labels defined in child blocks.
    4. Choose a label defined in the closest parent, if there are such labels defined in parent blocks.
    5. Choose a label defined in the closest sibling.
    Note: Labels that have different reference numbers are considered different. A reference number is a way to distinguish labels with same names. This happens when some subsequences are created using the same template representation (e.g. by instantiating the same preparator). For more implementation details, see the LabelManager.TargetDistance class.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LabelManager.Target
      The LabelManager.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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LabelManager

        public LabelManager()
        Constructs a new label manager that stores no information about labels.
    • 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 is null.
      • 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 the label parameter is null.
        java.lang.IllegalArgumentException - if an object in the labels 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 the LabelManager 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 is null.
      • reset

        public void reset()
        Clears all labels.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object