Class StepUntilElement


public class StepUntilElement extends ForListElement
Utility class: For-list Step until element.
  • Field Details

    • expr2

      Expression expr2
      The second expression.
    • expr3

      Expression expr3
      The third expression.
    • DELTA_SEQU

      private static int DELTA_SEQU
      Used to make deltaID unique.
  • Constructor Details

    • StepUntilElement

      public StepUntilElement(ForStatement forStatement, Expression expr1, Expression expr2, Expression expr3)
      Create a new StepUntilElement.
      Parameters:
      forStatement - the ForStatement
      expr1 - The first expression
      expr2 - The second expression
      expr3 - The third expression
    • StepUntilElement

      private StepUntilElement()
      Default constructor used by Attribute File I/O
  • Method Details

    • doChecking

      public void doChecking()
      Description copied from class: ForListElement
      Perform semantic checking.
      Overrides:
      doChecking in class ForListElement
    • edCode

      public String edCode(String classIdent, Type xType)
      Description copied from class: ForListElement
      Edit Java source code for this ForListElement.
      Overrides:
      edCode in class ForListElement
      Parameters:
      classIdent - Java class identifier
      xType - control variable's type
      Returns:
      the resulting Java source code for this ForListElement
    • isOptimisable

      public ForListElement isOptimisable()
      Description copied from class: ForListElement
      Checks if this ForListElement can be optimized.
      Overrides:
      isOptimisable in class ForListElement
      Returns:
      this ForListElement if it can be optimized
    • doSimplifiedJavaCoding

      public void doSimplifiedJavaCoding()
      Description copied from class: ForListElement
      Perform simplified JavaCoding.
      Overrides:
      doSimplifiedJavaCoding in class ForListElement
    • generalCase

      private void generalCase()

      ClassFile coding utility: generalCase.

      FOR controlVariable := expr1 STEP expr2 UNTIL expr3 DO statement;
      
      According to Simula Standard:
      
      		int/float/double DELTA; // Local
      
      		controlVariable = expr1();
      		DELTA = expr2();
      		while( sign(DELTA)*(controlVariable-expr3()) <= 0) {
      			STATEMENT();
      			DELTA = expr2();
      			controlVariable = controlVariable + DELTA;
      		}  // end while;
      
    • doSingleElementByteCoding

      public void doSingleElementByteCoding(CodeBuilder codeBuilder)

      ClassFile coding utility: doSingleElementByteCoding.

      FOR controlVariable := expr1 STEP expr2 UNTIL expr3 DO statement;
      
      
      int/float/double DELTA; // Local
      
      controlVariable = expr1();
      DELTA = expr2();
      while( sign(DELTA)/// (controlVariable - expr3() ) <= 0) {
      		STATEMENT();
      		DELTA = expr2();
      		controlVariable = controlVariable + DELTA;
      }  // end while;
      
      
        // controlVariable = expr1();
        aload_0
        aload_0
        invokevirtual #24                 // Method expr1:()I
        putfield      #12                 // Field controlVariable:I
      
      // DELTA = expr2();
        aload_0
        invokevirtual #26                 // Method expr2:()I
        istore_1	   // Local DELTA
      
      TST:
      // if(DELTA*(controlVariable-expr3()) > 0) goto END
        iload_1       // Local DELTA
        aload_0
        getfield      #12                 // Field controlVariable:I
        aload_0
        invokevirtual #30                 // Method expr3:()I
        isub
        imul
        ifle          END
      
      // STATEMENT
        aload_0
        invokevirtual #28                 // Method STATEMENT:()V
        
      // DELTA = expr2();
        aload_0
        invokevirtual #26                 // Method expr2:()I
        istore_1      // Local DELTA
        
      // controlVariable = controlVariable + DELTA;  
        aload_0
        dup
        getfield      #12                 // Field controlVariable:I
        iload_1       // Local DELTA
        iadd
        putfield      #12                 // Field controlVariable:I
      
        goto          TST
        
      END:  
      
      Overrides:
      doSingleElementByteCoding in class ForListElement
      Parameters:
      codeBuilder - the codeBuilder to use.
    • buildByteCode

      public void buildByteCode(CodeBuilder codeBuilder, VariableExpression controlVariable)
      Description copied from class: ForListElement
      Build byte code.
      Overrides:
      buildByteCode in class ForListElement
      Parameters:
      codeBuilder - the codeBuilder to use.
      controlVariable - the ForStatement's controlVariable.
    • toString

      public String toString()
      Overrides:
      toString in class ForListElement
    • writeObject

      public void writeObject(AttributeOutputStream oupt) throws IOException
      Description copied from class: SyntaxClass
      Write a SyntaxClass object to a AttributeOutputStream.
      Overrides:
      writeObject in class ForListElement
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static StepUntilElement readObject(AttributeInputStream inpt) throws IOException
      Read and return an object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the object read from the stream.
      Throws:
      IOException - if something went wrong.