Reputation: 127428
I have the following code in specman that I inherited:
some_method() is {
var a: bool;
if (!a) {
a = some_other_method();
};
};
My understanding is that each time some_method()
is called, a
is generated anew, and there's no sense in checking a
's value before it's assigned. However, it may be that I'm missing something here. For instance, if a
is static then this code makes sense, which brings me to my question:
Is there any way for a variable to be static in specman?
Upvotes: 1
Views: 687
Reputation: 384
Static struct members (events, fields, methods) were added to the language in Specman v15.2. A static field can't be generated, physical(%) or used in when 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's some comments from the teamspecman blog : Static members in e
Upvotes: 0
Reputation: 3816
there are no static variables as in C. A variable in a method has its default value (False
in this case) if not initialized, so you should be right if (!a)
should always be True
.
Things would be different if a
was a struct member, then like in other OO languages it would retain there value over several method calls and the check would make more sense:
struct some_struct_s {
a : bool;
some_method() is {
if (!a) {
a = some_other_method();
};
};
};
You can check stuff like this also on the interactive prompt:
Specman> var a : bool;
Specman> print a
a = FALSE
There the interactive help is also nice, for example try:
Specman> help variable
and select the entry (by number) sn_eref: variables : declaring
. There you will find all relevant information for your question.
Cheers, Daniel
Upvotes: 3