Statements

Overview

BMM provides meta-model elements for defining the body of a routine, consisting of statements. This facility is not needed for achieving the original purpose of BMM, i.e. a computable in-memory representation of a model at the interface level (classes, types and signatures), rather it provides a basis for representing program logic, such as function definitions.

BMM statements are formalised using the classes BMM_STATEMENT_ITEM, BMM_STATEMENT_BLOCK and BMM_STATEMENT and various recognisable descendant types, as shown in the UML view below.

LANG bmm.statement
Figure 1. Features for routine definition

The use of the three-class hierarchy pattern allows a Routine body to be a simple statement or a block, containing statements and/or more blocks. The class BMM_STATEMENT is abstract, allowing specific statement meta-models to be developed whose 'statement' meta-types inherit from this class. A number of common types are included by default, and are described below.

This facility is primarily provided to support the definition of higher-level languages by embedding them in the outer BMM meta-model.

Assignment

A BMM assignment is the same concept as found in most frame-based programming languages, and provides a meta-model to represent a writable target (variable or property) being assigned to from a source, which is any expression of the same evaluation type. Type checking is thus based on a comparison of definition.type of the target and eval_type() of the source.

The following example shows a simple assignment in the definition of the function position.

class Simple_bank_account

feature -- Definitions

    overdraft_limit: Decimal = 250;

feature -- State

    balance: Decimal;

feature -- Interface

    position: Decimal {
        Result := balance + overdraft_limit
    }

invariant
    Solvent: position >= 0.0

The BMM meta-model for this statement is shown below.

bmm assignment
Figure 2. Assignment to function Result

Procedure Call

A procedure call is represented in BMM by the meta-type BMM_PROCEDURE_CALL, which refers to an instance of EL_PROCEDURE_AGENT, the same way that a function call is represented in terms of an EL_FUNCTION_AGENT. In the following example, the procedure put() is called from the deposit() and withdraw() functions in the class Account_access.

class Simple_bank_account

feature -- Modification

    put (val: Decimal)
        precondition
            valid_amount: val + overdraft_limit >= 0.0
    {
        balance := balance + val
    }

class Account_access {

feature -- Command

    deposit (v: Decimal; ac: Simple_bank_account)
        pre_condition
            valid_amount: v > 0.0
    {
        ac.put (v);
    }

    withdraw (v: Decimal; ac: Simple_bank_account)
        pre_condition
            valid_amount: ac.overdraft_limit - v >= 0.0
    {
        ac.put (-v);
    }

The BMM meta-model for the call is shown below.

bmm procedure call
Figure 3. Procedure call

Action Tables

The BMM statement package includes the meta-classes BMM_ACTION_TABLE and BMM_CONDITIONAL_ACTION, which together provide a way of representing a decision table whose outputs are statements (rather than values, as in the case of the related Expression meta-classes EL_DECISION_TABLE and EL_CONDITIONAL_EXPRESSION). An action table corresponds closely to the standard constructs 'if/then/elseif' and the case statement.

The following example shows a typical instance of the BMM Action table meta-type, within a procedure that generates appropriate alerts or alarms based on patient vital signs.

    check_vital_signs
        if systolic_pressure.in_range ([critical_high])
            raise_alarm ([emergency])

