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: move lexer code from scan.l to lex.c
details: https://anonhg.NetBSD.org/src/rev/f65d8cd0c349
branches: trunk
changeset: 950263:f65d8cd0c349
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 23 17:58:03 2021 +0000
description:
lint: move lexer code from scan.l to lex.c
Previously, the generated scan.c was not included when running "make
lint". Similarly, cgram.c is still not included.
diffstat:
usr.bin/xlint/lint1/Makefile | 3 +-
usr.bin/xlint/lint1/externs1.h | 20 +-
usr.bin/xlint/lint1/lex.c | 1602 ++++++++++++++++++++++++++++++++++++++
usr.bin/xlint/lint1/scan.l | 1677 +--------------------------------------
4 files changed, 1678 insertions(+), 1624 deletions(-)
diffs (truncated from 3373 to 300 lines):
diff -r 12e6b30e90cd -r f65d8cd0c349 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile Sat Jan 23 16:33:49 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile Sat Jan 23 17:58:03 2021 +0000
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.58 2021/01/10 12:05:07 rillig Exp $
+# $NetBSD: Makefile,v 1.59 2021/01/23 17:58:03 rillig Exp $
.include <bsd.own.mk>
PROG= lint1
SRCS= cgram.y decl.c emit.c emit1.c err.c func.c init.c inittyp.c \
+ lex.c \
main1.c mem.c mem1.c oper.c print.c scan.l tree.c tyname.c
MAN= lint.7
diff -r 12e6b30e90cd -r f65d8cd0c349 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sat Jan 23 16:33:49 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sat Jan 23 17:58:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.59 2021/01/18 16:41:57 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.60 2021/01/23 17:58:03 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -308,6 +308,24 @@
extern void outusg(const sym_t *);
/*
+ * lex.c
+ */
+extern int lex_name(const char *, size_t);
+extern int lex_icon(const char *, size_t, int);
+extern int lex_fcon(const char *, size_t);
+extern int lex_operator(int, op_t);
+extern int lex_string(void);
+extern int lex_wcstrg(void);
+extern int lex_ccon(void);
+extern int lex_wccon(void);
+extern void lex_directive(const char *);
+extern void lex_incline(void);
+extern void lex_comment(void);
+extern void lex_slashslashcomment(void);
+extern void lex_badchar(int);
+extern int lex_input(void);
+
+/*
* print.c
*/
extern char *print_tnode(char *, size_t, const tnode_t *);
diff -r 12e6b30e90cd -r f65d8cd0c349 usr.bin/xlint/lint1/lex.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jan 23 17:58:03 2021 +0000
@@ -0,0 +1,1602 @@
+/* $NetBSD: lex.c,v 1.1 2021/01/23 17:58:03 rillig Exp $ */
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
+ * Copyright (c) 1994, 1995 Jochen Pohl
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Jochen Pohl for
+ * The NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: lex.c,v 1.1 2021/01/23 17:58:03 rillig Exp $");
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "lint1.h"
+#include "cgram.h"
+
+#define CHAR_MASK ((int)(~(~0U << CHAR_SIZE)))
+
+
+/* Current position (it's also updated when an included file is parsed) */
+pos_t curr_pos = { 1, "", 0 };
+
+/*
+ * Current position in C source (not updated when an included file is
+ * parsed).
+ */
+pos_t csrc_pos = { 1, "", 0 };
+
+/* Are we parsing a gcc attribute? */
+bool attron;
+
+bool in_system_header = false;
+
+static sbuf_t *allocsb(void);
+static void freesb(sbuf_t *);
+static int inpc(void);
+static int hash(const char *);
+static sym_t * search(sbuf_t *);
+static int keyw(sym_t *);
+static int getescc(int);
+
+void
+lex_incline(void)
+{
+ curr_pos.p_line++;
+ curr_pos.p_uniq = 0;
+#ifdef DEBUG
+ printf("parsing %s:%d\n", curr_pos.p_file, curr_pos.p_line);
+#endif
+ if (curr_pos.p_file == csrc_pos.p_file) {
+ csrc_pos.p_line++;
+ csrc_pos.p_uniq = 0;
+ }
+}
+
+void
+lex_badchar(int c)
+{
+
+ /* unknown character \%o */
+ error(250, c);
+}
+
+/*
+ * Keywords.
+ * During initialisation they are written to the symbol table.
+ */
+static struct kwtab {
+ const char *kw_name; /* keyword */
+ int kw_token; /* token returned by yylex() */
+ scl_t kw_scl; /* storage class if kw_token T_SCLASS */
+ tspec_t kw_tspec; /* type spec. if kw_token
+ * T_TYPE or T_STRUCT_OR_UNION */
+ tqual_t kw_tqual; /* type qual. fi kw_token T_QUAL */
+ bool kw_c89 : 1; /* C89 keyword */
+ bool kw_c99 : 1; /* C99 keyword */
+ bool kw_gcc : 1; /* GCC keyword */
+ bool kw_attr : 1; /* GCC attribute, keyword */
+ u_int kw_deco : 3; /* 1 = name, 2 = __name, 4 = __name__ */
+} kwtab[] = {
+#ifdef INT128_SIZE
+ { "__int128_t", T_TYPE, 0, INT128, 0, 0,1,0,0,1 },
+ { "__uint128_t",T_TYPE, 0, UINT128,0, 0,1,0,0,1 },
+#endif
+ { "__thread", T_QUAL, 0, 0, THREAD, 0,0,1,0,1 },
+ { "_Alignof", T_ALIGNOF, 0, 0, 0, 0,0,0,0,1 },
+ { "_Bool", T_TYPE, 0, BOOL, 0, 0,1,0,0,1 },
+ { "_Complex", T_TYPE, 0, COMPLEX,0, 0,1,0,0,1 },
+ { "_Generic", T_GENERIC, 0, 0, 0, 0,1,0,0,1 },
+ { "_Noreturn", T_NORETURN, 0, 0, 0, 0,1,0,0,1 },
+ { "_Thread_local",T_QUAL, 0, 0, THREAD, 0,1,0,0,1 },
+ { "alias", T_AT_ALIAS, 0, 0, 0, 0,0,1,1,5 },
+ { "aligned", T_AT_ALIGNED, 0, 0, 0, 0,0,1,1,5 },
+ { "alignof", T_ALIGNOF, 0, 0, 0, 0,0,0,0,4 },
+ { "alloc_size", T_AT_ALLOC_SIZE,0, 0, 0, 0,0,1,1,5 },
+ { "always_inline", T_AT_ALWAYS_INLINE, 0,0, 0, 0,0,1,1,5 },
+ { "asm", T_ASM, 0, 0, 0, 0,0,1,0,7 },
+ { "attribute", T_ATTRIBUTE, 0, 0, 0, 0,0,1,0,6 },
+ { "auto", T_SCLASS, AUTO, 0, 0, 0,0,0,0,1 },
+ { "bounded", T_AT_BOUNDED, 0, 0, 0, 0,0,1,1,5 },
+ { "break", T_BREAK, 0, 0, 0, 0,0,0,0,1 },
+ { "buffer", T_AT_BUFFER, 0, 0, 0, 0,0,1,1,5 },
+ { "builtin_offsetof", T_BUILTIN_OFFSETOF, 0, 0, 0, 0,0,1,0,2 },
+ { "case", T_CASE, 0, 0, 0, 0,0,0,0,1 },
+ { "char", T_TYPE, 0, CHAR, 0, 0,0,0,0,1 },
+ { "cold", T_AT_COLD, 0, 0, 0, 0,0,1,1,5 },
+ { "const", T_QUAL, 0, 0, CONST, 1,0,0,0,7 },
+ { "constructor",T_AT_CONSTRUCTOR,0, 0, 0, 0,0,1,1,5 },
+ { "continue", T_CONTINUE, 0, 0, 0, 0,0,0,0,1 },
+ { "default", T_DEFAULT, 0, 0, 0, 0,0,0,0,1 },
+ { "deprecated", T_AT_DEPRECATED,0, 0, 0, 0,0,1,1,5 },
+ { "destructor", T_AT_DESTRUCTOR,0, 0, 0, 0,0,1,1,5 },
+ { "do", T_DO, 0, 0, 0, 0,0,0,0,1 },
+ { "double", T_TYPE, 0, DOUBLE, 0, 0,0,0,0,1 },
+ { "else", T_ELSE, 0, 0, 0, 0,0,0,0,1 },
+ { "enum", T_ENUM, 0, 0, 0, 0,0,0,0,1 },
+ { "extension", T_EXTENSION, 0, 0, 0, 0,0,1,0,4 },
+ { "extern", T_SCLASS, EXTERN, 0, 0, 0,0,0,0,1 },
+ { "float", T_TYPE, 0, FLOAT, 0, 0,0,0,0,1 },
+ { "for", T_FOR, 0, 0, 0, 0,0,0,0,1 },
+ { "format", T_AT_FORMAT, 0, 0, 0, 0,0,1,1,5 },
+ { "format_arg", T_AT_FORMAT_ARG,0, 0, 0, 0,0,1,1,5 },
+ { "gnu_inline", T_AT_GNU_INLINE,0, 0, 0, 0,0,1,1,5 },
+ { "gnu_printf", T_AT_FORMAT_GNU_PRINTF,0,0, 0, 0,0,1,1,5 },
+ { "goto", T_GOTO, 0, 0, 0, 0,0,0,0,1 },
+ { "if", T_IF, 0, 0, 0, 0,0,0,0,1 },
+ { "imag", T_IMAG, 0, 0, 0, 0,1,0,0,4 },
+ { "inline", T_SCLASS, INLINE, 0, 0, 0,1,0,0,7 },
+ { "int", T_TYPE, 0, INT, 0, 0,0,0,0,1 },
+ { "long", T_TYPE, 0, LONG, 0, 0,0,0,0,1 },
+ { "malloc", T_AT_MALLOC, 0, 0, 0, 0,0,1,1,5 },
+ { "may_alias", T_AT_MAY_ALIAS, 0, 0, 0, 0,0,1,1,5 },
+ { "minbytes", T_AT_MINBYTES, 0, 0, 0, 0,0,1,1,5 },
+ { "mode", T_AT_MODE, 0, 0, 0, 0,0,1,1,5 },
+ { "no_instrument_function", T_AT_NO_INSTRUMENT_FUNCTION,
+ 0, 0, 0, 0,0,1,1,5 },
+ { "nonnull", T_AT_NONNULL, 0, 0, 0, 0,0,1,1,5 },
+ { "noinline", T_AT_NOINLINE, 0, 0, 0, 0,0,1,1,5 },
+ { "noreturn", T_AT_NORETURN, 0, 0, 0, 0,0,1,1,5 },
+ { "nothrow", T_AT_NOTHROW, 0, 0, 0, 0,0,1,1,5 },
+ { "optimize", T_AT_OPTIMIZE, 0, 0, 0, 0,0,1,1,5 },
+ { "packed", T_AT_PACKED, 0, 0, 0, 0,0,1,1,5 },
+ { "packed", T_PACKED, 0, 0, 0, 0,0,0,0,2 },
+ { "pcs", T_AT_PCS, 0, 0, 0, 0,0,0,0,5 },
+ { "printf", T_AT_FORMAT_PRINTF,0, 0, 0, 0,0,1,1,5 },
+ { "pure", T_AT_PURE, 0, 0, 0, 0,0,1,1,5 },
+ { "real", T_REAL, 0, 0, 0, 0,1,0,0,4 },
+ { "register", T_SCLASS, REG, 0, 0, 0,0,0,0,1 },
+ { "restrict", T_QUAL, 0, 0, RESTRICT, 0,1,0,0,5 },
+ { "return", T_RETURN, 0, 0, 0, 0,0,0,0,1 },
+ { "returns_twice", T_AT_RETURNS_TWICE,0,0, 0, 0,0,1,1,5 },
+ { "scanf", T_AT_FORMAT_SCANF,0, 0, 0, 0,0,1,1,5 },
+ { "section", T_AT_SECTION, 0, 0, 0, 0,0,1,1,7 },
+ { "sentinel", T_AT_SENTINEL, 0, 0, 0, 0,0,1,1,5 },
+ { "short", T_TYPE, 0, SHORT, 0, 0,0,0,0,1 },
+ { "signed", T_TYPE, 0, SIGNED, 0, 1,0,0,0,3 },
+ { "sizeof", T_SIZEOF, 0, 0, 0, 0,0,0,0,1 },
+ { "static", T_SCLASS, STATIC, 0, 0, 0,0,0,0,1 },
+ { "strfmon", T_AT_FORMAT_STRFMON,0, 0, 0, 0,0,1,1,5 },
+ { "strftime", T_AT_FORMAT_STRFTIME,0, 0, 0, 0,0,1,1,5 },
+ { "string", T_AT_STRING, 0, 0, 0, 0,0,1,1,5 },
+ { "struct", T_STRUCT_OR_UNION, 0, STRUCT, 0, 0,0,0,0,1 },
+ { "switch", T_SWITCH, 0, 0, 0, 0,0,0,0,1 },
+ { "symbolrename", T_SYMBOLRENAME,0, 0, 0, 0,0,0,0,2 },
+ { "syslog", T_AT_FORMAT_SYSLOG,0, 0, 0, 0,0,1,1,5 },
+ { "transparent_union",T_AT_TUNION,0, 0, 0, 0,0,1,1,5 },
+ { "tls_model", T_AT_TLS_MODEL, 0, 0, 0, 0,0,1,1,5 },
+ { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0,0,0,0,1 },
+ { "typeof", T_TYPEOF, 0, 0, 0, 0,0,1,0,7 },
+ { "union", T_STRUCT_OR_UNION, 0, UNION, 0, 0,0,0,0,1 },
+ { "unsigned", T_TYPE, 0, UNSIGN, 0, 0,0,0,0,1 },
+ { "unused", T_AT_UNUSED, 0, 0, 0, 0,0,1,1,5 },
+ { "used", T_AT_USED, 0, 0, 0, 0,0,1,1,5 },
+ { "visibility", T_AT_VISIBILITY,0, 0, 0, 0,0,1,1,5 },
+ { "void", T_TYPE, 0, VOID, 0, 0,0,0,0,1 },
+ { "volatile", T_QUAL, 0, 0, VOLATILE, 1,0,0,0,7 },
+ { "warn_unused_result", T_AT_WARN_UNUSED_RESULT, 0, 0, 0, 0,0,1,1,5 },
+ { "weak", T_AT_WEAK, 0, 0, 0, 0,0,1,1,5 },
+ { "while", T_WHILE, 0, 0, 0, 0,0,0,0,1 },
+ { NULL, 0, 0, 0, 0, 0,0,0,0,0 }
+};
+
+/* Symbol table */
+static sym_t *symtab[HSHSIZ1];
+
+/* bit i of the entry with index i is set */
+uint64_t qbmasks[64];
+
+/* least significant i bits are set in the entry with index i */
+uint64_t qlmasks[64 + 1];
+
+/* least significant i bits are not set in the entry with index i */
+uint64_t qumasks[64 + 1];
+
+/* free list for sbuf structures */
+static sbuf_t *sbfrlst;
+
+/* type of next expected symbol */
+symt_t symtyp;
+
+
+static void
+add_keyword(struct kwtab *kw, int deco)
+{
+ sym_t *sym;
+ size_t h;
+ char buf[256];
+ const char *name;
+
+ if (!(kw->kw_deco & deco))
+ return;
+
+ switch (deco) {
Home |
Main Index |
Thread Index |
Old Index