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: merge duplicate code for checking ...
details: https://anonhg.NetBSD.org/src/rev/0d3fb6440d6c
branches: trunk
changeset: 377485:0d3fb6440d6c
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Jul 13 23:27:20 2023 +0000
description:
lint: merge duplicate code for checking duplicate type qualifiers
diffstat:
usr.bin/xlint/lint1/debug.c | 10 ++++++----
usr.bin/xlint/lint1/decl.c | 38 ++++++++++----------------------------
usr.bin/xlint/lint1/lint1.h | 5 ++---
3 files changed, 18 insertions(+), 35 deletions(-)
diffs (141 lines):
diff -r 4e13037ccf4f -r 0d3fb6440d6c usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c Thu Jul 13 23:11:11 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c Thu Jul 13 23:27:20 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.54 2023/07/13 23:11:11 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.54 2023/07/13 23:11:11 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $");
#endif
#include <stdlib.h>
@@ -432,8 +432,10 @@ debug_decl_level(const decl_level *dl)
if (dl->d_sou_align_in_bits != 0)
debug_printf(" align=%u", dl->d_sou_align_in_bits);
- debug_word(dl->d_const, "const");
- debug_word(dl->d_volatile, "volatile");
+ debug_word(dl->d_qual.tq_const, "const");
+ debug_word(dl->d_qual.tq_restrict, "restrict");
+ debug_word(dl->d_qual.tq_volatile, "volatile");
+ debug_word(dl->d_qual.tq_atomic, "atomic");
debug_word(dl->d_inline, "inline");
debug_word(dl->d_multiple_storage_classes, "multiple_storage_classes");
debug_word(dl->d_invalid_type_combination, "invalid_type_combination");
diff -r 4e13037ccf4f -r 0d3fb6440d6c usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Thu Jul 13 23:11:11 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Thu Jul 13 23:27:20 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.354 2023/07/13 23:11:11 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.354 2023/07/13 23:11:11 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $");
#endif
#include <sys/param.h>
@@ -501,21 +501,7 @@ dcs_set_used(void)
void
dcs_add_qualifiers(type_qualifiers qs)
{
-
- if (qs.tq_const) {
- if (dcs->d_const) {
- /* duplicate '%s' */
- warning(10, "const");
- }
- dcs->d_const = true;
- }
- if (qs.tq_volatile) {
- if (dcs->d_volatile) {
- /* duplicate '%s' */
- warning(10, "volatile");
- }
- dcs->d_volatile = true;
- }
+ add_type_qualifiers(&dcs->d_qual, qs);
}
void
@@ -628,8 +614,7 @@ dcs_begin_type(void)
dcs->d_rank_mod = NO_TSPEC;
dcs->d_scl = NOSCL;
dcs->d_type = NULL;
- dcs->d_const = false;
- dcs->d_volatile = false;
+ dcs->d_qual = (type_qualifiers) { .tq_const = false };
dcs->d_inline = false;
dcs->d_multiple_storage_classes = false;
dcs->d_invalid_type_combination = false;
@@ -740,22 +725,23 @@ dcs_end_type(void)
dcs_adjust_storage_class();
- if (dcs->d_const && dcs->d_type->t_const && !dcs->d_type->t_typeof) {
+ if (dcs->d_qual.tq_const && dcs->d_type->t_const
+ && !dcs->d_type->t_typeof) {
lint_assert(dcs->d_type->t_typedef);
/* typedef already qualified with '%s' */
warning(68, "const");
}
- if (dcs->d_volatile && dcs->d_type->t_volatile &&
+ if (dcs->d_qual.tq_volatile && dcs->d_type->t_volatile &&
!dcs->d_type->t_typeof) {
lint_assert(dcs->d_type->t_typedef);
/* typedef already qualified with '%s' */
warning(68, "volatile");
}
- if (dcs->d_const || dcs->d_volatile) {
+ if (dcs->d_qual.tq_const || dcs->d_qual.tq_volatile) {
dcs->d_type = block_dup_type(dcs->d_type);
- dcs->d_type->t_const |= dcs->d_const;
- dcs->d_type->t_volatile |= dcs->d_volatile;
+ dcs->d_type->t_const |= dcs->d_qual.tq_const;
+ dcs->d_type->t_volatile |= dcs->d_qual.tq_volatile;
}
}
@@ -1172,10 +1158,6 @@ qual_ptr *
append_qualified_pointer(qual_ptr *p1, qual_ptr *p2)
{
- if (p2 == NULL)
- return p1;
-
- /* append p1 to p2, keeping p2 */
qual_ptr *tail = p2;
while (tail->p_next != NULL)
tail = tail->p_next;
diff -r 4e13037ccf4f -r 0d3fb6440d6c usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Thu Jul 13 23:11:11 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Thu Jul 13 23:27:20 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.191 2023/07/13 23:11:11 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.192 2023/07/13 23:27:20 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -363,8 +363,7 @@ typedef struct decl_level {
* trailing padding */
unsigned int d_sou_align_in_bits; /* alignment of the structure
* or union being built */
- bool d_const:1; /* const in declaration specifiers */
- bool d_volatile:1; /* volatile in declaration specifiers */
+ type_qualifiers d_qual; /* in declaration specifiers */
bool d_inline:1; /* inline in declaration specifiers */
bool d_multiple_storage_classes:1; /* reported in dcs_end_type */
bool d_invalid_type_combination:1;
Home |
Main Index |
Thread Index |
Old Index