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
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
Utility class to hold the single do-part.private final class
Utility class to hold a when-part. -
Field Summary
Modifier and TypeFieldDescriptionprivate final Vector
<ConnectionStatement.DoPart> The connection parts.private final boolean
True if this connection statement contains WhenPart(s).private final VariableExpression
Utility Variable to hold the evaluated object-expression.private final SimpleVariableDeclaration
The inspected variable's declaration.private final Expression
The inspected object.private final 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
lineNumber
-
Constructor Summary
-
Method Summary
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, toJavaCode
-
Field Details
-
objectExpression
The inspected object. -
inspectedVariable
Utility Variable to hold the evaluated object-expression. -
inspectVariableDeclaration
The inspected variable's declaration. -
connectionPart
The connection parts. A DoPart or a list of WhenParts. -
otherwise
The otherwise statement. -
hasWhenPart
private final boolean hasWhenPartTrue if this connection statement contains WhenPart(s). -
SEQU
private static int SEQUUtility 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 classSyntaxClass
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClass
Output Java code.- Overrides:
doJavaCoding
in classStatement
-
printTree
public void printTree(int indent) Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- 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 classSyntaxClass
- Parameters:
indent
- number of spaces leading the line
-
toString
-