3

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.

Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
Halona
  • 1,475
  • 1
  • 15
  • 26

2 Answers2

2

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];
};
};
Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
2

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

Thorsten
  • 710
  • 8
  • 17