Module Name: src Committed By: rillig Date: Sun Apr 24 08:48:17 UTC 2022
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/indent: Makefile lsym_lparen_or_lbracket.c lsym_rbrace.c Removed Files: src/tests/usr.bin/indent: token_lparen.c token_rbrace.c Log Message: tests/indent: migrate tests for parentheses, brackets, braces To generate a diff of this commit: cvs rdiff -u -r1.1196 -r1.1197 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.42 -r1.43 src/tests/usr.bin/indent/Makefile cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_rbrace.c cvs rdiff -u -r1.10 -r0 src/tests/usr.bin/indent/token_lparen.c cvs rdiff -u -r1.2 -r0 src/tests/usr.bin/indent/token_rbrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1196 src/distrib/sets/lists/tests/mi:1.1197 --- src/distrib/sets/lists/tests/mi:1.1196 Sat Apr 23 09:59:13 2022 +++ src/distrib/sets/lists/tests/mi Sun Apr 24 08:48:17 2022 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1196 2022/04/23 09:59:13 rillig Exp $ +# $NetBSD: mi,v 1.1197 2022/04/24 08:48:17 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5274,13 +5274,13 @@ ./usr/tests/usr.bin/indent/token_keyword_for_if_while.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_keyword_struct_union_enum.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_lbrace.c tests-obsolete obsolete,atf -./usr/tests/usr.bin/indent/token_lparen.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token_lparen.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token_newline.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_period.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token_postfix_op.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_preprocessing.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_question.c tests-obsolete obsolete,atf -./usr/tests/usr.bin/indent/token_rbrace.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token_rbrace.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token_rparen.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_semicolon.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_stmt.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/indent/Makefile diff -u src/tests/usr.bin/indent/Makefile:1.42 src/tests/usr.bin/indent/Makefile:1.43 --- src/tests/usr.bin/indent/Makefile:1.42 Sat Apr 23 09:59:14 2022 +++ src/tests/usr.bin/indent/Makefile Sun Apr 24 08:48:17 2022 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.42 2022/04/23 09:59:14 rillig Exp $ +# $NetBSD: Makefile,v 1.43 2022/04/24 08:48:17 rillig Exp $ .include <bsd.own.mk> @@ -124,11 +124,9 @@ FILES+= token_keyword_do_else.c FILES+= token_keyword_else.c FILES+= token_keyword_for_if_while.c FILES+= token_keyword_struct_union_enum.c -FILES+= token_lparen.c FILES+= token_newline.c FILES+= token_postfix_op.c FILES+= token_preprocessing.c -FILES+= token_rbrace.c FILES+= token_rparen.c FILES+= token_semicolon.c FILES+= token_stmt.c Index: src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.5 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.6 --- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.5 Sat Apr 23 17:25:58 2022 +++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sun Apr 24 08:48:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.5 2022/04/23 17:25:58 rillig Exp $ */ +/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.6 2022/04/24 08:48:17 rillig Exp $ */ /* * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '[' @@ -9,18 +9,20 @@ * In an expression, '(' starts an inner expression to override the usual * operator precedence. * - * In an expression, an identifier followed by '(' starts a function call - * expression. + * In a function call expression, '(' marks the beginning of the function + * arguments. * * In a 'sizeof' expression, '(' is required if the argument is a type name. * + * In an expression, '(' followed by a type name starts a cast expression or + * a compound literal. + * + * In a type declaration, '(' marks the beginning of the function parameters. + * * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling * expression must be enclosed in '(' and ')'; see lsym_for.c, lsym_if.c, * lsym_switch.c, lsym_while.c. * - * In an expression, '(' followed by a type name starts a cast expression or - * a compound literal. - * * In a declaration, '[' derives an array type. * * In an expression, '[' starts an array subscript. @@ -38,6 +40,13 @@ void (*signal(void (*)(int)))(int); #indent end +#indent input +#define macro(arg) ((arg) + 1) +#indent end + +#indent run-equals-input -di0 + + /* * The '(' in an expression overrides operator precedence. In multi-line * expressions, the continuation lines are aligned on the parentheses. @@ -134,4 +143,180 @@ function(void) #indent run-equals-input + +/* This is the maximum supported number of parentheses. */ +#indent input +int zero = (((((((((((((((((((0))))))))))))))))))); +#indent end + +#indent run-equals-input -di0 + + +#indent input +void (*action)(void); +#indent end + +#indent run-equals-input -di0 + + +#indent input +void +function(void) +{ + other_function(); + other_function("first", 2, "last argument"[4]); + + if (false)(void)x; + if (false)(func)(arg); + if (false)(cond)?123:456; + + /* C99 compound literal */ + origin = (struct point){0,0}; + + /* GCC statement expression */ + /* expr = ({if(expr)debug();expr;}); */ +/* $ XXX: Generates 'error: Standard Input:36: Unbalanced parentheses'. */ +} +#indent end + +#indent run +void +function(void) +{ + other_function(); + other_function("first", 2, "last argument"[4]); + + if (false) + (void)x; + if (false) + (func)(arg); + if (false) + (cond) ? 123 : 456; + + /* C99 compound literal */ + origin = (struct point){ + 0, 0 + }; + + /* GCC statement expression */ + /* expr = ({if(expr)debug();expr;}); */ +} +#indent end + + +/* + * C99 designator initializers are the rare situation where there is a space + * before a '['. + */ +#indent input +int array[] = { + 1, 2, [2] = 3, [3] = 4, +}; +#indent end + +#indent run-equals-input -di0 + + +/* + * Test want_blank_before_lparen for all possible token types. + */ +#indent input +void cover_want_blank_before_lparen(void) +{ + /* ps.prev_token can never be 'newline'. */ + int newline = + (3); + + int lparen_or_lbracket = a[(3)]; + int rparen_or_rbracket = a[3](5); + +(unary_op); + 3 + (binary_op); + a++(postfix_op); /* unlikely to be seen in practice */ + cond ? (question) : (5); + switch (expr) { + case (case_label):; + } + a ? 3 : (colon); + (semicolon) = 3; + int lbrace[] = {(3)}; + int rbrace_in_decl = {{3}(4)}; /* syntax error */ + {} + (rbrace_in_stmt)(); + ident(3); + int(decl); + a++, (comma)(); + int comment = /* comment */ (3); /* comment is skipped */ + switch (expr) {} +#define preprocessing + (preprocessing)(); + /* $ XXX: lsym_form_feed should be skipped, just as newline. */ + (lsym_form_feed)(); /* XXX: should be skipped */ + for(;;); + do(lsym_do)=3;while(0); + if(cond);else(lsym_else)(); + do(lsym_do);while(0); + str.(member); /* syntax error */ + L("string_prefix"); /* impossible */ + static (int)storage_class; /* syntax error */ + funcname(3); + typedef (type_def) new_type; + // $ TODO: is keyword_struct_union_enum possible? + struct (keyword_struct_union_enum); /* syntax error */ +} +#indent end + +#indent run -ldi0 +void +cover_want_blank_before_lparen(void) +{ + /* ps.prev_token can never be 'newline'. */ + int newline = + (3); + + int lparen_or_lbracket = a[(3)]; + int rparen_or_rbracket = a[3](5); + +(unary_op); + 3 + (binary_op); + a++ (postfix_op); /* unlikely to be seen in practice */ + cond ? (question) : (5); + switch (expr) { + case (case_label):; + } + a ? 3 : (colon); + (semicolon) = 3; + int lbrace[] = {(3)}; + int rbrace_in_decl = {{3} (4)}; /* syntax error */ + { + } + (rbrace_in_stmt)(); + ident(3); + int (decl); + a++, (comma)(); + int comment = /* comment */ (3); /* comment is skipped */ + switch (expr) { + } +#define preprocessing + (preprocessing)(); + +/* $ XXX: Where has the '\f' gone? It should have been preserved. */ + (lsym_form_feed)(); /* XXX: should be skipped */ + for (;;); + do + (lsym_do) = 3; + while (0); + if (cond); + else + (lsym_else)(); + do + (lsym_do); + while (0); + str.(member); /* syntax error */ + L("string_prefix"); /* impossible */ + static (int)storage_class; /* syntax error */ + funcname(3); + typedef (type_def) new_type; + struct (keyword_struct_union_enum); /* syntax error */ +} +#indent end + /* See t_errors.sh, test case 'compound_literal'. */ Index: src/tests/usr.bin/indent/lsym_rbrace.c diff -u src/tests/usr.bin/indent/lsym_rbrace.c:1.2 src/tests/usr.bin/indent/lsym_rbrace.c:1.3 --- src/tests/usr.bin/indent/lsym_rbrace.c:1.2 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/lsym_rbrace.c Sun Apr 24 08:48:17 2022 @@ -1,15 +1,77 @@ -/* $NetBSD: lsym_rbrace.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_rbrace.c,v 1.3 2022/04/24 08:48:17 rillig Exp $ */ /* - * Tests for the token lsym_rbrace, which represents '}', the counterpart to - * '{'. + * Tests for the token lsym_rbrace, which represents a '}' in these contexts: + * + * In an initializer, '}' ends an inner group of initializers, usually to + * initialize a nested struct, union or array. + * + * In a function body, '}' ends a block. + * + * In an expression like '(type){...}', '}' ends a compound literal, which is + * typically used in an assignment to a struct or array. + * + * In macro arguments, a '}' is an ordinary character, it does not need to be + * balanced. This is in contrast to '(' and ')', which must be balanced. + * + * TODO: try to split this token into lsym_rbrace_block and lsym_rbrace_init. * * See also: * lsym_lbrace.c */ +/* Brace level in an initializer */ #indent input -// TODO: add input +void +function(void) +{ + struct person p = { + .name = "Name", + .age = {{{35}}}, /* C11 6.7.9 allows this. */ + }; +} #indent end #indent run-equals-input + + +/* Begin of a block of statements */ +#indent input +void function(void) {{{ body(); }}} +#indent end + +#indent run +void +function(void) +/* $ FIXME: Each '{' must be properly indented. */ +{{{ + body(); +} +} +} +#indent end + + +/* Compound literal */ +#indent input +struct point +origin(void) +{ + return (struct point){ + .x = 0, + .y = 0, + }; +} +#indent end + +#indent run +struct point +origin(void) +{ + return (struct point){ + .x = 0, +/* $ FIXME: All initializers must be indented to the same level. */ + .y = 0, + }; +} +#indent end