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