        elseif systolic_pressure.in_range ([high]) and oxygen_sat.in_range([low])
            call_staff

Assertions

The BMM statement model includes a statement meta-type to represent the notion of an assertion as a statement, typically expressed in syntax such as assert (<boolean expression>). This kind of statement is understood as an executable instruction to check that the condition is true, and if not, to generate an exception of the appropriate type, assuming exceptions are available.

Class Definitions

BMM_STATEMENT_ITEM Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_STATEMENT_ITEM (abstract)

Description

Abstract parent of statement types representing a locally defined routine body.

Inherit

BMM_ROUTINE_BODY

BMM_STATEMENT_ITEM (abstract)

Abstract parent of statement types representing a locally defined routine body.

Inherits: BMM_ROUTINE_BODY

{
    "name": "BMM_STATEMENT_ITEM",
    "documentation": "Abstract parent of statement types representing a locally defined routine body.",
    "is_abstract": true,
    "ancestors": [
        "BMM_ROUTINE_BODY"
    ]
}
bmm statement item

BMM_STATEMENT_BLOCK Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_STATEMENT_BLOCK

Description

A statement 'block' corresponding to the programming language concept of the same name. May be used to establish scope in specific languages.

Inherit

BMM_STATEMENT_ITEM

Attributes

Signature

Meaning

0..1

items: List <BMM_STATEMENT_ITEM>

Child blocks of the current block.

BMM_STATEMENT_BLOCK

A statement 'block' corresponding to the programming language concept of the same name. May be used to establish scope in specific languages.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM

Attributes

items: List <BMM_STATEMENT_ITEM> [0..1]

Child blocks of the current block.

{
    "name": "BMM_STATEMENT_BLOCK",
    "documentation": "A statement 'block' corresponding to the programming language concept of the same name. May be used to establish scope in specific languages.",
    "ancestors": [
        "BMM_STATEMENT_ITEM"
    ],
    "properties": {
        "items": {
            "_type": "P_BMM_CONTAINER_PROPERTY",
            "name": "items",
            "documentation": "Child blocks of the current block.",
            "type_def": {
                "container_type": "List",
                "type": "BMM_STATEMENT_ITEM"
            },
            "cardinality": {
                "lower": 0,
                "upper_unbounded": true
            }
        }
    }
}
bmm statement block

BMM_STATEMENT Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_STATEMENT (abstract)

Description

Abstract parent of 'statement' types that may be defined to implement BMM Routines.

Inherit

BMM_STATEMENT_ITEM

BMM_STATEMENT (abstract)

Abstract parent of 'statement' types that may be defined to implement BMM Routines.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM

{
    "name": "BMM_STATEMENT",
    "documentation": "Abstract parent of 'statement' types that may be defined to implement BMM Routines.",
    "is_abstract": true,
    "ancestors": [
        "BMM_STATEMENT_ITEM"
    ]
}
bmm statement

BMM_SIMPLE_STATEMENT Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_SIMPLE_STATEMENT (abstract)

Description

Simple statement, i.e. statement with one logical element - a single expression, procedure call etc.

Inherit

BMM_STATEMENT

BMM_SIMPLE_STATEMENT (abstract)

Simple statement, i.e. statement with one logical element - a single expression, procedure call etc.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM, BMM_STATEMENT

{
    "name": "BMM_SIMPLE_STATEMENT",
    "documentation": "Simple statement, i.e. statement with one logical element - a single expression, procedure call etc.",
    "is_abstract": true,
    "ancestors": [
        "BMM_STATEMENT"
    ]
}
bmm simple statement

BMM_PROCEDURE_CALL Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_PROCEDURE_CALL

Description

A call made on a closed procedure agent.

Inherit

EL_AGENT_CALL, BMM_SIMPLE_STATEMENT

Attributes

Signature

Meaning

1..1
(redefined)

agent: EL_PROCEDURE_AGENT

The procedure agent being called.

BMM_PROCEDURE_CALL

A call made on a closed procedure agent.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM, BMM_STATEMENT, EL_AGENT_CALL, BMM_SIMPLE_STATEMENT

Attributes

agent: EL_PROCEDURE_AGENT [1..1]

The procedure agent being called.

Invariants

Inv_valid_call: agent.is_callable()
Inherited from EL_AGENT_CALL

{
    "name": "BMM_PROCEDURE_CALL",
    "documentation": "A call made on a closed procedure agent.",
    "ancestors": [
        "EL_AGENT_CALL",
        "BMM_SIMPLE_STATEMENT"
    ],
    "properties": {
        "agent": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "agent",
            "documentation": "The procedure agent being called.",
            "is_mandatory": true,
            "type": "EL_PROCEDURE_AGENT"
        }
    }
}
bmm procedure call

BMM_ASSIGNMENT Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_ASSIGNMENT

Description

Statement type representing an assignment from a value-generating source to a writable entity, i.e. a variable reference or property.

Inherit

BMM_SIMPLE_STATEMENT

Attributes

Signature

Meaning

1..1

target: EL_INSTANTIABLE_REF

The target variable on the notional left-hand side of this assignment.

1..1

source: EL_EXPRESSION

Source right hand side) of the assignment.

BMM_ASSIGNMENT

Statement type representing an assignment from a value-generating source to a writable entity, i.e. a variable reference or property.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM, BMM_STATEMENT, BMM_SIMPLE_STATEMENT

Attributes

target: EL_INSTANTIABLE_REF [1..1]

The target variable on the notional left-hand side of this assignment.

source: EL_EXPRESSION [1..1]

Source right hand side) of the assignment.

