[BACK]Return to token_preprocessing.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / usr.bin / indent

Annotation of src/tests/usr.bin/indent/token_preprocessing.c, Revision 1.1

1.1     ! rillig      1: /* $NetBSD: token-preprocessing.0,v 1.6 2021/10/09 10:56:13 rillig Exp $ */
        !             2: /* $FreeBSD$ */
        !             3:
        !             4: /*-
        !             5:  * Tests for indenting preprocessing directives:
        !             6:  *
        !             7:  * #define
        !             8:  * #ifdef
        !             9:  * #pragma
        !            10:  * #line
        !            11:  */
        !            12:
        !            13:
        !            14: #indent input
        !            15: #include <system-header.h>
        !            16: #include "local-header.h"
        !            17: #indent end
        !            18:
        !            19: #indent run-equals-input
        !            20:
        !            21:
        !            22: /*
        !            23:  * Nested conditional compilation.
        !            24:  */
        !            25: #indent input
        !            26: #if 0
        !            27: #else
        !            28: #endif
        !            29:
        !            30: #if 0 /* if comment */
        !            31: #else /* else comment */
        !            32: #endif /* endif comment */
        !            33:
        !            34: #if 0 /* outer if comment */
        !            35: #  if nested /* inner if comment */
        !            36: #  else /* inner else comment */
        !            37: #  endif /* inner endif comment */
        !            38: #endif /* outer endif comment */
        !            39: #indent end
        !            40:
        !            41: #indent run
        !            42: #if 0
        !            43: #else
        !            44: #endif
        !            45:
        !            46: #if 0                          /* if comment */
        !            47: #else                          /* else comment */
        !            48: #endif                         /* endif comment */
        !            49:
        !            50: #if 0                          /* outer if comment */
        !            51: /* $ XXX: The indentation is removed, which can get confusing */
        !            52: #if nested                     /* inner if comment */
        !            53: #else                          /* inner else comment */
        !            54: #endif                         /* inner endif comment */
        !            55: #endif                         /* outer endif comment */
        !            56: #indent end
        !            57:
        !            58:
        !            59: #indent input
        !            60: #define multi_line_definition /* first line
        !            61:  * middle
        !            62:  * final line
        !            63:  */ actual_value
        !            64: #indent end
        !            65:
        !            66: #indent run-equals-input
        !            67:
        !            68:
        !            69: /*
        !            70:  * Before indent.c 1.129 from 2021-10-08, indent mistakenly interpreted quotes
        !            71:  * in comments as starting a string literal. The '"' in the comment started a
        !            72:  * string, the next '"' finished the string, and the following '/' '*' was
        !            73:  * interpreted as the beginning of a comment. This comment lasted until the
        !            74:  * next '*' '/', which in this test is another preprocessor directive, solely
        !            75:  * for symmetry.
        !            76:  *
        !            77:  * The effect was that the extra space after d2 was not formatted, as that
        !            78:  * line was considered part of the comment.
        !            79:  */
        !            80: #indent input
        !            81: #define comment_in_string_literal "/* no comment "
        !            82: int this_is_an_ordinary_line_again;
        !            83:
        !            84: int d1 ;
        !            85: #define confuse_d /*"*/ "/*"
        !            86: int d2 ;
        !            87: #define resolve_d "*/"
        !            88: int d3 ;
        !            89:
        !            90: int s1 ;
        !            91: #define confuse_s /*'*/ '/*'
        !            92: int s2 ;
        !            93: #define resolve_s '*/'
        !            94: int s3 ;
        !            95: #indent end
        !            96:
        !            97: #indent run
        !            98: #define comment_in_string_literal "/* no comment "
        !            99: int            this_is_an_ordinary_line_again;
        !           100:
        !           101: int            d1;
        !           102: #define confuse_d /*"*/ "/*"
        !           103: int            d2;
        !           104: #define resolve_d "*/"
        !           105: int            d3;
        !           106:
        !           107: int            s1;
        !           108: #define confuse_s /*'*/ '/*'
        !           109: int            s2;
        !           110: #define resolve_s '*/'
        !           111: int            s3;
        !           112: #indent end
        !           113:
        !           114:
        !           115: /*
        !           116:  * A preprocessing directive inside an expression keeps the state about
        !           117:  * whether the next operator is unary or binary.
        !           118:  */
        !           119: #indent input
        !           120: int binary_plus = 3
        !           121: #define intermediate 1
        !           122:        +4;
        !           123: int unary_plus =
        !           124: #define intermediate 1
        !           125:        + 4;
        !           126: #indent end
        !           127:
        !           128: #indent run
        !           129: int            binary_plus = 3
        !           130: #define intermediate 1
        !           131: + 4;
        !           132: int            unary_plus =
        !           133: #define intermediate 1
        !           134: +4;
        !           135: #indent end
        !           136:
        !           137:
        !           138: /*
        !           139:  * Preprocessing lines that don't expect an argument but have one are fixed.
        !           140:  * They are indented with a single tab.
        !           141:  */
        !           142: #indent input
        !           143: #if 0
        !           144: #elif 1
        !           145: #else if 3
        !           146: #endif 0
        !           147: #indent end
        !           148:
        !           149: #indent run
        !           150: #if 0
        !           151: #elif 1
        !           152: #else  /* if 3 */
        !           153: #endif /* 0 */
        !           154: #indent end
        !           155:
        !           156:
        !           157: /*
        !           158:  * Existing comments are indented just like code comments.
        !           159:  *
        !           160:  * This means that the above wrong preprocessing lines (#else with argument)
        !           161:  * need to be fed through indent twice until they become stable. Since
        !           162:  * compilers issue warnings about these invalid lines, not much code still has
        !           163:  * these, making this automatic fix an edge case.
        !           164:  */
        !           165: #indent input
        !           166: #if 0          /* comment */
        !           167: #else          /* comment */
        !           168: #endif         /* comment */
        !           169:
        !           170: #if 0/* comment */
        !           171: #else/* comment */
        !           172: #endif/* comment */
        !           173: #indent end
        !           174:
        !           175: #indent run
        !           176: #if 0                          /* comment */
        !           177: #else                          /* comment */
        !           178: #endif                         /* comment */
        !           179:
        !           180: #if 0                          /* comment */
        !           181: #else                          /* comment */
        !           182: #endif                         /* comment */
        !           183: #indent end

CVSweb <webmaster@jp.NetBSD.org>