Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: for the token types, use enum instead...



details:   https://anonhg.NetBSD.org/src/rev/3ad3bbbe7660
branches:  trunk
changeset: 953366:3ad3bbbe7660
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 07 10:56:18 2021 +0000

description:
indent: for the token types, use enum instead of #define

This makes it easier to step through the code in a debugger.

No functional change.

diffstat:

 usr.bin/indent/Makefile       |   4 +-
 usr.bin/indent/indent.c       |  17 +++++---
 usr.bin/indent/indent.h       |   8 ++--
 usr.bin/indent/indent_codes.h |  79 ++++++++++++++++++++++--------------------
 usr.bin/indent/indent_globs.h |   6 +-
 usr.bin/indent/lexi.c         |  10 ++--
 usr.bin/indent/parse.c        |   4 +-
 7 files changed, 68 insertions(+), 60 deletions(-)

diffs (284 lines):

diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/Makefile
--- a/usr.bin/indent/Makefile   Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/Makefile   Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.7 2019/04/04 15:22:13 kamil Exp $
+#      $NetBSD: Makefile,v 1.8 2021/03/07 10:56:18 rillig Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
 
 PROG=  indent
@@ -6,4 +6,6 @@
 
 COPTS.io.c += -Wno-error=format-nonliteral
 
+LINTFLAGS+=    -e
+
 .include <bsd.prog.mk>
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/indent.c   Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -143,8 +143,8 @@
     int         dec_ind;       /* current indentation for declarations */
     int         di_stack[20];  /* a stack of structure indentation levels */
     int         force_nl;      /* when true, code must be broken */
-    int         hd_type = 0;   /* used to store type of stmt for if (...),
-                                * for (...), etc */
+    token_type  hd_type = end_of_file; /* used to store type of stmt
+                                * for if (...), for (...), etc */
     int                i;              /* local loop counter */
     int         scase;         /* set to true when we see a case, so we will
                                 * know what to do with the following colon */
@@ -155,7 +155,7 @@
                                 * construct */
     const char *t_ptr;         /* used for copying tokens */
     int                tabs_to_var;    /* true if using tabs to indent to var name */
-    int         type_code;     /* the type of token, returned by lexi */
+    token_type type_code;      /* returned by lexi */
 
     int         last_else = 0; /* true iff last keyword was an else */
     const char *profile_name = NULL;
@@ -505,7 +505,7 @@
             * We must make this check, just in case there was an unexpected
             * EOF.
             */
-           if (type_code != 0) {
+           if (type_code != end_of_file) {
                /*
                 * The only intended purpose of calling lexi() below is to
                 * categorize the next token in order to decide whether to
@@ -546,7 +546,7 @@
        }                       /* end of while (search_brace) */
        last_else = 0;
 check_type:
-       if (type_code == 0) {   /* we got eof */
+       if (type_code == end_of_file) { /* we got eof */
            if (s_lab != e_lab || s_code != e_code
                    || s_com != e_com)  /* must dump end of line */
                dump_line();
@@ -1274,6 +1274,9 @@
        case comment:           /* we have gotten a / followed by * this is a biggie */
            pr_comment();
            break;
+
+       default:
+           break;
        }                       /* end of big switch stmt */
 
        *e_code = '\0';         /* make sure code section is null terminated */
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/indent.h   Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $        */
+/*     $NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
 
 #if 0
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
 #endif
@@ -50,11 +50,11 @@
 int    count_spaces(int, char *);
 int    count_spaces_until(int, char *, char *);
 void   init_constant_tt(void);
-int    lexi(struct parser_state *);
+token_type lexi(struct parser_state *);
 void   diag(int, const char *, ...) __printflike(2, 3);
 void   dump_line(void);
 void   fill_buffer(void);
-void   parse(int);
+void   parse(token_type);
 void   pr_comment(void);
 void   set_defaults(void);
 void   set_option(char *);
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/indent_codes.h
--- a/usr.bin/indent/indent_codes.h     Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/indent_codes.h     Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_codes.h,v 1.6 2019/04/04 15:22:13 kamil Exp $   */
+/*     $NetBSD: indent_codes.h,v 1.7 2021/03/07 10:56:18 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -40,40 +40,43 @@
  * $FreeBSD: head/usr.bin/indent/indent_codes.h 334564 2018-06-03 16:21:15Z pstef $
  */
 
-#define newline                1
-#define lparen         2
-#define rparen         3
-#define unary_op       4
-#define binary_op      5
-#define postop         6
-#define question       7
-#define casestmt       8
-#define colon          9
-#define semicolon      10
-#define lbrace         11
-#define rbrace         12
-#define ident          13
-#define comma          14
-#define comment                15
-#define swstmt         16
-#define preesc         17
-#define form_feed      18
-#define decl           19
-#define sp_paren       20
-#define sp_nparen      21
-#define ifstmt         22
-#define whilestmt      23
-#define forstmt                24
-#define stmt           25
-#define stmtl          26
-#define elselit                27
-#define dolit          28
-#define dohead         29
-#define ifhead         30
-#define elsehead       31
-#define period         32
-#define strpfx         33
-#define storage                34
-#define funcname       35
-#define type_def       36
-#define structure      37
+typedef enum token_type {
+    end_of_file,
+    newline,
+    lparen,
+    rparen,
+    unary_op,
+    binary_op,
+    postop,
+    question,
+    casestmt,
+    colon,
+    semicolon,
+    lbrace,
+    rbrace,
+    ident,
+    comma,
+    comment,
+    swstmt,
+    preesc,
+    form_feed,
+    decl,
+    sp_paren,
+    sp_nparen,
+    ifstmt,
+    whilestmt,
+    forstmt,
+    stmt,
+    stmtl,
+    elselit,
+    dolit,
+    dohead,
+    ifhead,
+    elsehead,
+    period,
+    strpfx,
+    storage,
+    funcname,
+    type_def,
+    structure
+} token_type;
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/indent_globs.h     Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_globs.h,v 1.12 2020/04/23 00:17:34 joerg Exp $  */
+/*     $NetBSD: indent_globs.h,v 1.13 2021/03/07 10:56:18 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -239,8 +239,8 @@
 #define        STACKSIZE 256
 
 extern struct parser_state {
-    int         last_token;
-    int         p_stack[STACKSIZE];    /* this is the parsers stack */
+    token_type  last_token;
+    token_type p_stack[STACKSIZE];     /* this is the parsers stack */
     int         il[STACKSIZE]; /* this stack stores indentation levels */
     float       cstk[STACKSIZE];/* used to store case stmt indentation levels */
     int         box_com;       /* set to true when we are in a "boxed"
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/lexi.c     Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.18 2021/03/07 10:42:48 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.19 2021/03/07 10:56:18 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.18 2021/03/07 10:42:48 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.19 2021/03/07 10:56:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -176,12 +176,12 @@
     return (strcmp(e1, *(const char * const *)e2));
 }
 
-int
+token_type
 lexi(struct parser_state *state)
 {
     int         unary_delim;   /* this is set to 1 if the current token
                                 * forces a following operator to be unary */
-    int         code;          /* internal code to be returned */
+    token_type  code;          /* internal code to be returned */
     char        qchar;         /* the delimiter character for a string */
 
     e_token = s_token;         /* point to start of place to save token */
@@ -376,7 +376,7 @@
     case '\n':
        unary_delim = state->last_u_d;
        state->last_nl = true;  /* remember that we just had a newline */
-       code = (had_eof ? 0 : newline);
+       code = (had_eof ? end_of_file : newline);
 
        /*
         * if data has been exhausted, the newline is a dummy, and we should
diff -r fe849f018172 -r 3ad3bbbe7660 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Sun Mar 07 10:42:48 2021 +0000
+++ b/usr.bin/indent/parse.c    Sun Mar 07 10:56:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.12 2021/03/07 10:42:48 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.13 2021/03/07 10:56:18 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -60,7 +60,7 @@
 static void reduce(void);
 
 void
-parse(int tk) /* tk: the code for the construct scanned */
+parse(token_type tk) /* tk: the code for the construct scanned */
 {
     int         i;
 



Home | Main Index | Thread Index | Old Index