3

var name を別の var に保存しており、元の var から値を取得したいと考えています。

例:

var var_A: list of uint = {1,3,2};
var var_A_str:string = "var_A";

//ここで、var_A_str を使用して var_A の値のリストを出力します。どうやってやるの?

print $var_A_str;
4

1 に答える 1

2

これは内省または内省と呼ばれます。Specmanのを使用する必要がありますrf_manager。ドキュメントで検索してください。ただし、ドキュメントには、このユニットにあるすべてのメソッドが示されているわけではありません。本当にすべてのメソッドを確認したい場合は、次のコードスニペットを実行してください。

extend sys {
    run() is also {
        var rf_man : rf_struct = rf_manager.get_exact_subtype_of_instance(rf_manager);
        out(" RF Manager:");
        for each (meth) in rf_man.get_declared_methods() {
            print meth;
        };
    };
};

リスト要素を反復処理する方法はわかりませんが、このスニペットを使用して、オブジェクトのインスタンスメンバー(サブルーチンの変数ではない)への参照のメソッドを調べることができます。

extend sys {

    A : list of uint;
    keep A == {1;3;2};
    run() is also {

        var variable_name := "A";
        var rf_obj: rf_struct = rf_manager.get_exact_subtype_of_instance(sys);
        var rf_i : rf_field =  rf_obj.get_field(variable_name);
        print rf_i;
        var rf_rf_i := rf_manager.get_exact_subtype_of_instance(rf_i);
        out ( "#\n# RF_RFI\n#");
        for each (meth) in rf_rf_i.get_declared_methods() {
            print meth;
        }; 
    };
};    

私のバージョン(8.2)では、これは次のように出力されます。

    テストを開始しています...
    テストの実行..。
      rf_i = rf_field'A'、@rf_test4の7行目
    #
    #RF_RFI
    #
      meth = rf_method'get_type'、Specmanのプライベートモジュール
      meth = rf_method'is_physical'、Specmanのプライベートモジュール
      meth = rf_method'get_svtp_pack'、Specmanのプライベートモジュール
      meth = rf_method'set_svtp_pack'、Specmanのプライベートモジュール
      meth = rf_method'is_ungenerated'、Specmanのプライベートモジュール
      meth = rf_method'is_const'、Specmanのプライベートモジュール
      meth = rf_method'is_unit_instance'、Specmanのプライベートモジュール
      meth = rf_method'is_port_instance'、Specmanのプライベートモジュール
      meth = rf_method'is_reference'、Specmanのプライベートモジュール
      meth = rf_method'get_constrained_types'、Specmanのプライベートモジュール
      meth = rf_method'get_deep_copy_attr'、Specmanのプライベートモジュール
      meth = rf_method'get_value'、Specmanのプライベートモジュール
      meth = rf_method'set_value'、Specmanのプライベートモジュール
      meth = rf_method'get_value_unsafe'、Specmanのプライベートモジュール
      meth = rf_method'get_all_when_value_unsafe'、Specmanのプライベートモジュール
      meth = rf_method'set_value_unsafe'、Specmanのプライベートモジュール
      meth = rf_method'set_value_const_reassign_unsafe'、Specmanのプライベートモジュール
      meth = rf_method'get_interface_port_prefix'、Specmanのプライベートモジュール
      meth = rf_method'get_interface_port_suffix'、Specmanのプライベートモジュール
      meth = rf_method'is_gen_intelligen'、Specmanのプライベートモジュール
      meth = rf_method'get_long_name'、Specmanのプライベートモジュール
      meth = rf_method'get_implicit_constraints'、Specmanのプライベートモジュール
      meth = rf_method'make_path'、Specmanのプライベートモジュール
      meth = rf_method'make_element'、Specmanのプライベートモジュール
      meth = rf_method'make_list_size_path'、Specmanのプライベートモジュール
      meth = rf_method'is_unit_reference'、Specmanのプライベートモジュール
      meth = rf_method'get_id_name_for_port_type'、Specmanのプライベートモジュール
      meth = rf_method'get_list_upper_bound'、Specmanのプライベートモジュール
      meth = rf_method'get_sv_typename'、Specmanのプライベートモジュール
      meth = rf_method'get_sv_name_under_when'、Specmanのプライベートモジュール
      meth = rf_method'get_sv_size'、Specmanのプライベートモジュール
      meth = rf_method'sv_add_encode_lines'、Specmanのプライベートモジュール
      meth = rf_method'sv_get_decode_function_local_var_name'、Specmanのプライベートモジュール
      meth = rf_method'sv_get_decode_function_local_var_decl'、Specmanのプライベートモジュール
      meth = rf_method'sv_add_decode_lines'、Specmanのプライベートモジュール
      meth = rf_method'get_sv_field_name'、Specmanのプライベートモジュール
      meth = rf_method'get_sv_field'、Specmanのプライベートモジュール
      meth = rf_method'sv_must_be_protected_field'、Specmanのプライベートモジュール
      meth = rf_method'sv_add_get_set_field_functions'、Specmanのプライベートモジュール
      meth = rf_method'sv_add_get_set_field_function_decs'、Specmanのプライベートモジュール
      meth = rf_method'is_sv_exported_field'、Specmanのプライベートモジュール
      meth = rf_method'is_sv_determinant_field'、Specmanのプライベートモジュール
      meth = rf_method'field_configured_to_svtp_pack'、Specmanのプライベートモジュール
      meth = rf_method'get_ovm_field_macro'、Specmanのプライベートモジュール
      meth = rf_method'is_internal'、Specmanのプライベートモジュール
      meth = rf_method'get'、Specmanのプライベートモジュール
      meth = rf_method'eanalyze_lnt'、Specmanのプライベートモジュール
    実際の実行は要求されていません。
    テストをチェックしています...

Checking is complete - 0 DUT errors, 0 DUT warnings.

あなたがやりたいことをする方法があると確信していますが、Specmanのリフレクションインターフェースを使用するのは非常に難しい場合があります。

メリーハッキング!

于 2010-07-26T20:47:48.383 に答える