From f591d307d9af95bfa0ccda4d5eb76a674447ba39 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 3 Aug 2016 21:38:50 +0300 Subject: Restore typed regexp code in a new branch. --- awk.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'awk.h') diff --git a/awk.h b/awk.h index ba572d32..b286a9a9 100644 --- a/awk.h +++ b/awk.h @@ -264,6 +264,7 @@ typedef enum nodevals { Node_val, /* node is a value - type in flags */ Node_regex, /* a regexp, text, compiled, flags, etc */ Node_dynregex, /* a dynamic regexp */ + Node_typedregex, /* like Node_regex, but is a real type */ /* symbol table values */ Node_var, /* scalar variable, lnode is value */ @@ -1804,6 +1805,9 @@ dupnode(NODE *n) static inline NODE * force_string(NODE *s) { + if (s->type == Node_typedregex) + return dupnode(s->re_exp); + if ((s->flags & STRCUR) != 0 && (s->stfmt == STFMT_UNUSED || s->stfmt == CONVFMTidx) ) @@ -1830,6 +1834,9 @@ unref(NODE *r) static inline NODE * force_number(NODE *n) { + if (n->type == Node_typedregex) + return Nnull_string; + return (n->flags & NUMCUR) != 0 ? n : str2number(n); } @@ -1854,7 +1861,7 @@ force_number(NODE *n) static inline NODE * fixtype(NODE *n) { - assert(n->type == Node_val); + assert(n->type == Node_val || n->type == Node_typedregex); if (n->type == Node_val) { if ((n->flags & MAYBE_NUM) != 0) return force_number(n); -- cgit v1.2.3 From b37675aa79213f2665abb2bbb4db90560642bdee Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 15 Nov 2016 21:03:57 +0200 Subject: First steps reworking code away from node type. --- awk.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'awk.h') diff --git a/awk.h b/awk.h index df901190..cc487c3a 100644 --- a/awk.h +++ b/awk.h @@ -267,7 +267,6 @@ typedef enum nodevals { Node_val, /* node is a value - type in flags */ Node_regex, /* a regexp, text, compiled, flags, etc */ Node_dynregex, /* a dynamic regexp */ - Node_typedregex, /* like Node_regex, but is a real type */ /* symbol table values */ Node_var, /* scalar variable, lnode is value */ @@ -385,6 +384,7 @@ typedef struct exp_node { int idx; wchar_t *wsp; size_t wslen; + Regexp *preg; } val; } sub; NODETYPE type; @@ -461,6 +461,7 @@ typedef struct exp_node { * See cint_array.c */ # define XARRAY 0x20000 # define NUMCONSTSTR 0x40000 /* have string value for numeric constant */ +# define REGEX 0x80000 /* this is a typed regex */ } NODE; #define vname sub.nodep.name @@ -508,6 +509,7 @@ typedef struct exp_node { #else #define numbr sub.val.fltnum #endif +#define tre_regs sub.val.preg /* * If stfmt is set to STFMT_UNUSED, it means that the string representation @@ -1818,9 +1820,6 @@ dupnode(NODE *n) static inline NODE * force_string(NODE *s) { - if (s->type == Node_typedregex) - return dupnode(s->re_exp); - if ((s->flags & STRCUR) != 0 && (s->stfmt == STFMT_UNUSED || s->stfmt == CONVFMTidx) ) @@ -1847,9 +1846,6 @@ unref(NODE *r) static inline NODE * force_number(NODE *n) { - if (n->type == Node_typedregex) - return Nnull_string; - return (n->flags & NUMCUR) != 0 ? n : str2number(n); } @@ -1866,15 +1862,12 @@ force_number(NODE *n) * It is safe to assume that the return value will be the same NODE, * since force_number on a MAYBE_NUM should always return the same NODE, * and force_string on an INTIND should as well. - * - * There is no way to handle a Node_typedregex correctly, so we ignore - * that case. */ static inline NODE * fixtype(NODE *n) { - assert(n->type == Node_val || n->type == Node_typedregex); + assert(n->type == Node_val); if (n->type == Node_val) { if ((n->flags & MAYBE_NUM) != 0) return force_number(n); -- cgit v1.2.3 From 4f1eec385831018980e4c7424e1a544c5313b52a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 15 Nov 2016 21:45:58 +0200 Subject: Finish reworking typed regexes. Tests pass! --- awk.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'awk.h') diff --git a/awk.h b/awk.h index cc487c3a..890e5861 100644 --- a/awk.h +++ b/awk.h @@ -384,7 +384,7 @@ typedef struct exp_node { int idx; wchar_t *wsp; size_t wslen; - Regexp *preg; + struct exp_node *typre; } val; } sub; NODETYPE type; @@ -510,6 +510,7 @@ typedef struct exp_node { #define numbr sub.val.fltnum #endif #define tre_regs sub.val.preg +#define typed_re sub.val.typre /* * If stfmt is set to STFMT_UNUSED, it means that the string representation -- cgit v1.2.3 From f0b405cceab16dadbb84b95a8d68f705bc20f70f Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 15 Nov 2016 21:47:48 +0200 Subject: Actually remove tre_reg define. --- awk.h | 1 - 1 file changed, 1 deletion(-) (limited to 'awk.h') diff --git a/awk.h b/awk.h index 890e5861..1cd1d5d1 100644 --- a/awk.h +++ b/awk.h @@ -509,7 +509,6 @@ typedef struct exp_node { #else #define numbr sub.val.fltnum #endif -#define tre_regs sub.val.preg #define typed_re sub.val.typre /* -- cgit v1.2.3