Does specman have static variables?
I have the following code in specman which I inherited:
some_method() is {
var a: bool;
if (!a) {
a = some_other_method();
};
};
I understand that every time it some_method()
is called, a
generated anew, and there is no point in checking the value a
before assigning it. However, I may have missed something. For example, if it a
is static, then this code makes sense, which brings me to my question:
Is there a way for a variable to be static in specman?
a source to share
there are no static variables as in C. A variable in a method has a default value ( False
in this case) if it is not initialized, so you should be right if (!a)
always should be True
.
It would be different if it a
was a member of a struct, then, as in other OO languages, it would store the value over multiple method calls, and the check would make sense:
struct some_struct_s {
a : bool;
some_method() is {
if (!a) {
a = some_other_method();
};
};
};
You can also check things like this in the interactive prompt:
Specman> var a : bool;
Specman> print a
a = FALSE
There online help is also good, for example try:
Specman> help variable
and select the entry (by number) sn_eref: variables : declaring
. There you will find all the information you need for your question.
Cheers, Daniel
a source to share
Static structure elements (events, fields, methods) were added to the language in Specman v15.2. Static field cannot be generated, physical (%), or used on subtypes.
struct some_struct_s {
a : bool;
some_method() is {
if (!a) {
a = some_other_method();
};
};
};
-- Change field 'a' for all instances
on xxx { some_struct_s::a = TRUE; };
Here are some comments from the teampecman blog: Static members in e
a source to share