Class ConnectionStatement
java.lang.Object
simula.compiler.syntaxClass.SyntaxClass
simula.compiler.syntaxClass.statement.Statement
simula.compiler.syntaxClass.statement.ConnectionStatement
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 Summary
FieldsModifier and TypeFieldDescriptionprivate ObjectList
<ConnectionDoPart> The connection parts.(package private) Label
The end Label.private boolean
True if this connection statement contains ConnectionWhenPart(s).(package private) VariableExpression
Utility Variable to hold the evaluated object-expression.The inspected variable's declaration.(package private) Expression
The inspected object.private Statement
The otherwise statement.private static int
Utility to help generate unique identifiers to the inspected variable.Fields inherited from class simula.compiler.syntaxClass.SyntaxClass
CHECKED, lineNumber, OBJECT_SEQU
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Default constructor used by Attribute File I/O(package private)
ConnectionStatement
(int line) Create a new ConnectionStatement. -
Method Summary
Modifier and TypeMethodDescriptionvoid
buildByteCode
(CodeBuilder codeBuilder) Build Java ByteCode.void
Perform semantic checking.void
Output Java code.static String
Utility to be used in when-partsvoid
print
(int indent) Utility print method.void
Utility print syntax tree method.static ConnectionStatement
Read and return a ConnectionStatement object.toString()
void
Write a SyntaxClass object to a AttributeOutputStream.Methods inherited from class simula.compiler.syntaxClass.statement.Statement
expectStatement
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, doDeclarationCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, SET_SEMANTICS_CHECKED, setLineNumber, toJavaCode
-
Field Details
-
objectExpression
Expression objectExpressionThe inspected object. -
inspectedVariable
VariableExpression inspectedVariableUtility Variable to hold the evaluated object-expression. -
inspectVariableDeclaration
The inspected variable's declaration. -
connectionPart
The connection parts. A ConnectionDoPart or a list of WhenParts. -
otherwise
The otherwise statement. -
hasWhenPart
private boolean hasWhenPartTrue if this connection statement contains ConnectionWhenPart(s). -
SEQUX
private static int SEQUXUtility to help generate unique identifiers to the inspected variable. -
endLabel
Label endLabelThe 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
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 classSyntaxClass
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClass
Output Java code.- Overrides:
doJavaCoding
in classStatement
-
buildByteCode
Description copied from class:Statement
Build Java ByteCode.- Overrides:
buildByteCode
in classStatement
- Parameters:
codeBuilder
- the codeBuilder to use.
-
printTree
Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the lineshead
- the head of the tree.
-
print
public void print(int indent) Description copied from class:SyntaxClass
Utility print method.- Overrides:
print
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the line
-
toString
-
writeObject
Description copied from class:SyntaxClass
Write a SyntaxClass object to a AttributeOutputStream.- Overrides:
writeObject
in classSyntaxClass
- Parameters:
oupt
- the AttributeOutputStream to write to.- Throws:
IOException
- if something went wrong.
-
readObject
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.
-