简体   繁体   中英

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM