Class CodeSemantics

java.lang.Object
de.jplag.semantics.CodeSemantics

public class CodeSemantics extends Object
Contains semantic information about a code snippet, in our case either a token or a statement.
  • Constructor Details

    • CodeSemantics

      public CodeSemantics()
      Creates new semantics with the following meaning: The code snippet may be removed, and its position relative to other code snippets may change. Example: An assignment to a local variable.
  • Method Details

    • createKeep

      public static CodeSemantics createKeep()
      Returns:
      new semantics with the following meaning: The code snippet may not be removed, and its position relative to other code snippets may change. Example: An attribute declaration.
    • createCritical

      public static CodeSemantics createCritical()
      Returns:
      new semantics with the following meaning: The code snippet may not be removed, and its position must stay invariant to other code snippets of the same type. Example: A method call which is guaranteed to not result in an exception.
    • createControl

      public static CodeSemantics createControl()
      Returns:
      new semantics with the following meaning: The code snippet may not be removed, and its position must stay invariant to all other code snippets. Example: A return statement.
    • createLoopBegin

      public static CodeSemantics createLoopBegin()
      Returns:
      new semantics with the following meaning: The code snippet may not be removed, and its position must stay invariant to all other code snippets, which also begins a bidirectional block. Example: The beginning of a while loop.
    • createLoopEnd

      public static CodeSemantics createLoopEnd()
      Returns:
      new semantics with the following meaning: The code snippet may not be removed, and its position must stay invariant to all other code snippets, which also ends a bidirectional block. Example: The end of a while loop.
    • keep

      public boolean keep()
      Returns:
      whether this code snippet must be kept.
    • markKeep

      public void markKeep()
      Mark this code snippet as having to be kept.
    • bidirectionalBlockDepthChange

      public int bidirectionalBlockDepthChange()
      Returns:
      the change this code snippet causes in the depth of bidirectional loops.
    • hasPartialPositionSignificance

      public boolean hasPartialPositionSignificance()
      Returns:
      whether this code snippet has partial position significance.
    • hasFullPositionSignificance

      public boolean hasFullPositionSignificance()
      Returns:
      whether this code snippet has full position significance.
    • markFullPositionSignificance

      public void markFullPositionSignificance()
      Mark this code snippet as having full position significance.
    • reads

      public Set<Variable> reads()
      Returns:
      an unmodifiable set of the variables which were (potentially) read from in this code snippet.
    • writes

      public Set<Variable> writes()
      Returns:
      an unmodifiable set of the variables which were (potentially) written to in this code snippet.
    • addRead

      public void addRead(Variable variable)
      Add a variable to the set of variables which were (potentially) read from in this code snippet.
      Parameters:
      variable - The variable which is added.
    • addWrite

      public void addWrite(Variable variable)
      Add a variable to the set of variables which were (potentially) written to in this code snippet.
      Parameters:
      variable - The variable which is added.
    • join

      public static CodeSemantics join(List<CodeSemantics> semanticsList)
      Create new joint semantics by joining a number of existing ones. It has the following properties:
      • keep is the disjunction of all keeps
      • position significance is the most significant
      • bidirectionalBlockDepthChange is the sum of all bidirectionalBlockDepthChanges
      • reads is the union of all reads
      • writes is the union of all writes
      Parameters:
      semanticsList - A list of the semantics which should be joined.
      Returns:
      New semantics which were created by joining the elements in the semanticsList.
    • toString

      public String toString()
      Overrides:
      toString in class Object