Specman e: How to use deep_copy on a structure list?

I have a my_list_1

(list of structures) which is defined like this:

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);
    ...
};

      

Compilation error:

*** 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 spellings deep_copy()

I tried to cause a compilation error ... How do I copy a list of structures into a local variable? Thank you for your help.

+3


source to share


2 answers


You cannot directly use deep_copy(...)

to copy a list. If you look in the docs, deep_copy(...)

takes a single type parameter any_struct

and returns one instance of a struct. You have to use it in a loop for each

:



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];
};
};

      

+2


source


As of Specman 14.2, deep_copy () will copy anything. I think this is not an option yet, but at the end of this year.



+2


source







All Articles