diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-29 03:02:21 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-29 03:02:21 +0200 |
commit | f414fb4411e65662b44f038ed3175789172edc20 (patch) | |
tree | 8808a777db07f2c99d8f7edaec898b052de80309 | |
parent | cb6061a4e9860bf3d529109b34103ce3bde6d735 (diff) | |
download | busybox-w32-f414fb4411e65662b44f038ed3175789172edc20.tar.gz busybox-w32-f414fb4411e65662b44f038ed3175789172edc20.tar.bz2 busybox-w32-f414fb4411e65662b44f038ed3175789172edc20.zip |
awk: when parsing TC_FUNCTION token, eat its opening '('
...like we do for array references.
function old new delta
parse_expr 938 948 +10
next_token 788 791 +3
parse_program 313 310 -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 13/-3) Total: 10 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/editors/awk.c b/editors/awk.c index 7e4f0d142..1a4468a53 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -241,7 +241,7 @@ typedef struct tsplitter_s { | |||
241 | #define TC_EOF (1 << 25) | 241 | #define TC_EOF (1 << 25) |
242 | #define TC_VARIABLE (1 << 26) /* name */ | 242 | #define TC_VARIABLE (1 << 26) /* name */ |
243 | #define TC_ARRAY (1 << 27) /* name[ */ | 243 | #define TC_ARRAY (1 << 27) /* name[ */ |
244 | #define TC_FUNCTION (1 << 28) /* name( - but unlike TC_ARRAY, parser does not consume '(' */ | 244 | #define TC_FUNCTION (1 << 28) /* name( */ |
245 | #define TC_STRING (1 << 29) /* "..." */ | 245 | #define TC_STRING (1 << 29) /* "..." */ |
246 | #define TC_NUMBER (1 << 30) | 246 | #define TC_NUMBER (1 << 30) |
247 | 247 | ||
@@ -959,6 +959,7 @@ static double getvar_i(var *v) | |||
959 | v->number = my_strtod(&s); | 959 | v->number = my_strtod(&s); |
960 | debug_printf_eval("%f (s:'%s')\n", v->number, s); | 960 | debug_printf_eval("%f (s:'%s')\n", v->number, s); |
961 | if (v->type & VF_USER) { | 961 | if (v->type & VF_USER) { |
962 | //TODO: skip_spaces() also skips backslash+newline, is it intended here? | ||
962 | s = skip_spaces(s); | 963 | s = skip_spaces(s); |
963 | if (*s != '\0') | 964 | if (*s != '\0') |
964 | v->type &= ~VF_USER; | 965 | v->type &= ~VF_USER; |
@@ -1103,7 +1104,7 @@ static uint32_t next_token(uint32_t expected) | |||
1103 | #define save_tclass (G.next_token__save_tclass) | 1104 | #define save_tclass (G.next_token__save_tclass) |
1104 | #define save_info (G.next_token__save_info) | 1105 | #define save_info (G.next_token__save_info) |
1105 | 1106 | ||
1106 | char *p, *s; | 1107 | char *p; |
1107 | const char *tl; | 1108 | const char *tl; |
1108 | const uint32_t *ti; | 1109 | const uint32_t *ti; |
1109 | uint32_t tc, last_token_class; | 1110 | uint32_t tc, last_token_class; |
@@ -1131,15 +1132,12 @@ static uint32_t next_token(uint32_t expected) | |||
1131 | while (*p != '\n' && *p != '\0') | 1132 | while (*p != '\n' && *p != '\0') |
1132 | p++; | 1133 | p++; |
1133 | 1134 | ||
1134 | if (*p == '\n') | ||
1135 | t_lineno++; | ||
1136 | |||
1137 | if (*p == '\0') { | 1135 | if (*p == '\0') { |
1138 | tc = TC_EOF; | 1136 | tc = TC_EOF; |
1139 | debug_printf_parse("%s: token found: TC_EOF\n", __func__); | 1137 | debug_printf_parse("%s: token found: TC_EOF\n", __func__); |
1140 | } else if (*p == '\"') { | 1138 | } else if (*p == '\"') { |
1141 | /* it's a string */ | 1139 | /* it's a string */ |
1142 | t_string = s = ++p; | 1140 | char *s = t_string = ++p; |
1143 | while (*p != '\"') { | 1141 | while (*p != '\"') { |
1144 | char *pp; | 1142 | char *pp; |
1145 | if (*p == '\0' || *p == '\n') | 1143 | if (*p == '\0' || *p == '\n') |
@@ -1154,7 +1152,7 @@ static uint32_t next_token(uint32_t expected) | |||
1154 | debug_printf_parse("%s: token found:'%s' TC_STRING\n", __func__, t_string); | 1152 | debug_printf_parse("%s: token found:'%s' TC_STRING\n", __func__, t_string); |
1155 | } else if ((expected & TC_REGEXP) && *p == '/') { | 1153 | } else if ((expected & TC_REGEXP) && *p == '/') { |
1156 | /* it's regexp */ | 1154 | /* it's regexp */ |
1157 | t_string = s = ++p; | 1155 | char *s = t_string = ++p; |
1158 | while (*p != '/') { | 1156 | while (*p != '/') { |
1159 | if (*p == '\0' || *p == '\n') | 1157 | if (*p == '\0' || *p == '\n') |
1160 | syntax_error(EMSG_UNEXP_EOS); | 1158 | syntax_error(EMSG_UNEXP_EOS); |
@@ -1185,6 +1183,9 @@ static uint32_t next_token(uint32_t expected) | |||
1185 | tc = TC_NUMBER; | 1183 | tc = TC_NUMBER; |
1186 | debug_printf_parse("%s: token found:%f TC_NUMBER\n", __func__, t_double); | 1184 | debug_printf_parse("%s: token found:%f TC_NUMBER\n", __func__, t_double); |
1187 | } else { | 1185 | } else { |
1186 | if (*p == '\n') | ||
1187 | t_lineno++; | ||
1188 | |||
1188 | /* search for something known */ | 1189 | /* search for something known */ |
1189 | tl = tokenlist; | 1190 | tl = tokenlist; |
1190 | tc = 0x00000001; | 1191 | tc = 0x00000001; |
@@ -1230,15 +1231,15 @@ static uint32_t next_token(uint32_t expected) | |||
1230 | if (!(expected & TC_VARIABLE) || (expected & TC_ARRAY)) | 1231 | if (!(expected & TC_VARIABLE) || (expected & TC_ARRAY)) |
1231 | p = skip_spaces(p); | 1232 | p = skip_spaces(p); |
1232 | if (*p == '(') { | 1233 | if (*p == '(') { |
1234 | p++; | ||
1233 | tc = TC_FUNCTION; | 1235 | tc = TC_FUNCTION; |
1234 | debug_printf_parse("%s: token found:'%s' TC_FUNCTION\n", __func__, t_string); | 1236 | debug_printf_parse("%s: token found:'%s' TC_FUNCTION\n", __func__, t_string); |
1237 | } else if (*p == '[') { | ||
1238 | p++; | ||
1239 | tc = TC_ARRAY; | ||
1240 | debug_printf_parse("%s: token found:'%s' TC_ARRAY\n", __func__, t_string); | ||
1235 | } else { | 1241 | } else { |
1236 | if (*p == '[') { | 1242 | debug_printf_parse("%s: token found:'%s' TC_VARIABLE\n", __func__, t_string); |
1237 | p++; | ||
1238 | tc = TC_ARRAY; | ||
1239 | debug_printf_parse("%s: token found:'%s' TC_ARRAY\n", __func__, t_string); | ||
1240 | } else | ||
1241 | debug_printf_parse("%s: token found:'%s' TC_VARIABLE\n", __func__, t_string); | ||
1242 | } | 1243 | } |
1243 | } | 1244 | } |
1244 | token_found: | 1245 | token_found: |
@@ -1431,7 +1432,7 @@ static node *parse_expr(uint32_t term_tc) | |||
1431 | debug_printf_parse("%s: TC_FUNCTION\n", __func__); | 1432 | debug_printf_parse("%s: TC_FUNCTION\n", __func__); |
1432 | cn->info = OC_FUNC; | 1433 | cn->info = OC_FUNC; |
1433 | cn->r.f = newfunc(t_string); | 1434 | cn->r.f = newfunc(t_string); |
1434 | cn->l.n = parse_lrparen_list(); | 1435 | cn->l.n = parse_expr(TC_RPAREN); |
1435 | break; | 1436 | break; |
1436 | 1437 | ||
1437 | case TC_LPAREN: | 1438 | case TC_LPAREN: |
@@ -1682,7 +1683,6 @@ static void parse_program(char *p) | |||
1682 | } else if (tclass & TC_FUNCDECL) { | 1683 | } else if (tclass & TC_FUNCDECL) { |
1683 | debug_printf_parse("%s: TC_FUNCDECL\n", __func__); | 1684 | debug_printf_parse("%s: TC_FUNCDECL\n", __func__); |
1684 | next_token(TC_FUNCTION); | 1685 | next_token(TC_FUNCTION); |
1685 | g_pos++; | ||
1686 | f = newfunc(t_string); | 1686 | f = newfunc(t_string); |
1687 | f->body.first = NULL; | 1687 | f->body.first = NULL; |
1688 | f->nargs = 0; | 1688 | f->nargs = 0; |