Package components.statement
Interface StatementKernel
- All Known Subinterfaces:
Statement
- All Known Implementing Classes:
Statement1
,StatementSecondary
Statement kernel component with kernel methods. (Note: by package-wide
convention, all references are non-null.)
- Mathematical Subtypes:
IDENTIFIER is string of character exemplar id constraint [id starts with a letter 'a'-'z', 'A'-'Z'] and [id contains only letters, digits '0'-'9', and '-'] and [id is not one of the keywords or conditions in the BL language] STATEMENT_LABEL is ( kind: Kind, test: Condition, call: IDENTIFIER ) exemplar sl constraint [if sl.kind = BLOCK then sl.test and sl.call are irrelevant] and [if sl.kind = IF or sl.kind = IF_ELSE or sl.kind = WHILE then sl.call is irrelevant] and [if sl.kind = CALL then sl.test is irrelevant] STATEMENT_MODEL is tree of STATEMENT_LABEL exemplar s constraint |s| > 0 and [BLOCK can have 0 or more children, but not another BLOCK as a child] and [IF must have exactly one BLOCK child] and [IF_ELSE must have exactly two BLOCK children] and [WHILE must have exactly one BLOCK child] and [CALL must have no children (must be a leaf)]
- Mathematical Model (abstract value and abstract invariant of this):
type StatementKernel is modeled by STATEMENT_MODEL
- Constructor(s) (initial abstract value(s) of this):
(): ensures this = compose((BLOCK, ?, ?), <>)
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
The possible conditions for IF, IF_ELSE, and WHILE statements.static enum
The kinds of statements. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToBlock
(int pos, Statement s) Adds the statements
at positionpos
inthis
BLOCK statement; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.void
assembleCall
(String inst) Assembles inthis
a CALL statement with root label(CALL, ?, inst)
and no subtrees.void
Assembles inthis
an IF statement with root label(IF, c, ?)
and only subtree the BLOCKs
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.void
Assembles inthis
an IF_ELSE statement with root label(IF_ELSE, c, ?)
and as two subtrees the BLOCKss1
ands2
; the declaration notwithstanding, the dynamic type ofs1
ands2
must be the same as the dynamic type ofthis
.void
Assembles inthis
a WHILE statement with root label(WHILE, c, ?)
and only subtree the BLOCKs
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.Disassembles CALL statementthis
and returns the called instruction name as the value of the function.Disassembles IF statementthis
into its testCondition
, which is returned as the value of the function, and its only subtree, the BLOCK statements
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.disassembleIfElse
(Statement s1, Statement s2) Disassembles IF_ELSE statementthis
into its testCondition
, which is returned as the value of the function, and its two subtrees, the BLOCK statementss1
ands2
; the declaration notwithstanding, the dynamic type ofs1
ands2
must be the same as the dynamic type ofthis
.Disassembles WHILE statementthis
into its testCondition
, which is returned as the value of the function, and its only subtree, the BLOCK statements
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.kind()
Reports the kind of statementthis
is.int
Reports the number of statements inthis
BLOCK.removeFromBlock
(int pos) Removes and returns the statement at positionpos
inthis
BLOCK statement.Methods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Method Details
-
kind
Reports the kind of statementthis
is.- Returns:
- the kind of this statement
- Ensures:
kind = [the kind of this statement]
-
addToBlock
Adds the statements
at positionpos
inthis
BLOCK statement; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.- Parameters:
pos
- the position at which to adds
s
- theStatement
to add- Updates:
this
- Clears:
s
- Requires:
[this is a BLOCK statement] and [s is not a BLOCK statement] and 0 <= pos <= [length of this BLOCK]
- Ensures:
this = [#this with child #s inserted at position pos]
-
removeFromBlock
Removes and returns the statement at positionpos
inthis
BLOCK statement.- Parameters:
pos
- the position of the child to remove- Returns:
- the child at position pos in
this
- Updates:
this
- Requires:
[this is a BLOCK statement] and 0 <= pos < [length of this BLOCK]
- Ensures:
this = [#this with child at position pos removed and returned as result]
-
lengthOfBlock
int lengthOfBlock()Reports the number of statements inthis
BLOCK.- Returns:
- the length of
this
BLOCK - Requires:
[this is a BLOCK statement]
- Ensures:
lengthOfBlock = [the number of children of this]
-
assembleIf
Assembles inthis
an IF statement with root label(IF, c, ?)
and only subtree the BLOCKs
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.- Parameters:
c
- theCondition
of the IF statements
- the body of the IF statement- Replaces:
this
- Clears:
s
- Requires:
[s is a BLOCK statement]
- Ensures:
this = compose((IF, c, ?), <#s>)
-
disassembleIf
Disassembles IF statementthis
into its testCondition
, which is returned as the value of the function, and its only subtree, the BLOCK statements
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.- Parameters:
s
- the body of this IF statement- Returns:
- the
Condition
of this IF statement - Replaces:
s
- Clears:
this
- Requires:
[this is an IF statement]
- Ensures:
#this = compose((IF, disassembleIf, ?), <s>)
-
assembleIfElse
Assembles inthis
an IF_ELSE statement with root label(IF_ELSE, c, ?)
and as two subtrees the BLOCKss1
ands2
; the declaration notwithstanding, the dynamic type ofs1
ands2
must be the same as the dynamic type ofthis
.- Parameters:
c
- theCondition
of the IF_ELSE statements1
- the body of the "then" part of the IF_ELSE statements2
- the body of the "else" part of the IF_ELSE statement- Replaces:
this
- Clears:
s1, s2
- Requires:
[s1 is a BLOCK statement] and [s2 is a BLOCK statement]
- Ensures:
this = compose((IF_ELSE, c, ?), <#s1, #s2>)
-
disassembleIfElse
Disassembles IF_ELSE statementthis
into its testCondition
, which is returned as the value of the function, and its two subtrees, the BLOCK statementss1
ands2
; the declaration notwithstanding, the dynamic type ofs1
ands2
must be the same as the dynamic type ofthis
.- Parameters:
s1
- the body of the "then" part of the IF_ELSE statements2
- the body of the "else" part of the IF_ELSE statement- Returns:
- the
Condition
of this IF_ELSE statement - Replaces:
s1, s2
- Clears:
this
- Requires:
[this is an IF_ELSE statement]
- Ensures:
#this = compose((IF_ELSE, disassembleIfElse, ?), <s1, s2>)
-
assembleWhile
Assembles inthis
a WHILE statement with root label(WHILE, c, ?)
and only subtree the BLOCKs
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.- Parameters:
c
- theCondition
of the WHILE statements
- the body of the WHILE statement- Replaces:
this
- Clears:
s
- Requires:
[s is a BLOCK statement]
- Ensures:
this = compose((WHILE, c, ?), <#s>)
-
disassembleWhile
Disassembles WHILE statementthis
into its testCondition
, which is returned as the value of the function, and its only subtree, the BLOCK statements
; the declaration notwithstanding, the dynamic type ofs
must be the same as the dynamic type ofthis
.- Parameters:
s
- the body of this WHILE statement- Returns:
- the
Condition
of this WHILE statement - Replaces:
s
- Clears:
this
- Requires:
[this is a WHILE statement]
- Ensures:
#this = compose((WHILE, disassembleWhile, ?), <s>)
-
assembleCall
Assembles inthis
a CALL statement with root label(CALL, ?, inst)
and no subtrees.- Parameters:
inst
- the name of the instruction of the CALL statement- Replaces:
this
- Requires:
[inst is a valid IDENTIFIER]
- Ensures:
this = compose((CALL, ?, inst), <>)
-
disassembleCall
Disassembles CALL statementthis
and returns the called instruction name as the value of the function.- Returns:
- the name of the instruction of this CALL statement
- Clears:
this
- Requires:
[this is a CALL statement]
- Ensures:
#this = compose((CALL, ?, disassembleCall), <>)
-