Change CMPP-related struct Mif_Parse_Value to a union
as C99 allows initialisation of any member. Also correct a comment in miftypes.h.
This commit is contained in:
parent
7ff4ad0b32
commit
df71478cbc
|
|
@ -47,21 +47,14 @@ NON-STANDARD FEATURES
|
|||
#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 */
|
||||
int ivalue; /* For integer values */
|
||||
double rvalue; /* For real values */
|
||||
Mif_Complex_t cvalue; /* For complex values */
|
||||
char *svalue; /* For string values */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -205,19 +205,19 @@ typedef struct Mif_Complex {
|
|||
|
||||
typedef union {
|
||||
|
||||
Mif_Boolean_t bvalue; /* For digital node value */
|
||||
Mif_Boolean_t bvalue; /* For boolean parameters */
|
||||
int ivalue; /* For integer parameters */
|
||||
double rvalue; /* For spice node values and real 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;
|
||||
|
||||
|
||||
|
||||
/* 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_Param_Info Mif_Param_Info_t;
|
||||
typedef struct Mif_Inst_Var_Info Mif_Inst_Var_Info_t;
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@ static int write_param_info(
|
|||
p_param_cur->default_value_cnt = 0;
|
||||
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);
|
||||
|
||||
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:
|
||||
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;
|
||||
|
||||
case CMPP_INTEGER:
|
||||
sprintf(str, "{MIF_FALSE, %d, 0.0, {0.0, 0.0}, NULL}", value.ivalue);
|
||||
sprintf(str, "{ .ivalue=%d }", value.ivalue);
|
||||
break;
|
||||
|
||||
case CMPP_REAL:
|
||||
sprintf(str, "{MIF_FALSE, 0, %e, {0.0, 0.0}, NULL}", value.rvalue);
|
||||
sprintf(str, "{ .rvalue=%e }", value.rvalue);
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case CMPP_STRING:
|
||||
|
|
@ -1303,7 +1303,7 @@ static char *value_to_str(Data_Type_t type, Value_t value)
|
|||
max_len += str_len;
|
||||
} /* end of resize */
|
||||
|
||||
sprintf(str, "{MIF_FALSE, 0, 0.0, {0.0, 0.0}, \"%s\"}", value.svalue);
|
||||
sprintf(str, "{ .svalue=\"%s\" }", value.svalue);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -1338,8 +1338,5 @@ static char *integer_to_str(int value)
|
|||
|
||||
static const char *no_value_to_str(void)
|
||||
{
|
||||
return "{MIF_FALSE, 0, 0.0, {0.0, 0.0}, NULL}";
|
||||
return "{ .bvalue=MIF_FALSE }";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue