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) LabelThe end Label.private booleanTrue if this connection statement contains ConnectionWhenPart(s).(package private) VariableExpressionUtility Variable to hold the evaluated object-expression.The inspected variable's declaration.(package private) ExpressionThe inspected object.private StatementThe otherwise statement.private static intUtility to help generate unique identifiers to the inspected variable.Fields inherited from class SyntaxClass
CHECKED, lineNumber, OBJECT_SEQU -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDefault constructor used by Attribute File I/O(package private)ConnectionStatement(int line) Create a new ConnectionStatement. -
Method Summary
Modifier and TypeMethodDescriptionvoidbuildByteCode(CodeBuilder codeBuilder) Build Java ByteCode.voidPerform semantic checking.voidOutput Java code.static StringUtility to be used in when-partsvoidprint(int indent) Utility print method.voidUtility print syntax tree method.static ConnectionStatementRead and return a ConnectionStatement object.toString()voidWrite a SyntaxClass object to a AttributeOutputStream.Methods inherited from class Statement
expectStatementMethods inherited from class 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:SyntaxClassPerform semantic checking.
This must be redefined in every subclass.
- Overrides:
doCheckingin classSyntaxClass
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClassOutput Java code.- Overrides:
doJavaCodingin classStatement
-
buildByteCode
Description copied from class:StatementBuild Java ByteCode.- Overrides:
buildByteCodein classStatement- Parameters:
codeBuilder- the codeBuilder to use.
-
printTree
Description copied from class:SyntaxClassUtility print syntax tree method.- Overrides:
printTreein classSyntaxClass- Parameters:
indent- number of spaces leading the lineshead- the head of the tree.
-
print
public void print(int indent) Description copied from class:SyntaxClassUtility print method.- Overrides:
printin classSyntaxClass- Parameters:
indent- number of spaces leading the line
-
toString
-
writeObject
Description copied from class:SyntaxClassWrite a SyntaxClass object to a AttributeOutputStream.- Overrides:
writeObjectin 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.
-