Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: reorganize lexer functions



details:   https://anonhg.NetBSD.org/src/rev/eec12ea3e61b
branches:  trunk
changeset: 362467:eec12ea3e61b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 27 22:46:04 2022 +0000

description:
lint: reorganize lexer functions

Move the keywords table to the top, reduce forward declarations.

No functional change.

diffstat:

 usr.bin/xlint/lint1/lex.c |  83 +++++++++++++++++++++++-----------------------
 1 files changed, 41 insertions(+), 42 deletions(-)

diffs (139 lines):

diff -r 4069c9082751 -r eec12ea3e61b usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Feb 27 22:26:12 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Feb 27 22:46:04 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.104 2022/02/27 22:26:12 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.105 2022/02/27 22:46:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.104 2022/02/27 22:26:12 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.105 2022/02/27 22:46:04 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -67,30 +67,6 @@
 bool in_gcc_attribute;
 bool in_system_header;
 
-static int     inpc(void);
-static int     keyw(sym_t *);
-static int     get_escaped_char(int);
-
-void
-lex_next_line(void)
-{
-       curr_pos.p_line++;
-       curr_pos.p_uniq = 0;
-       debug_step("parsing %s:%d", curr_pos.p_file, curr_pos.p_line);
-       if (curr_pos.p_file == csrc_pos.p_file) {
-               csrc_pos.p_line++;
-               csrc_pos.p_uniq = 0;
-       }
-}
-
-void
-lex_unknown_character(int c)
-{
-
-       /* unknown character \%o */
-       error(250, c);
-}
-
 #define kwdef(name, token, scl, tspec, tqual,  c90, c99, gcc, attr, deco) \
        { \
                name, token, scl, tspec, tqual, \
@@ -258,6 +234,9 @@
 symt_t symtyp;
 
 
+static int     get_escaped_char(int);
+
+
 static unsigned int
 hash(const char *s)
 {
@@ -402,6 +381,21 @@
        return c;
 }
 
+static int
+lex_keyword(sym_t *sym)
+{
+       int     t;
+
+       if ((t = (int)sym->s_value.v_quad) == T_SCLASS) {
+               yylval.y_scl = sym->s_scl;
+       } else if (t == T_TYPE || t == T_STRUCT_OR_UNION) {
+               yylval.y_tspec = sym->s_tspec;
+       } else if (t == T_QUAL) {
+               yylval.y_tqual = sym->s_tqual;
+       }
+       return t;
+}
+
 /*
  * Lex has found a letter followed by zero or more letters or digits.
  * It looks for a symbol in the symbol table with the same name. This
@@ -428,7 +422,7 @@
        sb->sb_len = yyleng;
        if ((sym = symtab_search(sb)) != NULL && sym->s_keyword != NULL) {
                free(sb);
-               return keyw(sym);
+               return lex_keyword(sym);
        }
 
        sb->sb_sym = sym;
@@ -450,21 +444,6 @@
        return tok;
 }
 
-static int
-keyw(sym_t *sym)
-{
-       int     t;
-
-       if ((t = (int)sym->s_value.v_quad) == T_SCLASS) {
-               yylval.y_scl = sym->s_scl;
-       } else if (t == T_TYPE || t == T_STRUCT_OR_UNION) {
-               yylval.y_tspec = sym->s_tspec;
-       } else if (t == T_QUAL) {
-               yylval.y_tqual = sym->s_tqual;
-       }
-       return t;
-}
-
 /*
  * Convert a string representing an integer into internal representation.
  * Return T_CON, storing the numeric value in yylval, for yylex.
@@ -1302,6 +1281,26 @@
        return T_STRING;
 }
 
+void
+lex_next_line(void)
+{
+       curr_pos.p_line++;
+       curr_pos.p_uniq = 0;
+       debug_step("parsing %s:%d", curr_pos.p_file, curr_pos.p_line);
+       if (curr_pos.p_file == csrc_pos.p_file) {
+               csrc_pos.p_line++;
+               csrc_pos.p_uniq = 0;
+       }
+}
+
+void
+lex_unknown_character(int c)
+{
+
+       /* unknown character \%o */
+       error(250, c);
+}
+
 #ifdef DEBUG
 static const char *
 symt_name(symt_t kind)



Home | Main Index | Thread Index | Old Index