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
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe possible conditions for IF, IF_ELSE, and WHILE statements.static enumThe kinds of statements. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToBlock(int pos, Statement s) Adds the statementsat positionposinthisBLOCK statement; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.voidassembleCall(String inst) Assembles inthisa CALL statement with root label(CALL, ?, inst)and no subtrees.voidAssembles inthisan IF statement with root label(IF, c, ?)and only subtree the BLOCKs; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.voidAssembles inthisan IF_ELSE statement with root label(IF_ELSE, c, ?)and as two subtrees the BLOCKss1ands2; the declaration notwithstanding, the dynamic type ofs1ands2must be the same as the dynamic type ofthis.voidAssembles inthisa WHILE statement with root label(WHILE, c, ?)and only subtree the BLOCKs; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.Disassembles CALL statementthisand returns the called instruction name as the value of the function.Disassembles IF statementthisinto its testCondition, which is returned as the value of the function, and its only subtree, the BLOCK statements; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.disassembleIfElse(Statement s1, Statement s2) Disassembles IF_ELSE statementthisinto its testCondition, which is returned as the value of the function, and its two subtrees, the BLOCK statementss1ands2; the declaration notwithstanding, the dynamic type ofs1ands2must be the same as the dynamic type ofthis.Disassembles WHILE statementthisinto its testCondition, which is returned as the value of the function, and its only subtree, the BLOCK statements; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.kind()Reports the kind of statementthisis.intReports the number of statements inthisBLOCK.removeFromBlock(int pos) Removes and returns the statement at positionposinthisBLOCK statement.Methods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Method Details
-
kind
Reports the kind of statementthisis.- Returns:
- the kind of this statement
- Ensures:
kind = [the kind of this statement]
-
addToBlock
Adds the statementsat positionposinthisBLOCK statement; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.- Parameters:
pos- the position at which to addss- theStatementto 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 positionposinthisBLOCK 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 inthisBLOCK.- Returns:
- the length of
thisBLOCK - Requires:
[this is a BLOCK statement]- Ensures:
lengthOfBlock = [the number of children of this]
-
assembleIf
Assembles inthisan IF statement with root label(IF, c, ?)and only subtree the BLOCKs; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.- Parameters:
c- theConditionof 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 statementthisinto its testCondition, which is returned as the value of the function, and its only subtree, the BLOCK statements; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.- Parameters:
s- the body of this IF statement- Returns:
- the
Conditionof this IF statement - Replaces:
s- Clears:
this- Requires:
[this is an IF statement]- Ensures:
#this = compose((IF, disassembleIf, ?), <s>)
-
assembleIfElse
Assembles inthisan IF_ELSE statement with root label(IF_ELSE, c, ?)and as two subtrees the BLOCKss1ands2; the declaration notwithstanding, the dynamic type ofs1ands2must be the same as the dynamic type ofthis.- Parameters:
c- theConditionof 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 statementthisinto its testCondition, which is returned as the value of the function, and its two subtrees, the BLOCK statementss1ands2; the declaration notwithstanding, the dynamic type ofs1ands2must 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
Conditionof 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 inthisa WHILE statement with root label(WHILE, c, ?)and only subtree the BLOCKs; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.- Parameters:
c- theConditionof 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 statementthisinto its testCondition, which is returned as the value of the function, and its only subtree, the BLOCK statements; the declaration notwithstanding, the dynamic type ofsmust be the same as the dynamic type ofthis.- Parameters:
s- the body of this WHILE statement- Returns:
- the
Conditionof this WHILE statement - Replaces:
s- Clears:
this- Requires:
[this is a WHILE statement]- Ensures:
#this = compose((WHILE, disassembleWhile, ?), <s>)
-
assembleCall
Assembles inthisa 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 statementthisand 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), <>)
-