From 09d92ba6925b6cb3779eae13ce80616f9bbd25e8 Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 31 Oct 2017 10:45:48 +0100 Subject: [PATCH] numparam, entry_type, #2/5, use a type-checked enum for 'nupa_type' --- src/frontend/numparam/numparam.h | 26 ++++++++++++++++++-------- src/frontend/numparam/xpressn.c | 13 +++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/frontend/numparam/numparam.h b/src/frontend/numparam/numparam.h index 2d2d9740c..618e210d8 100644 --- a/src/frontend/numparam/numparam.h +++ b/src/frontend/numparam/numparam.h @@ -19,15 +19,25 @@ typedef enum {Psp = '{'} _nPsp; /* Ps expression */ * I believe the entry_t should be a union of type but I need more info. * ----------------------------------------------------------------- */ -#define NUPA_REAL 'R' -#define NUPA_STRING 'S' -#define NUPA_POINTER 'P' -#define NUPA_SUBCKT 'U' -#define NUPA_SPACE ' ' -#define NUPA_UNKNOWN '?' -#define NUPA_MODEL 'O' +struct nupa_type; -typedef char nupa_type; +extern const struct nupa_type S_nupa_real; +extern const struct nupa_type S_nupa_string; +extern const struct nupa_type S_nupa_pointer; +extern const struct nupa_type S_nupa_subckt; +extern const struct nupa_type S_nupa_space; +extern const struct nupa_type S_nupa_unknown; +extern const struct nupa_type S_nupa_model; + +#define NUPA_REAL (&S_nupa_real) +#define NUPA_STRING (&S_nupa_string) +#define NUPA_POINTER (&S_nupa_pointer) +#define NUPA_SUBCKT (&S_nupa_subckt) +#define NUPA_SPACE (&S_nupa_space) +#define NUPA_UNKNOWN (&S_nupa_unknown) +#define NUPA_MODEL (&S_nupa_model) + +typedef const struct nupa_type *nupa_type; typedef struct entry_s { diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index f29c0d9de..20430e022 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -1779,3 +1779,16 @@ nupa_subcktexit(dico_t *dico) { dicostack_pop(dico); } + + +struct nupa_type { /* used as a type-checked enum */ + const char *name; +}; + +const struct nupa_type S_nupa_real = { "NUPA_REAL" }; +const struct nupa_type S_nupa_string = { "NUPA_STRING" }; +const struct nupa_type S_nupa_pointer = { "NUPA_POINTER" }; +const struct nupa_type S_nupa_subckt = { "NUPA_SUBCKT" }; +const struct nupa_type S_nupa_unknown = { "NUPA_UNKNOWN" }; +const struct nupa_type S_nupa_model = { "NUPA_MODEL" }; +const struct nupa_type S_nupa_space = { "NUPA_SPACE" };