【发布时间】:2015-04-27 20:58:59
【问题描述】:
我正在用 Alloy 做一个模型来表示 Java 语言的一个子集。下面我们有这个模型的一些元素:
sig Method {
id : one MethodId,
param: lone Type,
return: one Type,
acc: lone Accessibility,
b: one Block
}
abstract sig Expression {}
abstract sig StatementExpression extends Expression {}
sig MethodInvocation extends StatementExpression{
pExp: lone PrimaryExpression,
id_methodInvoked: one Method,
param: lone Type
}
sig Block {
statements: seq StatementExpression
}
pred noRecursiveMethodInvocationCall [] {
no m:Method | m in ^getMethodInvokedInsideBody[m]
}
fun getMethodInvokedInsideBody [m: Method] : Method {
(univ.(m.b.statements)).id_methodInvoked
}
问题是 Block 必须是 StatementExpression 的序列,同时应该避免对同一方法的递归调用。因此,我想到了上面的解决方案。
当我尝试生成相应的实例时,我得到以下错误类型:
.
Name cannot be resolved; possible incorrect
function/predicate call; perhaps you used ( ) when you
should have used [ ]
This cannot be a correct call to fun
genericLawsMetaModel/javametamodel_withfield_final/getMethodInvokedInsideBody.
The parameters are
m:
{genericLawsMetaModel/javametamodel_withfield_final/Method}
so the arguments cannot be empty.
关于这个问题,我还尝试更改谓词 noRecursiveMethodInvocationCall 的定义(从而消除上述函数):
pred noRecursiveMethodInvocationCall [] {
no m:Method | m in ^( (univ.(m.b.statements)).id_methodInvoked )
}
但是,出现新的类型错误:
^ can be used only with a binary relation.
Instead, its possible type(s) are:
{genericLawsMetaModel/javametamodel_withfield_final/Method}
有什么线索吗?我只是想避免对同一方法的递归调用。 提前致谢,
【问题讨论】:
标签: function recursion closures alloy