9.3.26 IterateExpCS

IterateExpCS ::= OclExpressionCS[1] ‘->’ ‘iterate’ 
                ‘(‘ (VariableDeclarationCS[1] ‘;’)? 
                    VariableDeclarationCS[2] ‘|’ 
                    OclExpressionCS[2]
                ‘)’

抽象语法映射

IterateExpCS.ast : IterateExp

合成的属性

-- ast需要逐位判断, 首先是IterateExp的源关联
IterateExpCS.ast.source = OclExpressionCS[1].ast
-- 接下来是IterateExp的迭代器关联。当第一个变量声明存在是,它的ast是这个迭代表达式的迭代器;
-- 当变量声明不存在时, 迭代器有一个缺省的名称和类型, 不管哪种情况,迭代器不能有初始化表达式
IterateExpCS.ast.iterator.name = if VariableDeclarationCS[1]->isEmpty() then ‘’
        else VariableDeclarationCS[1].ast.name
        endif
IterateExpCS.ast.iterator.type =
        if VariableDeclarationCS[1]->isEmpty() or
                (VariableDeclarationCS[1]->notEmpty() and
                VariableDeclarationCS[1].ast.type.oclIsUndefined() ) then
            OclExpressionCS[1].type.oclAsType (CollectionType).elementType
        else
            VariableDeclarationCS[1].ast.type
        endif
IterateExpCS.ast.iterator.initExpression->isEmpty()
-- 接下来是IterateExp的名称属性、body和结果关联
IterateExpCS.ast.result = VariableDeclarationCS[2].ast
IterateExpCS.ast.name = ‘iterate’
IterateExpCS.ast.body = OclExpressionCS[2].ast

继承的属性

OclExpressionCS[1].env = IteratorExpCS.env
VariableDeclarationCS[1].env = IteratorExpCS.env
VariableDeclarationCS[2].env = IteratorExpCS.env
-- 在迭代表达式中,body在一个包含迭代器变量和结果变量的新环境内被计算。
OclExpressionCS[2].env = IteratorExpCS.env.nestedEnvironment().addElement(
                                VariableDeclarationCS[1].ast.varName,
                                VariableDeclarationCS[1].ast,
                                true).addElement(VariableDeclarationCS[2].ast.varName,
                                         VariableDeclarationCS[2].ast,
                                         true)

歧义消除规则

[1] 结果变量声明必须有一个类型和初始值。

not VariableDeclarationCS[2].ast.type.oclIsUndefined() VariableDeclarationCS[2].ast.initExpression->notEmpty()

[2] 当第一个变量声明存在时,它不能有初始化表达式。

VariableDeclarationCS[1]->notEmpty() implies VariableDeclarationCS[1].ast.initExpression->isEmpty()

results matching ""

    No results matching ""