Module Name:    src
Committed By:   rillig
Date:           Sun Aug 22 13:01:47 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: lex.c lint1.h
        src/usr.bin/xlint/lint2: lint2.h

Log Message:
lint: save some memory

Before lint1.h 1.47 from 2021-01-02, adjacent bit-field struct members
shared storage.  Restore that using smaller types.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.121 -r1.122 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint2/lint2.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.65 src/usr.bin/xlint/lint1/lex.c:1.66
--- src/usr.bin/xlint/lint1/lex.c:1.65	Thu Aug 19 21:13:58 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug 22 13:01:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.65 2021/08/19 21:13:58 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.66 2021/08/22 13:01:47 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.65 2021/08/19 21:13:58 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.66 2021/08/22 13:01:47 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -100,7 +100,8 @@ lex_unknown_character(int c)
 #define kwdef(name, token, scl, tspec, tqual,	c89, c99, gcc, attr, deco) \
 	{ \
 		name, token, scl, tspec, tqual, \
-		(c89) > 0, (c99) > 0, (gcc) > 0, (attr) > 0, deco, \
+		(c89) > 0, (c99) > 0, (gcc) > 0, (attr) > 0, \
+		((deco) & 1) != 0, ((deco) & 2) != 0, ((deco) & 4) != 0, \
 	}
 #define kwdef_token(name, token,		c89, c99, gcc, attr, deco) \
 	kwdef(name, token, 0, 0, 0,		c89, c99, gcc, attr, deco)
@@ -130,7 +131,9 @@ static	struct	kwtab {
 	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__ */
+	bool	kw_plain : 1;	/* 'name' */
+	bool	kw_leading : 1;	/* '__name' */
+	bool	kw_both : 1;	/* '__name__' */
 } kwtab[] = {
 	kwdef_gcc_attr(	"alias",	T_AT_ALIAS),
 	kwdef_keyword(	"_Alignas",	T_ALIGNAS),
@@ -282,33 +285,20 @@ symtab_remove(sym_t *sym)
 
 
 static void
-add_keyword(const struct kwtab *kw, u_int deco)
+add_keyword(const struct kwtab *kw, bool leading, bool trailing)
 {
 	sym_t *sym;
 	char buf[256];
 	const char *name;
 
-	if ((kw->kw_deco & deco) == 0)
-		return;
-
-	switch (deco) {
-	case 1:
+	if (!leading && !trailing) {
 		name = kw->kw_name;
-		break;
-	case 2:
-		snprintf(buf, sizeof(buf), "__%s", kw->kw_name);
-		name = strdup(buf);
-		break;
-	default:
-		lint_assert(deco == 4);
-		snprintf(buf, sizeof(buf), "__%s__", kw->kw_name);
-		name = strdup(buf);
-		break;
+	} else {
+		snprintf(buf, sizeof(buf), "%s%s%s",
+		    leading ? "__" : "", kw->kw_name, trailing ? "__" : "");
+		name = xstrdup(buf);
 	}
 
-	if (name == NULL)
-		err(1, "Can't init symbol table");
-
 	sym = getblk(sizeof(*sym));
 	sym->s_name = name;
 	sym->s_keyword = kw;
@@ -340,9 +330,12 @@ initscan(void)
 			continue;
 		if (kw->kw_gcc && !gflag)
 			continue;
-		add_keyword(kw, 1);
-		add_keyword(kw, 2);
-		add_keyword(kw, 4);
+		if (kw->kw_plain)
+			add_keyword(kw, false, false);
+		if (kw->kw_leading)
+			add_keyword(kw, true, false);
+		if (kw->kw_both)
+			add_keyword(kw, true, true);
 	}
 }
 

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.121 src/usr.bin/xlint/lint1/lint1.h:1.122
--- src/usr.bin/xlint/lint1/lint1.h:1.121	Sun Aug  1 08:03:43 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Aug 22 13:01:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.121 2021/08/01 08:03:43 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.122 2021/08/22 13:01:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -135,7 +135,7 @@ typedef struct {
  */
 typedef	struct {
 	u_int	sou_size_in_bits;
-	u_int	sou_align_in_bits : 15;
+	u_short	sou_align_in_bits;
 	bool	sou_incomplete : 1;
 	struct	sym *sou_first_member;
 	struct	sym *sou_tag;
@@ -362,7 +362,7 @@ typedef	struct dinfo {
 				   for all declarators */
 	sym_t	*d_redeclared_symbol;
 	u_int	d_offset;	/* offset of next structure member */
-	u_int	d_sou_align_in_bits; /* alignment required for current
+	u_short	d_sou_align_in_bits; /* alignment required for current
 				 * structure */
 	scl_t	d_ctx;		/* context of declaration */
 	bool	d_const : 1;	/* const in declaration specifiers */

Index: src/usr.bin/xlint/lint2/lint2.h
diff -u src/usr.bin/xlint/lint2/lint2.h:1.15 src/usr.bin/xlint/lint2/lint2.h:1.16
--- src/usr.bin/xlint/lint2/lint2.h:1.15	Sun Aug 22 12:15:37 2021
+++ src/usr.bin/xlint/lint2/lint2.h	Sun Aug 22 13:01:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint2.h,v 1.15 2021/08/22 12:15:37 rillig Exp $ */
+/* $NetBSD: lint2.h,v 1.16 2021/08/22 13:01:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -115,7 +115,7 @@ typedef	struct sym {
 	struct {
 		pos_t	s_pos;		/* pos of def./decl. */
 #ifndef lint
-		u_int	s_def : 3;	/* DECL, TDEF or DEF */
+		u_char	s_def;		/* DECL, TDEF or DEF */
 #else
 		def_t	s_def;
 #endif

Reply via email to