Browse Source

Change CMPP-related struct Mif_Parse_Value to a union

as C99 allows initialisation of any member.  Also correct a comment
in miftypes.h.
pre-master-46
Giles Atkinson 3 years ago
committed by Holger Vogt
parent
commit
7dd2db904c
  1. 11
      src/include/ngspice/mifparse.h
  2. 8
      src/include/ngspice/miftypes.h
  3. 19
      src/xspice/cmpp/writ_ifs.c

11
src/include/ngspice/mifparse.h

@ -47,21 +47,14 @@ NON-STANDARD FEATURES
#include "ngspice/miftypes.h" #include "ngspice/miftypes.h"
/*
* Values of different types used by the parser. Note that this is a structure
* instead of a union because we need to do initializations in the ifspec.c files for
* the models and unions cannot be initialized in any useful way in C
*
*/
struct Mif_Parse_Value {
/* Values of different types used by the parser. */
union Mif_Parse_Value {
Mif_Boolean_t bvalue; /* For boolean values */ Mif_Boolean_t bvalue; /* For boolean values */
int ivalue; /* For integer values */ int ivalue; /* For integer values */
double rvalue; /* For real values */ double rvalue; /* For real values */
Mif_Complex_t cvalue; /* For complex values */ Mif_Complex_t cvalue; /* For complex values */
char *svalue; /* For string values */ char *svalue; /* For string values */
}; };

8
src/include/ngspice/miftypes.h

@ -205,19 +205,19 @@ typedef struct Mif_Complex {
typedef union { typedef union {
Mif_Boolean_t bvalue; /* For digital node value */
Mif_Boolean_t bvalue; /* For boolean parameters */
int ivalue; /* For integer parameters */ int ivalue; /* For integer parameters */
double rvalue; /* For spice node values and real parameters */ double rvalue; /* For spice node values and real parameters */
Mif_Complex_t cvalue; /* For complex parameters */ Mif_Complex_t cvalue; /* For complex parameters */
char *svalue; /* For string parameters */
void *pvalue; /* For user defined nodes */
char *svalue; /* For string parameters */
void *pvalue; /* For Digital and user defined nodes */
} Mif_Value_t; } Mif_Value_t;
/* types from mifparse.h */ /* types from mifparse.h */
typedef struct Mif_Parse_Value Mif_Parse_Value_t;
typedef union Mif_Parse_Value Mif_Parse_Value_t;
typedef struct Mif_Conn_Info Mif_Conn_Info_t; typedef struct Mif_Conn_Info Mif_Conn_Info_t;
typedef struct Mif_Param_Info Mif_Param_Info_t; typedef struct Mif_Param_Info Mif_Param_Info_t;
typedef struct Mif_Inst_Var_Info Mif_Inst_Var_Info_t; typedef struct Mif_Inst_Var_Info Mif_Inst_Var_Info_t;

19
src/xspice/cmpp/writ_ifs.c

@ -719,7 +719,7 @@ static int write_param_info(
p_param_cur->default_value_cnt = 0; p_param_cur->default_value_cnt = 0;
continue; continue;
} }
rc |= fprintf(fp, "static struct Mif_Parse_Value %s_default[] = {\n",
rc |= fprintf(fp, "static union Mif_Parse_Value %s_default[] = {\n",
p_param_cur->name); p_param_cur->name);
do { // Write the default values for this parameter. do { // Write the default values for this parameter.
@ -1270,20 +1270,20 @@ static char *value_to_str(Data_Type_t type, Value_t value)
case CMPP_BOOLEAN: case CMPP_BOOLEAN:
bool_str = boolean_to_str(value.bvalue); bool_str = boolean_to_str(value.bvalue);
sprintf(str, "{%s, 0, 0.0, {0.0, 0.0}, NULL}", bool_str);
sprintf(str, "{ .bvalue=%s }", bool_str);
break; break;
case CMPP_INTEGER: case CMPP_INTEGER:
sprintf(str, "{MIF_FALSE, %d, 0.0, {0.0, 0.0}, NULL}", value.ivalue);
sprintf(str, "{ .ivalue=%d }", value.ivalue);
break; break;
case CMPP_REAL: case CMPP_REAL:
sprintf(str, "{MIF_FALSE, 0, %e, {0.0, 0.0}, NULL}", value.rvalue);
sprintf(str, "{ .rvalue=%e }", value.rvalue);
break; break;
case CMPP_COMPLEX: case CMPP_COMPLEX:
sprintf(str, "{MIF_FALSE, 0, 0.0, {%e, %e}, NULL}",
value.cvalue.real, value.cvalue.imag);
sprintf(str, "{ .cvalue={%e, %e} }",
value.cvalue.real, value.cvalue.imag);
break; break;
case CMPP_STRING: case CMPP_STRING:
@ -1303,7 +1303,7 @@ static char *value_to_str(Data_Type_t type, Value_t value)
max_len += str_len; max_len += str_len;
} /* end of resize */ } /* end of resize */
sprintf(str, "{MIF_FALSE, 0, 0.0, {0.0, 0.0}, \"%s\"}", value.svalue);
sprintf(str, "{ .svalue=\"%s\" }", value.svalue);
break; break;
default: default:
@ -1338,8 +1338,5 @@ static char *integer_to_str(int value)
static const char *no_value_to_str(void) static const char *no_value_to_str(void)
{ {
return "{MIF_FALSE, 0, 0.0, {0.0, 0.0}, NULL}";
return "{ .bvalue=MIF_FALSE }";
} }
Loading…
Cancel
Save