diff --git a/include/nsc.h b/include/nsc.h index 4a7f7251..91519206 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -275,6 +275,7 @@ extern int nstr_coerce_val(struct valstr *, nsc_type, char *); extern int nstr_exec(struct nscstr *, int, void *); /* src/lib/common/nstreval.c */ extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type); +extern int nstr_promote(int); extern char *symbol_by_value(int, struct symbol *); /* src/lib/global/nsc.c */ extern void nsc_init(void); diff --git a/src/lib/common/nstreval.c b/src/lib/common/nstreval.c index 9bb35dc8..c730ff5a 100644 --- a/src/lib/common/nstreval.c +++ b/src/lib/common/nstreval.c @@ -160,6 +160,44 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want) val->val_type = valtype; } +/* + * Promote VALTYPE. + * If VALTYPE is an integer type, return NSC_LONG. + * If VALTYPE is a floating-point type, return NSC_DOUBLE. + * If VALTYPE is a string type, return NSC_STRING. + */ +int +nstr_promote(int valtype) +{ + switch (valtype) { + case NSC_LONG: + case NSC_DOUBLE: + case NSC_STRING: + break; + case NSC_CHAR: + case NSC_UCHAR: + case NSC_SHORT: + case NSC_USHORT: + case NSC_INT: + case NSC_XCOORD: + case NSC_YCOORD: + case NSC_HIDDEN: + case NSC_TIME: + valtype = NSC_LONG; + break; + case NSC_FLOAT: + valtype = NSC_DOUBLE; + break; + case NSC_STRINGY: + valtype = NSC_STRING; + break; + default: + CANT_REACH(); + valtype = NSC_NOTYPE; + } + return valtype; +} + char * symbol_by_value(int key, struct symbol *table) { diff --git a/src/lib/subs/nstr.c b/src/lib/subs/nstr.c index 2ce08403..0142257c 100644 --- a/src/lib/subs/nstr.c +++ b/src/lib/subs/nstr.c @@ -49,8 +49,6 @@ static int nstr_string_ok(struct castr *ca, int idx); static struct valstr *nstr_resolve_sel(struct valstr *, struct castr *); static struct valstr *nstr_mkselval(struct valstr *, int, struct castr *); static struct valstr *nstr_resolve_id(struct valstr *, struct castr *, int, int); -static int nstr_promote(int); - /* * Compile conditions into array NP[LEN]. @@ -474,45 +472,6 @@ nstr_comp_val(char *str, struct valstr *val, int type) return tail; } - -/* - * Promote VALTYPE. - * If VALTYPE is an integer type, return NSC_LONG. - * If VALTYPE is a floating-point type, return NSC_DOUBLE. - * If VALTYPE is a string type, return NSC_STRING. - */ -static int -nstr_promote(int valtype) -{ - switch (valtype) { - case NSC_LONG: - case NSC_DOUBLE: - case NSC_STRING: - break; - case NSC_CHAR: - case NSC_UCHAR: - case NSC_SHORT: - case NSC_USHORT: - case NSC_INT: - case NSC_XCOORD: - case NSC_YCOORD: - case NSC_HIDDEN: - case NSC_TIME: - valtype = NSC_LONG; - break; - case NSC_FLOAT: - valtype = NSC_DOUBLE; - break; - case NSC_STRINGY: - valtype = NSC_STRING; - break; - default: - CANT_REACH(); - valtype = NSC_NOTYPE; - } - return valtype; -} - static int cond_type_mismatch(char *str) {