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

      Expression objectExpression
      The inspected object.
    • inspectedVariable

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

      public InspectVariableDeclaration inspectVariableDeclaration
      The inspected variable's declaration.
    • connectionPart

      private ObjectList<ConnectionDoPart> connectionPart
      The connection parts. A ConnectionDoPart or a list of WhenParts.
    • otherwise

      private Statement otherwise
      The otherwise statement.
    • hasWhenPart

      private boolean hasWhenPart
      True if this connection statement contains ConnectionWhenPart(s).
    • SEQUX

      private static int SEQUX
      Utility to help generate unique identifiers to the inspected variable.
    • endLabel

      Label endLabel
      The end Label.
  • Constructor Details

    • ConnectionStatement

      ConnectionStatement(int line)

      Create a new ConnectionStatement.

      Pre-Condition: INSPECT is already read.

      Parameters:
      line - the source line number
    • ConnectionStatement

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

    • getUniqueConnID

      public static String getUniqueConnID()
      Utility to be used in when-parts
      Returns:
      a unique identifier
    • 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
    • buildByteCode

      public void buildByteCode(CodeBuilder codeBuilder)
      Description copied from class: Statement
      Build Java ByteCode.
      Overrides:
      buildByteCode in class Statement
      Parameters:
      codeBuilder - the codeBuilder to use.
    • printTree

      public void printTree(int indent, Object head)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
      head - the head of the tree.
    • 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
    • writeObject

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

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