From a523eca1c2581be92cab4b1461e3dd65102d99bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Thu, 25 Jun 2020 14:03:23 +0900 Subject: rb_enc_symname_type: refactor split Reduce goto by splitting the function. --- symbol.c | 137 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 44 deletions(-) (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c index e9f0942324..6e868d3ebe 100644 --- a/symbol.c +++ b/symbol.c @@ -238,89 +238,138 @@ rb_sym_constant_char_p(const char *name, long nlen, rb_encoding *enc) #define IDSET_ATTRSET_FOR_SYNTAX ((1U<') ++m; break; - default: break; + default: return (t) { stophere, ID_JUNK, 1, }; + case '<': return (t) { stophere, ID_JUNK, 2, }; + case '=': + switch (*++m) { + default: return (t) { stophere, ID_JUNK, 2, }; + case '>': return (t) { stophere, ID_JUNK, 3, }; + } } - break; case '>': switch (*++m) { - case '>': case '=': ++m; break; + default: return (t) { stophere, ID_JUNK, 1, }; + case '>': case '=': return (t) { stophere, ID_JUNK, 2, }; } - break; case '=': switch (*++m) { - case '~': ++m; break; - case '=': if (*++m == '=') ++m; break; - default: return -1; + default: return (t) { invalid, 0, 1, }; + case '~': return (t) { stophere, ID_JUNK, 2, }; + case '=': + switch (*++m) { + default: return (t) { stophere, ID_JUNK, 2, }; + case '=': return (t) { stophere, ID_JUNK, 3, }; + } } - break; case '*': - if (*++m == '*') ++m; - break; + switch (*++m) { + default: return (t) { stophere, ID_JUNK, 1, }; + case '*': return (t) { stophere, ID_JUNK, 2, }; + } case '+': case '-': - if (*++m == '@') ++m; - break; + switch (*++m) { + default: return (t) { stophere, ID_JUNK, 1, }; + case '@': return (t) { stophere, ID_JUNK, 2, }; + } case '|': case '^': case '&': case '/': case '%': case '~': case '`': - ++m; - break; + return (t) { stophere, ID_JUNK, 1, }; case '[': - if (m[1] != ']') goto id; - ++m; - if (*++m == '=') ++m; - break; + switch (*++m) { + default: return (t) { needmore, ID_JUNK, 0, }; + case ']': + switch (*++m) { + default: return (t) { stophere, ID_JUNK, 2, }; + case '=': return (t) { stophere, ID_JUNK, 3, }; + } + } case '!': - if (len == 1) return ID_JUNK; switch (*++m) { - case '=': case '~': ++m; break; + case '=': case '~': return (t) { stophere, ID_JUNK, 2, }; default: - if (allowed_attrset & (1U << ID_JUNK)) goto id; - return -1; + if (allowed_attrset & (1U << ID_JUNK)) { + return (t) { needmore, ID_JUNK, 1, }; + } + else { + return (t) { stophere, ID_JUNK, 1, }; + } } - break; default: - type = rb_sym_constant_char_p(m, e-m, enc) ? ID_CONST : ID_LOCAL; - goto id; + if (rb_sym_constant_char_p(name, len, enc)) { + return (t) { needmore, ID_CONST, 0, }; + } + else { + return (t) { needmore, ID_LOCAL, 0, }; + } + } +} +#undef t + +int +rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset) +{ + const struct enc_synmane_type_leading_chars_tag f = + enc_synmane_type_leading_chars(name, len, enc, allowed_attrset); + const char *m = name + f.nread; + const char *e = name + len; + int type = (int)f.type; + + switch (f.kind) { + case invalid: return -1; + case stophere: goto stophere; + case needmore: break; } - goto stophere; - id: if (m >= e || (*m != '_' && !ISALPHA(*m) && ISASCII(*m))) { if (len > 1 && *(e-1) == '=') { type = rb_enc_symname_type(name, len-1, enc, allowed_attrset); -- cgit v1.2.3