Get the value of a variable not parsed by SWIG in python

Wrote a python routine called get_value_by_ref_name that takes
a variable name string as an argument.  The string is passed to
ref_attributes to find the address and returns a REF2 structure.  The REF2
structure is passed to ref_to_value and the type and value of the variable
is returned in a structure.  We call vval_<type> to extract the raw value
from the structure and return that to python space.

Made a couple of other bug fixes in the FieldVisior and cpp input file
example found while investigating this issue.

refs #123
This commit is contained in:
Alex Lin 2015-09-18 09:03:24 -05:00
parent 2de18b9174
commit 57c76041f5
5 changed files with 44 additions and 5 deletions

View File

@ -20,12 +20,9 @@ float vval_float(V_DATA * V);
double vval_double(V_DATA * V);
char *vval_string(V_DATA * V);
#ifndef __Lynx__
#ifndef SWIG
wchar_t vval_wchar(V_DATA * V);
wchar_t *vval_wstring(V_DATA * V);
#else
int vval_wchar(V_DATA * V);
int *vval_wstring(V_DATA * V);
#endif
FILE *vval_filep(V_DATA * V);

View File

@ -100,3 +100,33 @@ if hasattr(top.cvar, 'trick_data_record'):
drd_writer_thread = top.cvar.trick_data_record.drd.drd_writer_thread
data_record_cpu_set = top.cvar.trick_data_record.drd.drd_writer_thread.cpu_set
# This routine will look up the reference name through ref_attributes.
# ref_to_value retrieves the value and places it into a V_DATA structure
# The return statement is an anonymous dictionary lookup that returns
# the value based on the type in val. The 6 argument is a default
# type to use
def get_value_by_ref_name(name):
ref = trick.ref_attributes(name)
ref.thisown = True
val = trick.V_DATA()
trick.ref_to_value(ref, val)
return {
'1': trick.vval_char(val),
'2': trick.vval_char(val),
'3': trick.vval_string(val),
'4': trick.vval_short(val),
'5': trick.vval_short(val),
'6': trick.vval_int(val),
'7': trick.vval_int(val),
'8': trick.vval_long(val),
'9': trick.vval_long(val),
'10': trick.vval_float(val),
'11': trick.vval_double(val),
'14': trick.vval_longlong(val),
'15': trick.vval_longlong(val),
'16': trick.vval_filep(val),
'17': trick.vval_char(val),
'20': trick.vval_voidp(val),
'21': trick.vval_int(val)
}.get(str(val.type),6)

View File

@ -11,7 +11,9 @@
//#define protected public
#include "../S_source.hh"
#include "sim_services/CheckPointRestart/include/CheckPointRestart_c_intf.hh"
#include "trick/CheckPointRestart_c_intf.hh"
#include "trick/realtimesync_proto.h"
#include "trick/external_application_c_intf.h"
extern "C" int run_event_1() {
message_publish(1, "event 1 fired!\n") ;
@ -81,6 +83,12 @@ extern "C" int run_me() {
exec_set_terminate_time(200.0) ;
/*
real_time_enable() ;
trick_real_time.itimer.enable() ;
sim_control_panel_set_enabled(true) ;
*/
return 0 ;
}

View File

@ -447,6 +447,9 @@ bool FieldVisitor::VisitTypedefType(clang::TypedefType *tt) {
fdes->setHasType(true) ;
} else if ( tt->isRecordType() ) {
std::string type_name = tt->desugar().getAsString() ;
if ((pos = type_name.find("class ")) != std::string::npos ) {
type_name.erase(pos , 6) ;
}
if ((pos = type_name.find("struct ")) != std::string::npos ) {
type_name.erase(pos , 7) ;
}

View File

@ -129,6 +129,7 @@
#include "trick/trick_tests.h"
#include "trick/VariableServer.hh"
#include "trick/variable_server_proto.h"
#include "trick/vval.h"
#include "trick/Flag.h"
#include "trick/Unit.hh"