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 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.

Variable Declaration

Writable variables are declared using a variable declaration (BMM_DECLARATION). This may be understood as the creation of an instance of the relevant meta-type, i.e. of EL_WRITABLE_VARIABLE, that will represent the variable for all subsequent uses in the program text.

Assignment

A BMM assignment is the same concept as found in most frame-based programming languages, and provides a meta-model entity 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. The effect of a procedure call is to cause an external action to be performed, such as display something on the screen, write to a database etc.

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 instance structure 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 the logic of a BMM Action table meta-type, within a procedure that generates appropriate alerts or alarms based on patient vital signs, using the standard if/then/else constrol structure.

    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
        end
    end

In a functional style syntax that directly mirrors the Action table meta-model, this may be written as:

    check_vital_signs
        ============================================================================
        systolic_pressure.in_range ([critical_high]):     raise_alarm ([emergency]),
        ----------------------------------------------------------------------------
        systolic_pressure.in_range ([high]) and
        oxygen_sat.in_range([low]):                       call_staff
        ============================================================================
    end

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_DECLARATION Class

  • Definition

  • Effective

  • BMM

  • UML

Class

BMM_DECLARATION (abstract)

Description

Meta-type of BMM declared model elements. A declaration is a an element of a model specified by an author within a model definition within a context, which defines the scope of the element. Thus, a class definition and its property and routine definitions are model elements, but Types are not, since they are derived from model elements.

Attributes

Signature

Meaning

1..1

name: `String `

Name of this model element.

0..1

documentation: Hash <String ,Any >

Optional documentation of this element, as a keyed list.

It is strongly recommended to use the following key /type combinations for the relevant purposes:

  • "purpose": String

  • "keywords": List<String>

  • "use": String

  • "misuse": String

  • "references": String

Other keys and value types may be freely added.

1..1

scope: BMM_DECLARATION

Model element within which an element is declared.

0..1

extensions: Hash <String ,Any >

Optional meta-data of this element, as a keyed list. May be used to extend the meta-model.

Functions

Signature

Meaning

1..1

is_root_scope (): Boolean `

Post_result: `Result = (scope = self)

True if this declaration entity is the root of the declaration hierarchy.

BMM_DECLARATION (abstract)

Meta-type of BMM declared model elements. A declaration is a an element of a model specified by an author within a model definition within a context, which defines the scope of the element. Thus, a class definition and its property and routine definitions are model elements, but Types are not, since they are derived from model elements.

Attributes

name: `String ` [1..1]

Name of this model element.

documentation: Hash <String ,Any > [0..1]

Optional documentation of this element, as a keyed list.

It is strongly recommended to use the following key /type combinations for the relevant purposes:

  • "purpose": String

  • "keywords": List<String>

  • "use": String

  • "misuse": String

  • "references": String

Other keys and value types may be freely added.

scope: BMM_DECLARATION [1..1]

Model element within which an element is declared.

extensions: Hash <String ,Any > [0..1]

Optional meta-data of this element, as a keyed list. May be used to extend the meta-model.

Functions

is_root_scope (): Boolean `

Post_result: `Result = (scope = self)
[1..1]

True if this declaration entity is the root of the declaration hierarchy.

{
    "name": "BMM_DECLARATION",
    "documentation": "Meta-type of BMM declared model elements. A _declaration_ is a an element of a model _specified by an author within a model definition_ within a context, which defines the _scope_ of the element. Thus, a class definition and its property and routine definitions are model elements, but Types are not, since they are derived from model elements.",
    "is_abstract": true,
    "properties": {
        "name": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "name",
            "documentation": "Name of this model element.",
            "is_mandatory": true,
            "type": "String"
        },
        "documentation": {
            "_type": "P_BMM_GENERIC_PROPERTY",
            "name": "documentation",
            "documentation": "Optional documentation of this element, as a keyed list.\n\nIt is strongly recommended to use the following key /type combinations for the relevant purposes:\n\n* `\"purpose\": String`\n* `\"keywords\": List<String>`\n* `\"use\": String`\n* `\"misuse\": String`\n* `\"references\": String`\n\nOther keys and value types may be freely added.",
            "type_def": {
                "root_type": "Hash",
                "generic_parameters": [
                    "String",
                    "Any"
                ]
            }
        },
        "scope": {
            "_type": "P_BMM_SINGLE_PROPERTY",
            "name": "scope",
            "documentation": "Model element within which an element is declared.",
            "is_mandatory": true,
            "type": "BMM_DECLARATION"
        },
        "extensions": {
            "_type": "P_BMM_GENERIC_PROPERTY",
            "name": "extensions",
            "documentation": "Optional meta-data of this element, as a keyed list. May be used to extend the meta-model.",
            "type_def": {
                "root_type": "Hash",
                "generic_parameters": [
                    "String",
                    "Any"
                ]
            }
        }
    },
    "functions": {
        "is_root_scope": {
            "name": "is_root_scope",
            "documentation": "True if this declaration entity is the root of the declaration hierarchy.",
            "post_conditions": {
                "Post_result": "Result = (scope = self)"
            },
            "result": {
                "_type": "P_BMM_SIMPLE_TYPE",
                "type": "Boolean"
            }
        }
    }
}
bmm declaration

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_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_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