From owner-svn-src-head@freebsd.org Thu May 18 17:16:00 2017 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 468A7D735FA; Thu, 18 May 2017 17:16:00 +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 mx1.freebsd.org (Postfix) with ESMTPS id 210A2D8C; Thu, 18 May 2017 17:16:00 +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 v4IHFxNi033852; Thu, 18 May 2017 17:15:59 GMT (envelope-from pstef@FreeBSD.org) Received: (from pstef@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4IHFwwN033848; Thu, 18 May 2017 17:15:58 GMT (envelope-from pstef@FreeBSD.org) Message-Id: <201705181715.v4IHFwwN033848@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pstef set sender to pstef@FreeBSD.org using -f From: Piotr Pawel Stefaniak Date: Thu, 18 May 2017 17:15:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318471 - in head/usr.bin/indent: . tests 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.23 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: Thu, 18 May 2017 17:16:00 -0000 Author: pstef Date: Thu May 18 17:15:58 2017 New Revision: 318471 URL: https://svnweb.freebsd.org/changeset/base/318471 Log: indent(1): Support binary integer literals. This was done by Romain Tartière for PR123553. I initially thought that it would break code like this: #define b00101010 -1 if (0 b00101010) ... by joining 0 and b00101010 together. However, the real problem with that patch was that once it saw a 0, it assumed that the number was base 2, 8 or 16, ignoring base 10 floating point numbers. I fixed that. I didn't copy the diagnostic part of the original patch as it seems out of scope of implementing binary integer literals formatting. PR: 123553 Submitted by: romain (original version) Approved by: pfg (mentor) Added: head/usr.bin/indent/tests/binary.0 (contents, props changed) head/usr.bin/indent/tests/binary.0.stdout (contents, props changed) Modified: head/usr.bin/indent/lexi.c head/usr.bin/indent/tests/Makefile Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Thu May 18 17:01:26 2017 (r318470) +++ head/usr.bin/indent/lexi.c Thu May 18 17:15:58 2017 (r318471) @@ -169,19 +169,47 @@ lexi(void) struct templ *p; if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { + enum base { + BASE_2, BASE_8, BASE_10, BASE_16 + }; int seendot = 0, seenexp = 0, seensfx = 0; - if (*buf_ptr == '0' && - (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) { + enum base in_base = BASE_10; + + if (*buf_ptr == '0') { + if (buf_ptr[1] == 'b' || buf_ptr[1] == 'B') + in_base = BASE_2; + else if (buf_ptr[1] == 'x' || buf_ptr[1] == 'X') + in_base = BASE_16; + else if (isdigit(buf_ptr[1])) + in_base = BASE_8; + } + switch (in_base) { + case BASE_2: + *e_token++ = *buf_ptr++; + *e_token++ = *buf_ptr++; + while (*buf_ptr == '0' || *buf_ptr == '1') { + CHECK_SIZE_TOKEN; + *e_token++ = *buf_ptr++; + } + break; + case BASE_8: + *e_token++ = *buf_ptr++; + while (*buf_ptr >= '0' && *buf_ptr <= '8') { + CHECK_SIZE_TOKEN; + *e_token++ = *buf_ptr++; + } + break; + case BASE_16: *e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++; while (isxdigit(*buf_ptr)) { CHECK_SIZE_TOKEN; *e_token++ = *buf_ptr++; } - } - else + break; + case BASE_10: while (1) { if (*buf_ptr == '.') { if (seendot) @@ -204,6 +232,8 @@ lexi(void) } } } + break; + } while (1) { if (!(seensfx & 1) && (*buf_ptr == 'U' || *buf_ptr == 'u')) { CHECK_SIZE_TOKEN; Modified: head/usr.bin/indent/tests/Makefile ============================================================================== --- head/usr.bin/indent/tests/Makefile Thu May 18 17:01:26 2017 (r318470) +++ head/usr.bin/indent/tests/Makefile Thu May 18 17:15:58 2017 (r318471) @@ -2,6 +2,8 @@ PACKAGE= tests +${PACKAGE}FILES+= binary.0 +${PACKAGE}FILES+= binary.0.stdout ${PACKAGE}FILES+= comments.0 ${PACKAGE}FILES+= comments.0.stdout ${PACKAGE}FILES+= declarations.0 Added: head/usr.bin/indent/tests/binary.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/binary.0 Thu May 18 17:15:58 2017 (r318471) @@ -0,0 +1,10 @@ +/* $FreeBSD$ */ +#define b00101010 -1 +void t(void) { + unsigned a[] = {0b00101010, 0x00005678, 02, 17U}; + float x[] = {.7f, 0.7f}; + unsigned long ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL}; + + if (0 b00101010) + return; +} Added: head/usr.bin/indent/tests/binary.0.stdout ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/binary.0.stdout Thu May 18 17:15:58 2017 (r318471) @@ -0,0 +1,12 @@ +/* $FreeBSD$ */ +#define b00101010 -1 +void +t(void) +{ + unsigned a[] = {0b00101010, 0x00005678, 02, 17U}; + float x[] = {.7f, 0.7f}; + unsigned long ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL}; + + if (0 b00101010) + return; +}