From owner-svn-src-head@freebsd.org Wed Aug 3 16:33:36 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0D8B4BAE285; Wed, 3 Aug 2016 16:33:36 +0000 (UTC) (envelope-from pfg@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 mx1.freebsd.org (Postfix) with ESMTPS id DD14B1890; Wed, 3 Aug 2016 16:33:35 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u73GXZOs067095; Wed, 3 Aug 2016 16:33:35 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u73GXYKe067092; Wed, 3 Aug 2016 16:33:34 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201608031633.u73GXYKe067092@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Wed, 3 Aug 2016 16:33:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303718 - head/usr.bin/indent X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Aug 2016 16:33:36 -0000 Author: pfg Date: Wed Aug 3 16:33:34 2016 New Revision: 303718 URL: https://svnweb.freebsd.org/changeset/base/303718 Log: indent(1): accept offsetof(3) as a keyword. Reference: https://github.com/pstef/freebsd_indent/commit/c470e5e2c974aa38450ca4762b93829f7a7bfa4d Differential Revision: https://reviews.freebsd.org/D6966 (Partial) Submitted by: Piotr Stefaniak Modified: head/usr.bin/indent/indent.c head/usr.bin/indent/indent_globs.h head/usr.bin/indent/lexi.c Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Wed Aug 3 16:10:53 2016 (r303717) +++ head/usr.bin/indent/indent.c Wed Aug 3 16:33:34 2016 (r303718) @@ -510,8 +510,11 @@ check_type: case lparen: /* got a '(' or '[' */ ++ps.p_l_follow; /* count parens to make Healy happy */ if (ps.want_blank && *token != '[' && - (ps.last_token != ident || proc_calls_space - || (ps.its_a_keyword && (!ps.sizeof_keyword || Bill_Shannon)))) + (ps.last_token != ident || proc_calls_space || + /* offsetof (1) is never allowed a space; sizeof (2) gets + * one iff -bs; all other keywords (>2) always get a space + * before lparen */ + (ps.keyword + Bill_Shannon > 2))) *e_code++ = ' '; ps.want_blank = false; if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent && @@ -542,19 +545,20 @@ check_type: ps.in_or_st = false; /* turn off flag for structure decl or * initialization */ } - if (ps.sizeof_keyword) - ps.sizeof_mask |= 1 << ps.p_l_follow; + /* parenthesized type following sizeof or offsetof is not a cast */ + if (ps.keyword == 1 || ps.keyword == 2) + ps.not_cast_mask |= 1 << ps.p_l_follow; break; case rparen: /* got a ')' or ']' */ rparen_count--; - if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) { + if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) { ps.last_u_d = true; ps.cast_mask &= (1 << ps.p_l_follow) - 1; ps.want_blank = false; } else ps.want_blank = true; - ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; + ps.not_cast_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { ps.p_l_follow = 0; diag3(0, "Extra %c", *token); @@ -712,7 +716,7 @@ check_type: if (ps.last_token == rparen && rparen_count == 0) ps.in_parameter_declaration = 0; ps.cast_mask = 0; - ps.sizeof_mask = 0; + ps.not_cast_mask = 0; ps.block_init = 0; ps.block_init_level = 0; ps.just_saw_decl--; @@ -968,7 +972,7 @@ check_type: copy_id: if (ps.want_blank) *e_code++ = ' '; - if (troff && ps.its_a_keyword) { + if (troff && ps.keyword) { e_code = chfont(&bodyf, &keywordf, e_code); for (t_ptr = token; *t_ptr; ++t_ptr) { CHECK_SIZE_CODE; Modified: head/usr.bin/indent/indent_globs.h ============================================================================== --- head/usr.bin/indent/indent_globs.h Wed Aug 3 16:10:53 2016 (r303717) +++ head/usr.bin/indent/indent_globs.h Wed Aug 3 16:33:34 2016 (r303718) @@ -244,10 +244,10 @@ struct parser_state { * char should be lined up with the / in / followed by * */ int comment_delta, n_comment_delta; - int cast_mask; /* indicates which close parens close off - * casts */ - int sizeof_mask; /* indicates which close parens close off - * sizeof''s */ + int cast_mask; /* indicates which close parens potentially + * close off casts */ + int not_cast_mask; /* indicates which close parens definitely + * close off something else than casts */ int block_init; /* true iff inside a block initialization */ int block_init_level; /* The level of brace nesting in an * initialization */ @@ -317,8 +317,7 @@ struct parser_state { * specially */ int decl_indent; /* column to indent declared identifiers to */ int local_decl_indent; /* like decl_indent but for locals */ - int its_a_keyword; - int sizeof_keyword; + int keyword; /* the type of a keyword or 0 */ int dumped_decl_indent; float case_indent; /* The distance to indent case labels from the * switch statement */ Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Wed Aug 3 16:10:53 2016 (r303717) +++ head/usr.bin/indent/lexi.c Wed Aug 3 16:33:34 2016 (r303718) @@ -66,13 +66,13 @@ struct templ { struct templ specials[1000] = { - {"switch", 1}, - {"case", 2}, - {"break", 0}, + {"switch", 7}, + {"case", 8}, + {"break", 9}, {"struct", 3}, {"union", 3}, {"enum", 3}, - {"default", 2}, + {"default", 8}, {"int", 4}, {"char", 4}, {"float", 4}, @@ -88,14 +88,15 @@ struct templ specials[1000] = {"void", 4}, {"const", 4}, {"volatile", 4}, - {"goto", 0}, - {"return", 0}, + {"goto", 9}, + {"return", 9}, {"if", 5}, {"while", 5}, {"for", 5}, {"else", 6}, {"do", 6}, - {"sizeof", 7}, + {"sizeof", 2}, + {"offsetof", 1}, {0, 0} }; @@ -230,8 +231,7 @@ lexi(void) if (++buf_ptr >= buf_end) fill_buffer(); } - ps.its_a_keyword = false; - ps.sizeof_keyword = false; + ps.keyword = 0; if (l_struct && !ps.p_l_follow) { /* if last token was 'struct' and we're not * in parentheses, then this token @@ -253,7 +253,7 @@ lexi(void) /* Check if we have an "_t" in the end */ if (q_len > 2 && (strcmp(q + q_len - 2, "_t") == 0)) { - ps.its_a_keyword = true; + ps.keyword = 4; /* a type name */ ps.last_u_d = true; goto found_auto_typedef; } @@ -278,12 +278,12 @@ lexi(void) } if (p->rwd) { /* we have a keyword */ found_keyword: - ps.its_a_keyword = true; + ps.keyword = p->rwcode; ps.last_u_d = true; switch (p->rwcode) { - case 1: /* it is a switch */ + case 7: /* it is a switch */ return (swstmt); - case 2: /* a case or default */ + case 8: /* a case or default */ return (casestmt); case 3: /* a "struct" */ @@ -297,8 +297,9 @@ lexi(void) case 4: /* one of the declaration keywords */ found_auto_typedef: if (ps.p_l_follow) { - ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.sizeof_mask; - break; /* inside parens: cast, param list or sizeof */ + /* inside parens: cast, param list, offsetof or sizeof */ + ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.not_cast_mask; + break; } last_code = decl; return (decl); @@ -309,8 +310,6 @@ lexi(void) case 6: /* do, else */ return (sp_nparen); - case 7: - ps.sizeof_keyword = true; default: /* all others are treated like any other * identifier */ return (ident); @@ -337,7 +336,7 @@ lexi(void) && (ps.last_token == rparen || ps.last_token == semicolon || ps.last_token == decl || ps.last_token == lbrace || ps.last_token == rbrace)) { - ps.its_a_keyword = true; + ps.keyword = 4; /* a type name */ ps.last_u_d = true; last_code = decl; return decl;