svn commit: r334566 - in head/usr.bin/indent: . tests
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Sun Jun 3 16:43:00 UTC 2018
Author: pstef
Date: Sun Jun 3 16:42:58 2018
New Revision: 334566
URL: https://svnweb.freebsd.org/changeset/base/334566
Log:
indent(1): don't format function declarations as variables
Added:
head/usr.bin/indent/tests/f_decls.0 (contents, props changed)
head/usr.bin/indent/tests/f_decls.0.stdout (contents, props changed)
Modified:
head/usr.bin/indent/indent.c
head/usr.bin/indent/lexi.c
head/usr.bin/indent/tests/Makefile
Modified: head/usr.bin/indent/indent.c
==============================================================================
--- head/usr.bin/indent/indent.c Sun Jun 3 16:27:40 2018 (r334565)
+++ head/usr.bin/indent/indent.c Sun Jun 3 16:42:58 2018 (r334566)
@@ -1029,30 +1029,31 @@ check_type:
case funcname:
case ident: /* got an identifier or constant */
- if (ps.in_decl) { /* if we are in a declaration, we must indent
- * identifier */
- if (type_code != funcname || !procnames_start_line) {
- if (!ps.block_init && !ps.dumped_decl_indent && ps.paren_level == 0) {
- if (troff) {
- if (ps.want_blank)
- *e_code++ = ' ';
- sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
- e_code += strlen(e_code);
- } else
- indent_declaration(dec_ind, tabs_to_var);
- ps.dumped_decl_indent = true;
- ps.want_blank = false;
- }
- } else {
- if (ps.want_blank && !(procnames_start_line &&
- type_code == funcname))
- *e_code++ = ' ';
- ps.want_blank = false;
- if (dec_ind && s_code != e_code) {
+ if (ps.in_decl) {
+ if (type_code == funcname) {
+ ps.in_decl = false;
+ if (procnames_start_line && s_code != e_code) {
*e_code = '\0';
dump_line();
}
- dec_ind = 0;
+ else if (ps.want_blank) {
+ *e_code++ = ' ';
+ }
+ ps.want_blank = false;
+ }
+ else if (!ps.block_init && !ps.dumped_decl_indent &&
+ ps.paren_level == 0) { /* if we are in a declaration, we
+ * must indent identifier */
+
+ if (troff) {
+ if (ps.want_blank)
+ *e_code++ = ' ';
+ sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
+ e_code += strlen(e_code);
+ } else
+ indent_declaration(dec_ind, tabs_to_var);
+ ps.dumped_decl_indent = true;
+ ps.want_blank = false;
}
}
else if (sp_sw && ps.p_l_follow == 0) {
Modified: head/usr.bin/indent/lexi.c
==============================================================================
--- head/usr.bin/indent/lexi.c Sun Jun 3 16:27:40 2018 (r334565)
+++ head/usr.bin/indent/lexi.c Sun Jun 3 16:42:58 2018 (r334566)
@@ -367,12 +367,12 @@ lexi(struct parser_state *state)
* token is in fact a declaration keyword -- one that has been
* typedefd
*/
- if (((*buf_ptr == '*' && buf_ptr[1] != '=') || isalpha(*buf_ptr) || *buf_ptr == '_')
- && !state->p_l_follow
- && !state->block_init
- && (state->last_token == rparen || state->last_token == semicolon ||
- state->last_token == decl ||
- state->last_token == lbrace || state->last_token == rbrace)) {
+ else if (!state->p_l_follow && !state->block_init &&
+ !state->in_stmt &&
+ ((*buf_ptr == '*' && buf_ptr[1] != '=') ||
+ isalpha((unsigned char)*buf_ptr)) &&
+ (state->last_token == semicolon || state->last_token == lbrace ||
+ state->last_token == rbrace)) {
state->keyword = 4; /* a type name */
state->last_u_d = true;
return decl;
@@ -578,6 +578,34 @@ stop_lit:
*e_token++ = *buf_ptr++;
code = (state->last_u_d ? unary_op : binary_op);
unary_delim = true;
+ break;
+
+ case '*':
+ unary_delim = true;
+ if (!state->last_u_d) {
+ if (*buf_ptr == '=')
+ *e_token++ = *buf_ptr++;
+ code = binary_op;
+ break;
+ }
+ while (*buf_ptr == '*' || isspace((unsigned char)*buf_ptr)) {
+ if (*buf_ptr == '*')
+ *e_token++ = *buf_ptr;
+ if (++buf_ptr >= buf_end)
+ fill_buffer();
+ }
+ if (ps.in_decl) {
+ char *tp = buf_ptr;
+
+ while (isalpha((unsigned char)*tp) ||
+ isspace((unsigned char)*tp)) {
+ if (++tp >= buf_end)
+ fill_buffer();
+ }
+ if (*tp == '(')
+ ps.procname[0] = ' ';
+ }
+ code = unary_op;
break;
default:
Modified: head/usr.bin/indent/tests/Makefile
==============================================================================
--- head/usr.bin/indent/tests/Makefile Sun Jun 3 16:27:40 2018 (r334565)
+++ head/usr.bin/indent/tests/Makefile Sun Jun 3 16:42:58 2018 (r334566)
@@ -11,6 +11,8 @@ ${PACKAGE}FILES+= declarations.0.stdout
${PACKAGE}FILES+= elsecomment.0
${PACKAGE}FILES+= elsecomment.0.stdout
${PACKAGE}FILES+= elsecomment.0.pro
+${PACKAGE}FILES+= f_decls.0
+${PACKAGE}FILES+= f_decls.0.stdout
${PACKAGE}FILES+= float.0
${PACKAGE}FILES+= float.0.stdout
${PACKAGE}FILES+= label.0
Added: head/usr.bin/indent/tests/f_decls.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/usr.bin/indent/tests/f_decls.0 Sun Jun 3 16:42:58 2018 (r334566)
@@ -0,0 +1,29 @@
+/* $FreeBSD$ */
+
+char * x(void)
+{
+ type identifier;
+ type *pointer;
+ unused * value;
+ (void)unused * value;
+
+ dmax = (double)3 * 10.0;
+ dmin = (double)dmax * 10.0;
+ davg = (double)dmax * dmin;
+
+ return NULL;
+}
+
+int *
+y(void) {
+
+}
+
+int
+z(void) {
+
+}
+
+int x;
+int *y;
+int * * * * z;
Added: head/usr.bin/indent/tests/f_decls.0.stdout
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/usr.bin/indent/tests/f_decls.0.stdout Sun Jun 3 16:42:58 2018 (r334566)
@@ -0,0 +1,32 @@
+/* $FreeBSD$ */
+
+char *
+x(void)
+{
+ type identifier;
+ type *pointer;
+ unused *value;
+ (void)unused * value;
+
+ dmax = (double)3 * 10.0;
+ dmin = (double)dmax * 10.0;
+ davg = (double)dmax * dmin;
+
+ return NULL;
+}
+
+int *
+y(void)
+{
+
+}
+
+int
+z(void)
+{
+
+}
+
+int x;
+int *y;
+int ****z;
More information about the svn-src-all
mailing list