From owner-svn-src-all@freebsd.org Sun Jun 3 16:21:17 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D3ED5FD582E; Sun, 3 Jun 2018 16:21:16 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8A1656D41C; Sun, 3 Jun 2018 16:21:16 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6C67C20ED4; Sun, 3 Jun 2018 16:21:16 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w53GLGRr077471; Sun, 3 Jun 2018 16:21:16 GMT (envelope-from pstef@FreeBSD.org) Received: (from pstef@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w53GLFWj077466; Sun, 3 Jun 2018 16:21:15 GMT (envelope-from pstef@FreeBSD.org) Message-Id: <201806031621.w53GLFWj077466@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pstef set sender to pstef@FreeBSD.org using -f From: Piotr Pawel Stefaniak Date: Sun, 3 Jun 2018 16:21:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334564 - in head/usr.bin/indent: . tests X-SVN-Group: head X-SVN-Commit-Author: pstef X-SVN-Commit-Paths: in head/usr.bin/indent: . tests X-SVN-Commit-Revision: 334564 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jun 2018 16:21:17 -0000 Author: pstef Date: Sun Jun 3 16:21:15 2018 New Revision: 334564 URL: https://svnweb.freebsd.org/changeset/base/334564 Log: 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. Modified: head/usr.bin/indent/indent.c head/usr.bin/indent/indent_codes.h head/usr.bin/indent/lexi.c head/usr.bin/indent/tests/struct.0 head/usr.bin/indent/tests/struct.0.stdout Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Sun Jun 3 15:28:55 2018 (r334563) +++ head/usr.bin/indent/indent.c Sun Jun 3 16:21:15 2018 (r334564) @@ -995,6 +995,9 @@ check_type: prefix_blankline_requested = 0; goto copy_id; + case structure: + if (ps.p_l_follow > 0) + goto copy_id; case decl: /* we have a declaration type (int, etc.) */ parse(decl); /* let parser worry about indentation */ if (ps.last_token == rparen && ps.tos <= 1) { Modified: head/usr.bin/indent/indent_codes.h ============================================================================== --- head/usr.bin/indent/indent_codes.h Sun Jun 3 15:28:55 2018 (r334563) +++ head/usr.bin/indent/indent_codes.h Sun Jun 3 16:21:15 2018 (r334564) @@ -74,4 +74,4 @@ #define storage 34 #define funcname 35 #define type_def 36 - +#define structure 37 Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Sun Jun 3 15:28:55 2018 (r334563) +++ head/usr.bin/indent/lexi.c Sun Jun 3 16:21:15 2018 (r334564) @@ -145,8 +145,6 @@ lexi(struct parser_state *state) { int unary_delim; /* this is set to 1 if the current token * 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 */ char qchar; /* the delimiter character for a string */ @@ -283,21 +281,17 @@ lexi(struct parser_state *state) fill_buffer(); } 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 * in parentheses, then this token * should be treated as a declaration */ - l_struct = false; - last_code = ident; state->last_u_d = true; return (decl); } - state->last_u_d = l_struct; /* Operator after identifier is - * binary unless last token was - * 'struct' */ - l_struct = false; - last_code = ident; /* Remember that this is the code we will - * return */ + /* + * Operator after identifier is binary unless last token was 'struct' + */ + state->last_u_d = (state->last_token == structure); p = bsearch(s_token, specials, @@ -326,21 +320,17 @@ lexi(struct parser_state *state) return (casestmt); case 3: /* a "struct" */ - /* - * Next time around, we will want to know that we have had a - * 'struct' - */ - l_struct = true; /* FALLTHROUGH */ - case 4: /* one of the declaration keywords */ found_typename: if (state->p_l_follow) { /* inside parens: cast, param list, offsetof or sizeof */ 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); case 5: /* if, while, for */ @@ -369,7 +359,7 @@ lexi(struct parser_state *state) strncpy(state->procname, token, sizeof state->procname - 1); if (state->in_decl) state->in_parameter_declaration = 1; - return (last_code = funcname); + return (funcname); not_proc:; } /* @@ -385,13 +375,11 @@ lexi(struct parser_state *state) state->last_token == lbrace || state->last_token == rbrace)) { state->keyword = 4; /* a type name */ state->last_u_d = true; - last_code = decl; return decl; } - if (last_code == decl) /* if this is a declared variable, then - * following sign is unary */ + if (state->last_token == decl) /* if this is a declared variable, + * then following sign is unary */ state->last_u_d = true; /* will make "int a -1" work */ - last_code = ident; return (ident); /* the ident is not in the list */ } /* end of procesing for alpanum character */ @@ -536,7 +524,7 @@ stop_lit: /* check for doubled character */ *e_token++ = *buf_ptr++; /* 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); /* check for following ++ or -- */ unary_delim = false; @@ -617,10 +605,6 @@ stop_lit: } /* end of switch */ - if (code != newline) { - l_struct = false; - last_code = code; - } if (buf_ptr >= buf_end) /* check for input buffer empty */ fill_buffer(); state->last_u_d = unary_delim; Modified: head/usr.bin/indent/tests/struct.0 ============================================================================== --- head/usr.bin/indent/tests/struct.0 Sun Jun 3 15:28:55 2018 (r334563) +++ head/usr.bin/indent/tests/struct.0 Sun Jun 3 16:21:15 2018 (r334564) @@ -1,4 +1,7 @@ /* $FreeBSD$ */ + +int f(struct x *a); + /* See r303485 */ void t(void) @@ -10,4 +13,9 @@ t(void) { D, E }, { F, G } }; +} + +void u(struct x a) { + int b; + struct y c = (struct y *)&a; } Modified: head/usr.bin/indent/tests/struct.0.stdout ============================================================================== --- head/usr.bin/indent/tests/struct.0.stdout Sun Jun 3 15:28:55 2018 (r334563) +++ head/usr.bin/indent/tests/struct.0.stdout Sun Jun 3 16:21:15 2018 (r334564) @@ -1,4 +1,7 @@ /* $FreeBSD$ */ + +int f(struct x *a); + /* See r303485 */ void t(void) @@ -10,4 +13,11 @@ t(void) {D, E}, {F, G} }; +} + +void +u(struct x a) +{ + int b; + struct y c = (struct y *)&a; }