Specman e: How to use deep_copy on list of structs?

507 views Asked by At

I have a my_list_1 (list of structs) that defined this way:

struct my_struct {
    something[2] : list of int;
    something_else[2] : list of uint;
};
...
my_list_1[10] : list of my_struct;

I need to copy this list to a local variable in a method:

foo_method() is {
    var my_list_2 : list of my_struct;
    my_list_2 = deep_copy(my_list_1);
    ...
};

The compilation error I get:

*** Error: 'my_list_1' is of type 'list of my_struct', while
expecting type 'any_struct'.
...
        my_list_2 = deep_copy(my_list_1);

All variations to write deep_copy() I've tried caused compilation error... How to copy a list of structs to a local variable? Thank you for your help.

2

There are 2 answers

0
Tudor Timi On BEST ANSWER

You can't use deep_copy(...) directly to copy a list. If you look in the docs, deep_copy(...) takes a single parameter of type any_struct and returns a single struct instance. You have to use it in a for each loop:

extend sys {
  my_list_1[10] : list of my_struct;

  run() is also {
    foo_method();
  };

  foo_method() is {
    var my_list_2 : list of my_struct;

    for each (elem) in my_list_1 {
      my_list_2.add(deep_copy(elem));
    };

    print my_list_1[0], my_list_2[0];
    print my_list_1[1], my_list_2[1];
};
};
0
Thorsten On

From Specman 14.2, deep_copy() will copy anything. I think it is not yet out, but due towards the end of this year.