aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--awk.h31
-rw-r--r--mpfr.c4
-rw-r--r--node.c4
4 files changed, 45 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 05f53423..e685dd6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,16 @@
of unexpected data. Make the lint warning an unconditional
warning.
+ Unrelated:
+
+ * awk.h: Add explanatory comment on the flags related to
+ types and values.
+ * mpfr.c (mpg_force_number): If setting NUMBER, clear STRING also
+ when clearing MAYBE_NUM.
+ (set_PREC): Check STRCUR instead of STRING.
+ * node.c (r_force_number): If setting NUMBER, clear STRING also
+ when clearing MAYBE_NUM.
+
2015-08-15 Arnold D. Robbins <arnold@skeeve.com>
* dfa.c (dfamust): Restore c90 compat by moving some
diff --git a/awk.h b/awk.h
index 1eb26880..c3a3cba7 100644
--- a/awk.h
+++ b/awk.h
@@ -404,6 +404,37 @@ typedef struct exp_node {
# define MALLOC 0x0001 /* can be free'd */
/* type = Node_val */
+ /*
+ * STRING and NUMBER are mutually exclusive. They represent the
+ * type of a value as assigned.
+ *
+ * STRCUR and NUMCUR are not mutually exclusive. They represent that
+ * the particular type of value is up to date. For example,
+ *
+ * a = 5 # NUMBER | NUMCUR
+ * b = a "" # Adds STRCUR to a, since a string value
+ * # is now available. But the type hasn't changed!
+ *
+ * a = "42" # STRING | STRCUR
+ * b = a + 0 # Adds NUMCUR to a, since numeric value
+ * # is now available. But the type hasn't changed!
+ *
+ * MAYBE_NUM is the joker. It means "this is string data, but
+ * the user may have really wanted it to be a number. If we have
+ * to guess, like in a comparison, turn it into a number."
+ * For example, gawk -v a=42 ....
+ * Here, `a' gets STRING|STRCUR|MAYBE_NUM and then when used where
+ * a number is needed, it gets turned into a NUMBER and STRING
+ * is cleared.
+ *
+ * WSTRCUR is for efficiency. If in a multibyte locale, and we
+ * need to do something character based (substr, length, etc.)
+ * we create the corresponding wide character string and store it,
+ * and add WSTRCUR to the flags so that we don't have to do the
+ * conversion more than once.
+ *
+ * We hope that the rest of the flags are self-explanatory. :-)
+ */
# define STRING 0x0002 /* assigned as string */
# define STRCUR 0x0004 /* string value is current */
# define NUMCUR 0x0008 /* numeric value is current */
diff --git a/mpfr.c b/mpfr.c
index a89b2bc6..4e4e12dc 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -347,7 +347,7 @@ mpg_force_number(NODE *n)
return n;
if ((n->flags & MAYBE_NUM) != 0) {
- n->flags &= ~MAYBE_NUM;
+ n->flags &= ~(MAYBE_NUM|STRING);
newflags = NUMBER;
}
@@ -525,7 +525,7 @@ set_PREC()
if ((val->flags & MAYBE_NUM) != 0)
force_number(val);
- if ((val->flags & (STRING|NUMBER)) == STRING) {
+ if ((val->flags & STRCUR) != 0) {
int i, j;
/* emulate IEEE-754 binary format */
diff --git a/node.c b/node.c
index de771147..a7c19db1 100644
--- a/node.c
+++ b/node.c
@@ -76,7 +76,7 @@ r_force_number(NODE *n)
return n;
} else if (n->stlen == 4 && is_ieee_magic_val(n->stptr)) {
if ((n->flags & MAYBE_NUM) != 0)
- n->flags &= ~MAYBE_NUM;
+ n->flags &= ~(MAYBE_NUM|STRING);
n->flags |= NUMBER|NUMCUR;
n->numbr = get_ieee_magic_val(n->stptr);
@@ -103,7 +103,7 @@ r_force_number(NODE *n)
if ((n->flags & MAYBE_NUM) != 0) {
newflags = NUMBER;
- n->flags &= ~MAYBE_NUM;
+ n->flags &= ~(MAYBE_NUM|STRING);
} else
newflags = 0;