lint2.h revision 1.20
122347Spst/* $NetBSD: lint2.h,v 1.20 2021/11/01 19:48:51 rillig Exp $ */ 222347Spst 322347Spst/* 422347Spst * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 522347Spst * Copyright (c) 1994, 1995 Jochen Pohl 622347Spst * All Rights Reserved. 729964Sache * 859118Skris * Redistribution and use in source and binary forms, with or without 922347Spst * modification, are permitted provided that the following conditions 1022347Spst * are met: 1122347Spst * 1. Redistributions of source code must retain the above copyright 1222347Spst * notice, this list of conditions and the following disclaimer. 1322347Spst * 2. Redistributions in binary form must reproduce the above copyright 1422347Spst * notice, this list of conditions and the following disclaimer in the 1522347Spst * documentation and/or other materials provided with the distribution. 1622347Spst * 3. All advertising materials mentioning features or use of this software 1722347Spst * must display the following acknowledgement: 1822347Spst * This product includes software developed by Jochen Pohl for 1922347Spst * The NetBSD Project. 2022347Spst * 4. The name of the author may not be used to endorse or promote products 2129964Sache * derived from this software without specific prior written permission. 2229964Sache * 2329964Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2422347Spst * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2522347Spst * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2622347Spst * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2722347Spst * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2822347Spst * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2922347Spst * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3022347Spst * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3122347Spst * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3222347Spst * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3322347Spst */ 3422347Spst 3522347Spst#include "lint.h" 3622347Spst 3722347Spst/* 3822347Spst * Types are described by structures of type type_t. 3922347Spst */ 4022347Spststruct lint2_type { 4122347Spst tspec_t t_tspec; /* type specifier */ 4222347Spst bool t_const : 1; /* constant */ 4322347Spst bool t_volatile : 1; /* volatile */ 4422347Spst bool t_vararg : 1; /* function has variable number of arguments */ 4522347Spst bool t_is_enum : 1; 4622347Spst bool t_proto : 1; /* this is a prototype */ 4722347Spst bool t_istag : 1; /* tag with _t_tag valid */ 4822347Spst bool t_istynam : 1; /* tag with _t_tynam valid */ 4922347Spst bool t_isuniqpos : 1; /* tag with _t_uniqpos valid */ 5022347Spst union { 5122347Spst int _t_dim; /* if the type is an ARRAY than this 5222347Spst is the dimension of the array. */ 5322347Spst struct hte *_t_tag; /* hash table entry of tag if 5422347Spst t_is_enum, STRUCT or UNION */ 5522347Spst struct hte *_t_tynam; /* hash table entry of typename if 5622347Spst t_is_enum, STRUCT or UNION */ 5722347Spst struct { 5822347Spst int p_line; 5922347Spst short p_file; 6022347Spst int p_uniq; 6122347Spst } _t_uniqpos; /* unique position, for untagged 6222347Spst untyped STRUCTs, UNIONS, and ENUMs, 6322347Spst if t_isuniqpos */ 6422347Spst struct lint2_type **_t_args; /* list of argument types if 6522347Spst this is a prototype */ 6622347Spst } t_u; 6722347Spst struct lint2_type *t_subt; /* element type (if ARRAY), 6822347Spst return type (if FUNC), 6922347Spst target type (if PTR) */ 7022347Spst}; 7122347Spst 7222347Spst#define t_dim t_u._t_dim 7322347Spst#define t_tag t_u._t_tag 7429964Sache#define t_tynam t_u._t_tynam 7522347Spst#define t_uniqpos t_u._t_uniqpos 7622347Spst#define t_args t_u._t_args 7722347Spst 7822347Spst/* 7922347Spst * argument information 8022347Spst * 8122347Spst * Such a structure is created for each argument of a function call 8222347Spst * which is an integer constant or a constant string. 8322347Spst */ 8422347Spsttypedef struct arginf { 8522347Spst int a_num; /* # of argument (1..) */ 8629964Sache bool a_zero : 1; /* argument is 0 */ 8722347Spst bool a_pcon : 1; /* msb of argument is not set */ 8822347Spst bool a_ncon : 1; /* msb of argument is set */ 8922347Spst bool a_fmt : 1; /* a_fstrg points to format string */ 9022347Spst char *a_fstrg; /* format string */ 9122347Spst struct arginf *a_next; /* information for next const. argument */ 9222347Spst} arginf_t; 9322347Spst 9422347Spst/* 9522347Spst * Keeps information about position in source file. 9622347Spst */ 9722347Spsttypedef struct { 9822347Spst unsigned short p_src; /* index of name of translation unit 9922347Spst (the name which was specified at the 10022347Spst command line) */ 10122347Spst unsigned short p_line; /* line number in p_src */ 10222347Spst unsigned short p_isrc; /* index of (included) file */ 10322347Spst unsigned short p_iline; /* line number in p_iline */ 10422347Spst} pos_t; 10522347Spst 10622347Spst/* Used for definitions and declarations. */ 10722347Spsttypedef struct sym { 10822347Spst struct { 10922347Spst pos_t s_pos; /* pos of def./decl. */ 11022347Spst#if !defined(lint) && !defined(DEBUG) 11122347Spst unsigned char s_def; /* DECL, TDEF or DEF */ 11222347Spst#else 11322347Spst def_t s_def; 11422347Spst#endif 11522347Spst bool s_function_has_return_value : 1; 11622347Spst bool s_inline : 1; 11722347Spst bool s_old_style_function : 1; 11822347Spst bool s_static : 1; 11922347Spst bool s_check_only_first_args : 1; 12022347Spst bool s_printflike : 1; 12122347Spst bool s_scanflike : 1; 12222347Spst unsigned short s_type; 12322347Spst /* XXX: gap of 4 bytes on LP64 platforms */ 12422347Spst struct sym *s_next; /* next symbol with same name */ 12522347Spst } s_s; 12622347Spst /* 12722347Spst * To save memory, the remaining members are only allocated if one of 12822347Spst * s_check_only_first_args, s_printflike and s_scanflike is set. 12922347Spst */ 13022347Spst short s_check_num_args; /* if s_check_only_first_args */ 13122347Spst short s_printflike_arg; /* if s_printflike */ 13222347Spst short s_scanflike_arg; /* if s_scanflike */ 13322347Spst} sym_t; 13422347Spst 13522347Spst#define s_pos s_s.s_pos 13622347Spst#define s_function_has_return_value s_s.s_function_has_return_value 13722347Spst#define s_old_style_function s_s.s_old_style_function 13822347Spst#define s_inline s_s.s_inline 13922347Spst#define s_static s_s.s_static 14022347Spst#define s_def s_s.s_def 14122347Spst#define s_check_only_first_args s_s.s_check_only_first_args 14222347Spst#define s_printflike s_s.s_printflike 14322347Spst#define s_scanflike s_s.s_scanflike 14422347Spst#define s_type s_s.s_type 14522347Spst#define s_next s_s.s_next 14622347Spst 14722347Spst/* 14822347Spst * Used to store information about function calls. 14922347Spst */ 15022347Spsttypedef struct fcall { 15122347Spst pos_t f_pos; /* position of call */ 15222347Spst bool f_rused : 1; /* return value used */ 15322347Spst bool f_rdisc : 1; /* return value discarded (casted to void) */ 15422347Spst unsigned short f_type; /* types of expected return value and args */ 15522347Spst arginf_t *f_args; /* information about constant arguments */ 15622347Spst struct fcall *f_next; /* next call of same function */ 15722347Spst} fcall_t; 15822347Spst 15922347Spst/* 16022347Spst * Used to store information about usage of symbols other 16122347Spst * than for function calls. 16222347Spst */ 16322347Spsttypedef struct usym { 16422347Spst pos_t u_pos; /* position */ 16522347Spst struct usym *u_next; /* next usage */ 16622347Spst} usym_t; 16722347Spst 16822347Spst/* 16922347Spst * hash table entry 17022347Spst */ 17122347Spsttypedef struct hte { 17222347Spst const char *h_name; /* name */ 17322347Spst bool h_used : 1; /* symbol is used */ 17422347Spst bool h_def : 1; /* symbol is defined */ 17522347Spst bool h_static : 1; /* static symbol */ 17622347Spst sym_t *h_syms; /* declarations and definitions */ 17722347Spst sym_t **h_lsym; /* points to s_next of last decl./def. */ 17822347Spst fcall_t *h_calls; /* function calls */ 17922347Spst fcall_t **h_lcall; /* points to f_next of last call */ 18022347Spst usym_t *h_usyms; /* usage info */ 18122347Spst usym_t **h_lusym; /* points to u_next of last usage info */ 18222347Spst struct hte *h_link; /* next hte with same hash function */ 18322347Spst struct hte *h_hte; /* pointer to other htes (for renames) */ 18422347Spst} hte_t; 18522347Spst 18622347Spst#include "externs2.h" 18722347Spst 18822347Spst/* maps type indices into pointers to type structs */ 18922347SpstINLINE_FUNC type_t * 19022347SpstTP(unsigned short type_id) { 19122347Spst /* force sequence point for newly parsed type_id */ 19222347Spst return tlst[type_id]; 19322347Spst} 19422347Spst