Module Simula

Class ConnectionStatement


public final class ConnectionStatement extends Statement
Connection Statement.
 
 Simula Standard: 4.8 Connection statement

        connection-statement
                        = INSPECT object-expression when-clause { when-clause } [ otherwise-clause ]
                        | INSPECT object-expression DO statement [ otherwise-clause ]

                        when-clause = WHEN class-identifier DO statement

                        otherwise-clause = OTHERWISE statement


 The connection statement is implemented using Java's instanceof operator and the
 if statement. For example, the connection statement:
 
         inspect x do image:-t;
         
 Where 'x' is declared as a reference to an ImageFile, is compiled to:
 
         if(x!=null) x.image=t;
         
 Other examples that also use 'ref(Imagefile) x' may be:
 
      1) inspect x do image:-t otherwise t:-notext;
      
      2) inspect x
            when infile do t:-intext(12)
            when outfile do outtext(t);
            
      3) inspect x
            when infile do t:-intext(12)
            when outfile do outtext(t)
         otherwise t:-notext;
 
 These examples are compiled to:
 
      1) if(x!=null) x.image=t; else t=null;
      
      2) if(x instanceof RTS_Infile) t=((RTS_Infile)x).intext(12);
         else if(x instanceof RTS_Outfile) ((RTS_Outfile)x).outtext(t);
          
      3) if(x instanceof RTS_Infile) t=((RTS_Infile)x).intext(12);
         else if(x instanceof RTS_Outfile) ((RTS_Outfile)x).outtext(t);
         else t=null;
 
 
Link to GitHub: Source File.
Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • objectExpression

      private final Expression objectExpression
      The inspected object.
    • inspectedVariable

      private final VariableExpression inspectedVariable
      Utility Variable to hold the evaluated object-expression.
    • inspectVariableDeclaration

      private final SimpleVariableDeclaration inspectVariableDeclaration
      The inspected variable's declaration.
    • connectionPart

      private final Vector<ConnectionStatement.DoPart> connectionPart
      The connection parts. A DoPart or a list of WhenParts.
    • otherwise

      private final Statement otherwise
      The otherwise statement.
    • hasWhenPart

      private final boolean hasWhenPart
      True if this connection statement contains WhenPart(s).
    • SEQU

      private static int SEQU
      Utility to help generate unique identifiers to the inspected variable.
  • Constructor Details

    • ConnectionStatement

      ConnectionStatement(int line)
      Create a new ConnectionStatement.

      Pre-Condition: INSPECT is already read.

      Parameters:
      line - the source line number
  • Method Details

    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass
      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • doJavaCoding

      public void doJavaCoding()
      Description copied from class: SyntaxClass
      Output Java code.
      Overrides:
      doJavaCoding in class Statement
    • printTree

      public void printTree(int indent)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
    • print

      public void print(int indent)
      Description copied from class: SyntaxClass
      Utility print method.
      Overrides:
      print in class SyntaxClass
      Parameters:
      indent - number of spaces leading the line
    • toString

      public String toString()
      Overrides:
      toString in class Object