indent(1): disjoint parser state from lexi()
The function is sometimes used as a look-ahead, so ideally it should bear no information about parser state.
This commit is contained in:
parent
d51ca1681c
commit
72a53430c7
@ -995,6 +995,9 @@ main(int argc, char **argv)
|
|||||||
prefix_blankline_requested = 0;
|
prefix_blankline_requested = 0;
|
||||||
goto copy_id;
|
goto copy_id;
|
||||||
|
|
||||||
|
case structure:
|
||||||
|
if (ps.p_l_follow > 0)
|
||||||
|
goto copy_id;
|
||||||
case decl: /* we have a declaration type (int, etc.) */
|
case decl: /* we have a declaration type (int, etc.) */
|
||||||
parse(decl); /* let parser worry about indentation */
|
parse(decl); /* let parser worry about indentation */
|
||||||
if (ps.last_token == rparen && ps.tos <= 1) {
|
if (ps.last_token == rparen && ps.tos <= 1) {
|
||||||
|
@ -74,4 +74,4 @@
|
|||||||
#define storage 34
|
#define storage 34
|
||||||
#define funcname 35
|
#define funcname 35
|
||||||
#define type_def 36
|
#define type_def 36
|
||||||
|
#define structure 37
|
||||||
|
@ -145,8 +145,6 @@ lexi(struct parser_state *state)
|
|||||||
{
|
{
|
||||||
int unary_delim; /* this is set to 1 if the current token
|
int unary_delim; /* this is set to 1 if the current token
|
||||||
* forces a following operator to be unary */
|
* forces a following operator to be unary */
|
||||||
static int last_code; /* the last token type returned */
|
|
||||||
static int l_struct; /* set to 1 if the last token was 'struct' */
|
|
||||||
int code; /* internal code to be returned */
|
int code; /* internal code to be returned */
|
||||||
char qchar; /* the delimiter character for a string */
|
char qchar; /* the delimiter character for a string */
|
||||||
|
|
||||||
@ -283,21 +281,17 @@ lexi(struct parser_state *state)
|
|||||||
fill_buffer();
|
fill_buffer();
|
||||||
}
|
}
|
||||||
state->keyword = 0;
|
state->keyword = 0;
|
||||||
if (l_struct && !state->p_l_follow) {
|
if (state->last_token == structure && !state->p_l_follow) {
|
||||||
/* if last token was 'struct' and we're not
|
/* if last token was 'struct' and we're not
|
||||||
* in parentheses, then this token
|
* in parentheses, then this token
|
||||||
* should be treated as a declaration */
|
* should be treated as a declaration */
|
||||||
l_struct = false;
|
|
||||||
last_code = ident;
|
|
||||||
state->last_u_d = true;
|
state->last_u_d = true;
|
||||||
return (decl);
|
return (decl);
|
||||||
}
|
}
|
||||||
state->last_u_d = l_struct; /* Operator after identifier is
|
/*
|
||||||
* binary unless last token was
|
* Operator after identifier is binary unless last token was 'struct'
|
||||||
* 'struct' */
|
*/
|
||||||
l_struct = false;
|
state->last_u_d = (state->last_token == structure);
|
||||||
last_code = ident; /* Remember that this is the code we will
|
|
||||||
* return */
|
|
||||||
|
|
||||||
p = bsearch(s_token,
|
p = bsearch(s_token,
|
||||||
specials,
|
specials,
|
||||||
@ -326,21 +320,17 @@ lexi(struct parser_state *state)
|
|||||||
return (casestmt);
|
return (casestmt);
|
||||||
|
|
||||||
case 3: /* a "struct" */
|
case 3: /* a "struct" */
|
||||||
/*
|
|
||||||
* Next time around, we will want to know that we have had a
|
|
||||||
* 'struct'
|
|
||||||
*/
|
|
||||||
l_struct = true;
|
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
case 4: /* one of the declaration keywords */
|
case 4: /* one of the declaration keywords */
|
||||||
found_typename:
|
found_typename:
|
||||||
if (state->p_l_follow) {
|
if (state->p_l_follow) {
|
||||||
/* inside parens: cast, param list, offsetof or sizeof */
|
/* inside parens: cast, param list, offsetof or sizeof */
|
||||||
state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask;
|
state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
last_code = decl;
|
if (p != NULL && p->rwcode == 3)
|
||||||
|
return (structure);
|
||||||
|
if (state->p_l_follow)
|
||||||
|
break;
|
||||||
return (decl);
|
return (decl);
|
||||||
|
|
||||||
case 5: /* if, while, for */
|
case 5: /* if, while, for */
|
||||||
@ -369,7 +359,7 @@ lexi(struct parser_state *state)
|
|||||||
strncpy(state->procname, token, sizeof state->procname - 1);
|
strncpy(state->procname, token, sizeof state->procname - 1);
|
||||||
if (state->in_decl)
|
if (state->in_decl)
|
||||||
state->in_parameter_declaration = 1;
|
state->in_parameter_declaration = 1;
|
||||||
return (last_code = funcname);
|
return (funcname);
|
||||||
not_proc:;
|
not_proc:;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -385,13 +375,11 @@ lexi(struct parser_state *state)
|
|||||||
state->last_token == lbrace || state->last_token == rbrace)) {
|
state->last_token == lbrace || state->last_token == rbrace)) {
|
||||||
state->keyword = 4; /* a type name */
|
state->keyword = 4; /* a type name */
|
||||||
state->last_u_d = true;
|
state->last_u_d = true;
|
||||||
last_code = decl;
|
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
if (last_code == decl) /* if this is a declared variable, then
|
if (state->last_token == decl) /* if this is a declared variable,
|
||||||
* following sign is unary */
|
* then following sign is unary */
|
||||||
state->last_u_d = true; /* will make "int a -1" work */
|
state->last_u_d = true; /* will make "int a -1" work */
|
||||||
last_code = ident;
|
|
||||||
return (ident); /* the ident is not in the list */
|
return (ident); /* the ident is not in the list */
|
||||||
} /* end of procesing for alpanum character */
|
} /* end of procesing for alpanum character */
|
||||||
|
|
||||||
@ -536,7 +524,7 @@ lexi(struct parser_state *state)
|
|||||||
/* check for doubled character */
|
/* check for doubled character */
|
||||||
*e_token++ = *buf_ptr++;
|
*e_token++ = *buf_ptr++;
|
||||||
/* buffer overflow will be checked at end of loop */
|
/* buffer overflow will be checked at end of loop */
|
||||||
if (last_code == ident || last_code == rparen) {
|
if (state->last_token == ident || state->last_token == rparen) {
|
||||||
code = (state->last_u_d ? unary_op : postop);
|
code = (state->last_u_d ? unary_op : postop);
|
||||||
/* check for following ++ or -- */
|
/* check for following ++ or -- */
|
||||||
unary_delim = false;
|
unary_delim = false;
|
||||||
@ -617,10 +605,6 @@ lexi(struct parser_state *state)
|
|||||||
|
|
||||||
|
|
||||||
} /* end of switch */
|
} /* end of switch */
|
||||||
if (code != newline) {
|
|
||||||
l_struct = false;
|
|
||||||
last_code = code;
|
|
||||||
}
|
|
||||||
if (buf_ptr >= buf_end) /* check for input buffer empty */
|
if (buf_ptr >= buf_end) /* check for input buffer empty */
|
||||||
fill_buffer();
|
fill_buffer();
|
||||||
state->last_u_d = unary_delim;
|
state->last_u_d = unary_delim;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
/* $FreeBSD$ */
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
|
int f(struct x *a);
|
||||||
|
|
||||||
/* See r303485 */
|
/* See r303485 */
|
||||||
void
|
void
|
||||||
t(void)
|
t(void)
|
||||||
@ -11,3 +14,8 @@ t(void)
|
|||||||
{ F, G }
|
{ F, G }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void u(struct x a) {
|
||||||
|
int b;
|
||||||
|
struct y c = (struct y *)&a;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
/* $FreeBSD$ */
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
|
int f(struct x *a);
|
||||||
|
|
||||||
/* See r303485 */
|
/* See r303485 */
|
||||||
void
|
void
|
||||||
t(void)
|
t(void)
|
||||||
@ -11,3 +14,10 @@ t(void)
|
|||||||
{F, G}
|
{F, G}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
u(struct x a)
|
||||||
|
{
|
||||||
|
int b;
|
||||||
|
struct y c = (struct y *)&a;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user