Remove unions in rb_strterm
structs for alignment
This commit is contained in:
parent
82c8f22a36
commit
cb06b6632a
@ -22,48 +22,24 @@ struct rb_iseq_struct; /* in vm_core.h */
|
||||
|
||||
/* structs for managing terminator of string literal and heredocment */
|
||||
typedef struct rb_strterm_literal_struct {
|
||||
union {
|
||||
VALUE dummy;
|
||||
long nest;
|
||||
} u0;
|
||||
union {
|
||||
VALUE dummy;
|
||||
long func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */
|
||||
} u1;
|
||||
union {
|
||||
VALUE dummy;
|
||||
long paren; /* '(' of `%q(...)` */
|
||||
} u2;
|
||||
union {
|
||||
VALUE dummy;
|
||||
long term; /* ')' of `%q(...)` */
|
||||
} u3;
|
||||
long nest;
|
||||
long func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */
|
||||
long paren; /* '(' of `%q(...)` */
|
||||
long term; /* ')' of `%q(...)` */
|
||||
} rb_strterm_literal_t;
|
||||
|
||||
#define HERETERM_LENGTH_BITS ((SIZEOF_VALUE - 1) * CHAR_BIT - 1)
|
||||
|
||||
typedef struct rb_strterm_heredoc_struct {
|
||||
VALUE lastline; /* the string of line that contains `<<"END"` */
|
||||
long offset; /* the column of END in `<<"END"` */
|
||||
int sourceline; /* lineno of the line that contains `<<"END"` */
|
||||
unsigned length /* the length of END in `<<"END"` */
|
||||
#if HERETERM_LENGTH_BITS < SIZEOF_INT * CHAR_BIT
|
||||
: HERETERM_LENGTH_BITS
|
||||
# define HERETERM_LENGTH_MAX ((1U << HERETERM_LENGTH_BITS) - 1)
|
||||
#else
|
||||
# define HERETERM_LENGTH_MAX UINT_MAX
|
||||
#endif
|
||||
;
|
||||
#if HERETERM_LENGTH_BITS < SIZEOF_INT * CHAR_BIT
|
||||
unsigned quote: 1;
|
||||
unsigned func: 8;
|
||||
#else
|
||||
unsigned length; /* the length of END in `<<"END"` */
|
||||
uint8_t quote;
|
||||
uint8_t func;
|
||||
#endif
|
||||
} rb_strterm_heredoc_t;
|
||||
STATIC_ASSERT(rb_strterm_heredoc_t, sizeof(rb_strterm_heredoc_t) <= 4 * SIZEOF_VALUE);
|
||||
|
||||
#define HERETERM_LENGTH_MAX UINT_MAX
|
||||
|
||||
typedef struct rb_strterm_struct {
|
||||
VALUE flags;
|
||||
union {
|
||||
|
20
parse.y
20
parse.y
@ -7852,7 +7852,7 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
|
||||
p->lex.pcur += numlen;
|
||||
if (p->lex.strterm == NULL ||
|
||||
(strterm_is_heredoc((VALUE)p->lex.strterm)) ||
|
||||
(p->lex.strterm->u.literal.u1.func != str_regexp)) {
|
||||
(p->lex.strterm->u.literal.func != str_regexp)) {
|
||||
if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) {
|
||||
literal_flush(p, p->lex.pcur);
|
||||
yyerror0("invalid Unicode escape");
|
||||
@ -7908,7 +7908,7 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp,
|
||||
if (regexp_literal) { tokadd(p, '\\'); tokadd(p, 'u'); }
|
||||
|
||||
if (peek(p, open_brace)) { /* handle \u{...} form */
|
||||
if (regexp_literal && p->lex.strterm->u.literal.u1.func == str_regexp) {
|
||||
if (regexp_literal && p->lex.strterm->u.literal.func == str_regexp) {
|
||||
/*
|
||||
* Skip parsing validation code and copy bytes as-is until term or
|
||||
* closing brace, in order to correctly handle extended regexps where
|
||||
@ -8567,9 +8567,9 @@ parser_string_term(struct parser_params *p, int func)
|
||||
static enum yytokentype
|
||||
parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
|
||||
{
|
||||
int func = (int)quote->u1.func;
|
||||
int term = (int)quote->u3.term;
|
||||
int paren = (int)quote->u2.paren;
|
||||
int func = (int)quote->func;
|
||||
int term = (int)quote->term;
|
||||
int paren = (int)quote->paren;
|
||||
int c, space = 0;
|
||||
rb_encoding *enc = p->enc;
|
||||
rb_encoding *base_enc = 0;
|
||||
@ -8587,12 +8587,12 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
|
||||
space = 1;
|
||||
}
|
||||
if (func & STR_FUNC_LIST) {
|
||||
quote->u1.func &= ~STR_FUNC_LIST;
|
||||
quote->func &= ~STR_FUNC_LIST;
|
||||
space = 1;
|
||||
}
|
||||
if (c == term && !quote->u0.nest) {
|
||||
if (c == term && !quote->nest) {
|
||||
if (func & STR_FUNC_QWORDS) {
|
||||
quote->u1.func |= STR_FUNC_TERM;
|
||||
quote->func |= STR_FUNC_TERM;
|
||||
pushback(p, c); /* dispatch the term at tSTRING_END */
|
||||
add_delayed_token(p, p->lex.ptok, p->lex.pcur, __LINE__);
|
||||
return ' ';
|
||||
@ -8612,7 +8612,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
|
||||
c = nextc(p);
|
||||
}
|
||||
pushback(p, c);
|
||||
if (tokadd_string(p, func, term, paren, "e->u0.nest,
|
||||
if (tokadd_string(p, func, term, paren, "e->nest,
|
||||
&enc, &base_enc) == -1) {
|
||||
if (p->eofp) {
|
||||
#ifndef RIPPER
|
||||
@ -8633,7 +8633,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
|
||||
else {
|
||||
unterminated_literal("unterminated string meets end of file");
|
||||
}
|
||||
quote->u1.func |= STR_FUNC_TERM;
|
||||
quote->func |= STR_FUNC_TERM;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user