Class VariableTracker<T>


  • public final class VariableTracker<T>
    extends java.lang.Object
    Tracks information related to HTL variables, at different levels of the compiler.
    • Constructor Summary

      Constructors 
      Constructor Description
      VariableTracker()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get​(java.lang.String name)
      Get the data associated with the given variable.
      java.util.List<T> getAll​(java.lang.String name)
      Get an immutable view of all the data items associated with the specified variable.
      int getOccurrenceCount​(java.lang.String name)
      Get how many times a variable was declared in the current scope.
      boolean isDeclared​(java.lang.String name)
      Checks if the variable identified by name is tracked by this tracker or not.
      boolean isEmpty()
      Checks if the declaration stack is empty.
      boolean isInScope​(java.lang.String name)
      Check whether a variable was declared and is visible in the current scope.
      java.util.Map.Entry<java.lang.String,​T> peek()
      Peeks at the top of the declaration stack.
      java.lang.String popVariable()
      Pops a variable from this tracker.
      void pushVariable​(java.lang.String name, T data)
      Pushes a variable to this tracker.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VariableTracker

        public VariableTracker()
    • Method Detail

      • isDeclared

        public boolean isDeclared​(java.lang.String name)
        Checks if the variable identified by name is tracked by this tracker or not.
        Parameters:
        name - the name of the variable
        Returns:
        true if the variable is declared, false otherwise
      • pushVariable

        public void pushVariable​(java.lang.String name,
                                 T data)
        Pushes a variable to this tracker. Call this method whenever a variable is declared.
        Parameters:
        name - the name of the variable
        data - the data associated with the variable
      • popVariable

        public java.lang.String popVariable()
        Pops a variable from this tracker. Call this method whenever a variable goes out of scope.
        Returns:
        the name of the popped variable
        Throws:
        java.util.NoSuchElementException - if there are no declared variables in the scope
      • peek

        public java.util.Map.Entry<java.lang.String,​T> peek()
        Peeks at the top of the declaration stack.
        Returns:
        the most recently declared variable and its associated data
        Throws:
        java.util.NoSuchElementException - if there are no variables in scope
      • isEmpty

        public boolean isEmpty()
        Checks if the declaration stack is empty.
        Returns:
        true if the stack is empty, false otherwise
      • get

        public T get​(java.lang.String name)
        Get the data associated with the given variable.
        Parameters:
        name - the name of the variable
        Returns:
        the associated data or null if that variable is not in scope
      • isInScope

        public boolean isInScope​(java.lang.String name)
        Check whether a variable was declared and is visible in the current scope.
        Parameters:
        name - the name of the variable
        Returns:
        true if the variable is visible in the current scope, false otherwise
      • getAll

        public java.util.List<T> getAll​(java.lang.String name)
        Get an immutable view of all the data items associated with the specified variable.
        Parameters:
        name - the name of the variable
        Returns:
        a list of all the data associated with this variable name. If the variable is not declared in the current scope then that list will be empty. Otherwise it will contain all the data associated for the current scope starting with the data associated at the topmost scope and ending with the most recently associated data
      • getOccurrenceCount

        public int getOccurrenceCount​(java.lang.String name)
        Get how many times a variable was declared in the current scope.
        Parameters:
        name - the name of the variable
        Returns:
        the number of declarations for a variable in the current scope