summaryrefslogtreecommitdiff
path: root/symbol.c
diff options
context:
space:
mode:
author卜部昌平 <[email protected]>2020-06-25 14:03:23 +0900
committer卜部昌平 <[email protected]>2020-06-29 11:05:41 +0900
commita523eca1c2581be92cab4b1461e3dd65102d99bf ()
treeaac61bb57321d727dea2f91a9510268a4a34ea9b /symbol.c
parent2bd0f37e2bb5300991b2b497b57446a115904ee1 (diff)
rb_enc_symname_type: refactor split
Reduce goto by splitting the function.
Notes: Merged: https://.com/ruby/ruby/pull/3247
-rw-r--r--symbol.c137
1 files changed, 93 insertions, 44 deletions
@@ -238,89 +238,138 @@ rb_sym_constant_char_p(const char *name, long nlen, rb_encoding *enc)
#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
-int
-rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
{
const char *m = name;
const char *e = m + len;
- int type = ID_JUNK;
- if (!rb_enc_asciicompat(enc)) return -1;
- if (!m || len <= 0) return -1;
switch (*m) {
case '\0':
- return -1;
case '$':
- type = ID_GLOBAL;
- if (is_special_global_name(++m, e, enc)) return type;
- goto id;
case '@':
- type = ID_INSTANCE;
- if (*++m == '@') {
- ++m;
- type = ID_CLASS;
- }
- goto id;
case '<':
switch (*++m) {
- case '<': ++m; break;
- case '=': if (*++m == '>') ++m; break;
- default: break;
}
- break;
case '>':
switch (*++m) {
- case '>': case '=': ++m; break;
}
- break;
case '=':
switch (*++m) {
- case '~': ++m; break;
- case '=': if (*++m == '=') ++m; break;
- default: return -1;
}
- break;
case '*':
- if (*++m == '*') ++m;
- break;
case '+': case '-':
- if (*++m == '@') ++m;
- break;
case '|': case '^': case '&': case '/': case '%': case '~': case '`':
- ++m;
- break;
case '[':
- if (m[1] != ']') goto id;
- ++m;
- if (*++m == '=') ++m;
- break;
case '!':
- if (len == 1) return ID_JUNK;
switch (*++m) {
- case '=': case '~': ++m; break;
default:
- if (allowed_attrset & (1U << ID_JUNK)) goto id;
- return -1;
}
- break;
default:
- type = rb_sym_constant_char_p(m, e-m, enc) ? ID_CONST : ID_LOCAL;
- goto id;
}
- 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);