{
    "name": "BMM_ASSIGNMENT",
    "documentation": "Statement type representing an assignment from a value-generating source to a writable entity, i.e. a variable reference or property.",
    "ancestors": [
        "BMM_SIMPLE_STATEMENT"
    ],
    "properties": {
        "target": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "target",
            "documentation": "The target variable on the notional left-hand side of this assignment.",
            "is_mandatory": true,
            "type": "EL_INSTANTIABLE_REF"
        },
        "source": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "source",
            "documentation": "Source right hand side) of the assignment.",
            "is_mandatory": true,
            "type": "EL_EXPRESSION"
        }
    }
}
bmm assignment

BMM_ASSERTION Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_ASSERTION

Description

A statement that asserts the truth of its expression. If not, generates an exception (depending on run-time settings).

May be rendered in syntax as assert condition or similar.

Inherit

BMM_SIMPLE_STATEMENT

Attributes

Signature

Meaning

1..1

expression: EL_BOOLEAN_EXPRESSION

0..1

tag: `String `

Optional tag, typically used to designate design intention of the assertion, e.g. "Inv_all_members_valid".

BMM_ASSERTION

A statement that asserts the truth of its expression. If not, generates an exception (depending on run-time settings).

May be rendered in syntax as assert condition or similar.

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM, BMM_STATEMENT, BMM_SIMPLE_STATEMENT

Attributes

expression: EL_BOOLEAN_EXPRESSION [1..1]

tag: `String ` [0..1]

Optional tag, typically used to designate design intention of the assertion, e.g. "Inv_all_members_valid".

{
    "name": "BMM_ASSERTION",
    "documentation": "A statement that asserts the truth of its expression. If not, generates an exception (depending on run-time settings).\n\nMay be rendered in syntax as `assert condition` or similar.",
    "ancestors": [
        "BMM_SIMPLE_STATEMENT"
    ],
    "properties": {
        "expression": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "expression",
            "is_mandatory": true,
            "type": "EL_BOOLEAN_EXPRESSION"
        },
        "tag": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "tag",
            "documentation": "Optional tag, typically used to designate design intention of the assertion, e.g. `\"Inv_all_members_valid\"`.",
            "type": "String"
        }
    }
}
bmm assertion

BMM_ACTION_TABLE Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_ACTION_TABLE

Description

Multi-branch conditional statement structure

Inherit

BMM_STATEMENT

Attributes

Signature

Meaning

1..1

items: List <BMM_CONDITIONAL_ACTION>

Decision branches.

BMM_ACTION_TABLE

Multi-branch conditional statement structure

Inherits: BMM_ROUTINE_BODY, BMM_STATEMENT_ITEM, BMM_STATEMENT

Attributes

items: List <BMM_CONDITIONAL_ACTION> [1..1]

Decision branches.

{
    "name": "BMM_ACTION_TABLE",
    "documentation": "Multi-branch conditional statement structure",
    "ancestors": [
        "BMM_STATEMENT"
    ],
    "properties": {
        "items": {
            "_type": "P_BMM_CONTAINER_PROPERTY",
            "name": "items",
            "documentation": "Decision branches.",
            "is_mandatory": true,
            "type_def": {
                "container_type": "List",
                "type": "BMM_CONDITIONAL_ACTION"
            },
            "cardinality": {
                "lower": 1,
                "upper_unbounded": true
            }
        }
    }
}
bmm action table

BMM_CONDITIONAL_ACTION Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_CONDITIONAL_ACTION

Description

Conditional, or 'gated' statement, consisting of a Boolean-returning condition and the target statement.

Attributes

Signature

Meaning

1..1

condition: EL_BOOLEAN_EXPRESSION

The gate condition for the target statement.

1..1

statement: BMM_STATEMENT_ITEM

Target statement.

BMM_CONDITIONAL_ACTION

Conditional, or 'gated' statement, consisting of a Boolean-returning condition and the target statement.

Attributes

condition: EL_BOOLEAN_EXPRESSION [1..1]

The gate condition for the target statement.

statement: BMM_STATEMENT_ITEM [1..1]

Target statement.

{
    "name": "BMM_CONDITIONAL_ACTION",
    "documentation": "Conditional, or 'gated' statement, consisting of a Boolean-returning `_condition_` and the target `_statement_`.",
    "properties": {
        "condition": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "condition",
            "documentation": "The gate condition for the target statement.",
            "is_mandatory": true,
            "type": "EL_BOOLEAN_EXPRESSION"
        },
        "statement": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "statement",
            "documentation": "Target statement.",
            "is_mandatory": true,
            "type": "BMM_STATEMENT_ITEM"
        }
    }
}
bmm conditional action