summaryrefslogtreecommitdiff
path: root/usr.bin/xlint/common/lint.h
blob: 77c8a518206e67cdce4ae170811a722e70744353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*	$NetBSD: lint.h,v 1.41 2023/07/08 16:13:00 rillig Exp $	*/

/*
 * 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.
 */

#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#define HAVE_DECL_SYS_SIGNAME 1
#endif

#include <sys/types.h>
#include <ctype.h>
#include <err.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>

#include "param.h"

#if defined(IS_LINT1) || defined(IS_LINT2)
/*
 * Type specifiers, used in type structures (type_t) and elsewhere.
 */
typedef enum {
	NO_TSPEC = 0,
	SIGNED,		/* keyword "signed", only used in the parser */
	UNSIGN,		/* keyword "unsigned", only used in the parser */
	BOOL,		/* _Bool */
	CHAR,		/* char */
	SCHAR,		/* signed char */
	UCHAR,		/* unsigned char */
	SHORT,		/* (signed) short */
	USHORT,		/* unsigned short */
	INT,		/* (signed) int */
	UINT,		/* unsigned int */
	LONG,		/* (signed) long */
	ULONG,		/* unsigned long */
	LLONG,		/* (signed) long long */
	ULLONG,		/* unsigned long long */
#ifdef INT128_SIZE
	INT128,		/* (signed) __int128_t */
	UINT128,	/* __uint128_t */
#endif
	FLOAT,		/* float */
	DOUBLE,		/* double or, with tflag, long float */
	LDOUBLE,	/* long double */
	COMPLEX,	/* keyword "_Complex", only used in the parser */
	FCOMPLEX,	/* float _Complex */
	DCOMPLEX,	/* double _Complex */
	LCOMPLEX,	/* long double _Complex */
	VOID,		/* void */
	STRUCT,		/* structure tag */
	UNION,		/* union tag */
	ENUM,		/* enum tag */
	PTR,		/* pointer */
	ARRAY,		/* array */
	FUNC,		/* function */
#define NTSPEC ((int)FUNC + 1)
} tspec_t;


/*
 * size of types, name and classification
 */
typedef	struct {
#ifdef IS_LINT1
	unsigned int tt_size_in_bits;
	enum rank_kind {
		RK_NONE,
		RK_INTEGER,
		RK_FLOATING,
		RK_COMPLEX,
	} tt_rank_kind;
	unsigned int tt_rank_value;	/* relative size of the type; depends
					 * on pflag and PTRDIFF_TSPEC */
#endif
	tspec_t	tt_signed_counterpart;
	tspec_t	tt_unsigned_counterpart;
	bool	tt_is_integer:1;	/* integer type */
#ifdef IS_LINT1
	bool	tt_is_uinteger:1;	/* unsigned integer type */
	bool	tt_is_floating:1;	/* floating point type */
	bool	tt_is_arithmetic:1;	/* arithmetic type */
	bool	tt_is_scalar:1;		/* scalar type */
	bool	tt_is_complex:1;	/* complex type */
#endif
	const char *tt_name;		/* name of the type */
} ttab_t;

extern	ttab_t	ttab[];

static inline const ttab_t *
type_properties(tspec_t t) {
	return ttab + t;
}

#define size_in_bits(t)		(type_properties(t)->tt_size_in_bits)
#define signed_type(t)		(type_properties(t)->tt_signed_counterpart)
#define unsigned_type(t)	(type_properties(t)->tt_unsigned_counterpart)
#define is_integer(t)		(type_properties(t)->tt_is_integer)
#define is_uinteger(t)		(type_properties(t)->tt_is_uinteger)
#define is_floating(t)		(type_properties(t)->tt_is_floating)
#define is_arithmetic(t)	(type_properties(t)->tt_is_arithmetic)
#define is_complex(t)		(type_properties(t)->tt_is_complex)
#define is_scalar(t)		(type_properties(t)->tt_is_scalar)


typedef	enum {
	NODECL,			/* not declared until now */
	DECL,			/* declared */
	TDEF,			/* tentative defined */
	DEF			/* defined */
} def_t;

/* Some data used for the output buffer. */
typedef	struct	ob {
	char	*o_buf;		/* buffer */
	char	*o_end;		/* first byte after buffer */
	size_t	o_len;		/* length of buffer */
	char	*o_next;	/* next free byte in buffer */
} ob_t;

#if defined(IS_LINT1)
typedef struct lint1_type type_t;
#else
typedef struct lint2_type type_t;
#endif
#endif

#include "externs.h"

static inline bool
ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
static inline bool
ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
static inline bool
ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; }
static inline bool
ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
static inline bool
ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }