1

我有一个变量,我想在同一个函数中生成几次,每次都使用相同的约束集。我可以设置一次约束并gen多次设置约束吗?也就是说,而不是这样:

var a:uint;
gen a keeping {it in [100..120];};
// some code that uses a
.
.
.
gen a keeping {it in [100..120];};
// some code that uses a
.
.
.
gen a keeping {it in [100..120];};
// some code that uses a
// etc...

我想这样做:

var a:uint;
keep a in [100..120];
.
.
.
gen a;
// some code that uses a
.
.
.
gen a;
// some code that uses a
.
.
.
gen a;
// some code that uses a
// etc...

这样,如果我想更改as 约束,我只需要做一次。

4

1 回答 1

1

您可以通过使变量成为封闭对象的实例成员来做到这一点。

a : uint;
keep a in [100..120];
my_method()@qualified_clk_rise_e is {

    gen a;
    ...
    gen a;
    ...
    gen a; 
};

如果多个 my_method() 同时在同一个对象上运行,则此实现不是线程安全的。您可以通过将生成的 'a' 分配给方法范围:

var my_a : uint;
gen a;
my_a = a;

或者您可以编写一个生成“a”的方法:

gen_a(): uint is {
    gen result keeping { it in [100..120] };
};

my_method()@qualified_clock_rise_e is {
    var a : uint;
    ...
    a = gen_a();
    ...
    a = gen_a();
    ...
    a = gen_a();
    ...
};
于 2008-12-13T02:50:50.847 回答