Import of NetBSD's (x)lint, snapshotted at 2002-3-3.

This commit is contained in:
Mark Murray 2002-03-03 13:17:00 +00:00
parent 96a322df43
commit fdd1668006
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/JPO/; revision=91586
56 changed files with 4045 additions and 1886 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.2 1995/07/03 21:23:45 cgd Exp $
# $NetBSD$
SUBDIR= lint1 lint2 xlint llib

View File

@ -0,0 +1,21 @@
# $NetBSD: Makefile.inc,v 1.8 2002/02/04 00:18:32 thorpej Exp $
.include <bsd.own.mk>
.PATH: ${.CURDIR}/../common
# On the m68000, MACHINE_CPU is "m68k", but we have different
# target parameters (namely, long double is a different size
# on the m68000), so we special case the directory name here.
.if ${MACHINE_ARCH} == "m68000"
ARCHSUBDIR= m68000
.else
ARCHSUBDIR= ${MACHINE_CPU}
.endif
CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR}
CPPFLAGS+= -I${.CURDIR}/../common
.if exists(${.CURDIR}/../../Makefile.inc)
.include "${.CURDIR}/../../Makefile.inc"
.endif

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:18 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "lp64.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.2 2002/01/30 06:55:00 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "lp64.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (16 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,63 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:19 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#if defined(TARGET_OBJFMT_ELF)
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#else
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#endif
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#if defined(TARGET_OBJFMT_ELF)
/* XXX ARM ELF ABI says packed enums -- variable size! */
#define ENUM_SIZE (4 * CHAR_BIT)
#else
#define ENUM_SIZE (4 * CHAR_BIT)
#endif

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:19 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (12 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD$ */
/*
* 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:19 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (12 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:19 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:20 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (12 * CHAR_BIT) /* XXX double-check */
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:20 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:20 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:21 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.2 2002/01/30 06:55:00 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "lp64.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (16 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:22 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "ilp32.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (8 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

View File

@ -0,0 +1,53 @@
/* $NetBSD: targparam.h,v 1.1 2002/01/18 20:39:22 thorpej 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.
*/
/*
* Machine-dependent target parameters for lint1.
*/
#include "lp64.h"
/*
* Should be set to 1 if the difference of two pointers is of type long
* or the value of sizeof is of type unsigned long. Note this MUST be
* kept in sync with the compiler!
*/
#define PTRDIFF_IS_LONG 1
#define SIZEOF_IS_ULONG 1
#define FLOAT_SIZE (4 * CHAR_BIT)
#define DOUBLE_SIZE (8 * CHAR_BIT)
#define LDOUBLE_SIZE (16 * CHAR_BIT)
#define ENUM_SIZE (4 * CHAR_BIT)

234
usr.bin/xlint/common/emit.c Normal file
View File

@ -0,0 +1,234 @@
/* $NetBSD: emit.c,v 1.2 2002/01/21 19:49:51 tv 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.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: emit.c,v 1.2 2002/01/21 19:49:51 tv Exp $");
#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "lint.h"
/* name and handle of output file */
static const char *loname;
static FILE *lout;
/* output buffer data */
ob_t ob;
static void outxbuf(void);
/*
* initialize output
*/
void
outopen(const char *name)
{
loname = name;
/* Open output file */
if ((lout = fopen(name, "w")) == NULL)
err(1, "cannot open '%s'", name);
/* Create output buffer */
ob.o_len = 1024;
ob.o_end = (ob.o_buf = ob.o_nxt = xmalloc(ob.o_len)) + ob.o_len;
}
/*
* flush output buffer and close file
*/
void
outclose(void)
{
outclr();
if (fclose(lout) == EOF)
err(1, "cannot close '%s'", loname);
}
/*
* resize output buffer
*/
static void
outxbuf(void)
{
ptrdiff_t coffs;
coffs = ob.o_nxt - ob.o_buf;
ob.o_len *= 2;
ob.o_end = (ob.o_buf = xrealloc(ob.o_buf, ob.o_len)) + ob.o_len;
ob.o_nxt = ob.o_buf + coffs;
}
/*
* reset output buffer
* if it is not empty, it is flushed
*/
void
outclr(void)
{
size_t sz;
if (ob.o_buf != ob.o_nxt) {
outchar('\n');
sz = ob.o_nxt - ob.o_buf;
if (sz > ob.o_len)
errx(1, "internal error: outclr() 1");
if (fwrite(ob.o_buf, sz, 1, lout) != 1)
err(1, "cannot write to %s", loname);
ob.o_nxt = ob.o_buf;
}
}
/*
* write a character to the output buffer
*/
void
outchar(int c)
{
if (ob.o_nxt == ob.o_end)
outxbuf();
*ob.o_nxt++ = (char)c;
}
/*
* write a character to the output buffer, qouted if necessary
*/
void
outqchar(int c)
{
if (isprint(c) && c != '\\' && c != '"' && c != '\'') {
outchar(c);
} else {
outchar('\\');
switch (c) {
case '\\':
outchar('\\');
break;
case '"':
outchar('"');
break;
case '\'':
outchar('\'');
break;
case '\b':
outchar('b');
break;
case '\t':
outchar('t');
break;
case '\n':
outchar('n');
break;
case '\f':
outchar('f');
break;
case '\r':
outchar('r');
break;
case '\v':
outchar('v');
break;
case '\a':
outchar('a');
break;
default:
outchar((((u_int)c >> 6) & 07) + '0');
outchar((((u_int)c >> 3) & 07) + '0');
outchar((c & 07) + '0');
break;
}
}
}
/*
* write a strint to the output buffer
* the string must not contain any characters which
* should be quoted
*/
void
outstrg(const char *s)
{
while (*s != '\0') {
if (ob.o_nxt == ob.o_end)
outxbuf();
*ob.o_nxt++ = *s++;
}
}
/*
* write an integer value to toe output buffer
*/
void
outint(int i)
{
if ((ob.o_end - ob.o_nxt) < 3 * sizeof (int))
outxbuf();
ob.o_nxt += sprintf(ob.o_nxt, "%d", i);
}
/*
* write the name of a symbol to the output buffer
* the name is preceded by its length
*/
void
outname(const char *name)
{
if (name == NULL)
errx(1, "internal error: outname() 1");
outint((int)strlen(name));
outstrg(name);
}
/*
* write the name of the .c source
*/
void
outsrc(const char *name)
{
outclr();
outchar('S');
outstrg(name);
}

View File

@ -0,0 +1,66 @@
/* $NetBSD: externs.h,v 1.1 2002/01/18 20:39:23 thorpej 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.
*/
/*
* main[12].c
*/
extern int pflag;
/*
* inittyp.c
*/
extern void inittyp(void);
/*
* mem.c
*/
extern void *xmalloc(size_t);
extern void *xcalloc(size_t, size_t);
extern void *xrealloc(void *, size_t);
extern char *xstrdup(const char *);
extern void nomem(void);
/*
* emit.c
*/
extern ob_t ob;
extern void outopen(const char *);
extern void outclose(void);
extern void outclr(void);
extern void outchar(int);
extern void outqchar(int);
extern void outstrg(const char *);
extern void outint(int);
extern void outname(const char *);
extern void outsrc(const char *);

View File

@ -0,0 +1,59 @@
/* $NetBSD: ilp32.h,v 1.1 2002/01/18 20:39:23 thorpej Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* 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 for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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.
*/
/*
* Type sizes for IPL32 platforms (int, long, pointer: 32-bit)
*/
#define CHAR_SIZE (CHAR_BIT)
#define SHORT_SIZE (2 * CHAR_BIT)
#define INT_SIZE (4 * CHAR_BIT)
#define LONG_SIZE (4 * CHAR_BIT)
#define QUAD_SIZE (8 * CHAR_BIT)
#define PTR_SIZE (4 * CHAR_BIT)
#define TARG_INT_MAX ((int32_t) (((uint32_t) -1) >> 1))
#define TARG_INT_MIN ((-TARG_INT_MAX) - 1)
#define TARG_UINT_MAX ((uint32_t) -1)
#define TARG_LONG_MAX TARG_INT_MAX
#define TARG_LONG_MIN TARG_INT_MIN
#define TARG_ULONG_MAX TARG_UINT_MAX
#define TARG_QUAD_MAX ((int64_t) (((uint64_t) -1) >> 1))
#define TARG_QUAD_MIN ((-TARG_QUAD_MAX) - 1)
#define TARG_UQUAD_MAX ((uint64_t) -1)

View File

@ -0,0 +1,133 @@
/* $NetBSD: inittyp.c,v 1.3 2002/01/30 06:55:02 thorpej 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.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: inittyp.c,v 1.3 2002/01/30 06:55:02 thorpej Exp $");
#endif
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "lint.h"
/* various type information */
ttab_t ttab[NTSPEC];
void
inittyp(void)
{
int i;
static const struct {
tspec_t it_tspec;
ttab_t it_ttab;
} ittab[NTSPEC] = {
{ SIGNED, { 0, 0,
SIGNED, UNSIGN,
0, 0, 0, 0, 0, "signed" } },
{ UNSIGN, { 0, 0,
SIGNED, UNSIGN,
0, 0, 0, 0, 0, "unsigned" } },
{ CHAR, { CHAR_SIZE, CHAR_BIT,
SCHAR, UCHAR,
1, 0, 0, 1, 1, "char" } },
{ SCHAR, { CHAR_SIZE, CHAR_BIT,
SCHAR, UCHAR,
1, 0, 0, 1, 1, "signed char" } },
{ UCHAR, { CHAR_SIZE, CHAR_BIT,
SCHAR, UCHAR,
1, 1, 0, 1, 1, "unsigned char" } },
{ SHORT, { SHORT_SIZE, 2 * CHAR_BIT,
SHORT, USHORT,
1, 0, 0, 1, 1, "short" } },
{ USHORT, { SHORT_SIZE, 2 * CHAR_BIT,
SHORT, USHORT,
1, 1, 0, 1, 1, "unsigned short" } },
{ INT, { INT_SIZE, 3 * CHAR_BIT,
INT, UINT,
1, 0, 0, 1, 1, "int" } },
{ UINT, { INT_SIZE, 3 * CHAR_BIT,
INT, UINT,
1, 1, 0, 1, 1, "unsigned int" } },
{ LONG, { LONG_SIZE, 4 * CHAR_BIT,
LONG, ULONG,
1, 0, 0, 1, 1, "long" } },
{ ULONG, { LONG_SIZE, 4 * CHAR_BIT,
LONG, ULONG,
1, 1, 0, 1, 1, "unsigned long" } },
{ QUAD, { QUAD_SIZE, 8 * CHAR_BIT,
QUAD, UQUAD,
1, 0, 0, 1, 1, "long long" } },
{ UQUAD, { QUAD_SIZE, 8 * CHAR_BIT,
QUAD, UQUAD,
1, 1, 0, 1, 1, "unsigned long long" } },
{ FLOAT, { FLOAT_SIZE, 4 * CHAR_BIT,
FLOAT, FLOAT,
0, 0, 1, 1, 1, "float" } },
{ DOUBLE, { DOUBLE_SIZE, 8 * CHAR_BIT,
DOUBLE, DOUBLE,
0, 0, 1, 1, 1, "double" } },
{ LDOUBLE, { LDOUBLE_SIZE, 10 * CHAR_BIT,
LDOUBLE, LDOUBLE,
0, 0, 1, 1, 1, "long double" } },
{ VOID, { -1, -1,
VOID, VOID,
0, 0, 0, 0, 0, "void" } },
{ STRUCT, { -1, -1,
STRUCT, STRUCT,
0, 0, 0, 0, 0, "struct" } },
{ UNION, { -1, -1,
UNION, UNION,
0, 0, 0, 0, 0, "union" } },
{ ENUM, { ENUM_SIZE, 3 * CHAR_BIT,
ENUM, ENUM,
1, 0, 0, 1, 1, "enum" } },
{ PTR, { PTR_SIZE, 4 * CHAR_BIT,
PTR, PTR,
0, 1, 0, 0, 1, "pointer" } },
{ ARRAY, { -1, -1,
ARRAY, ARRAY,
0, 0, 0, 0, 0, "array" } },
{ FUNC, { -1, -1,
FUNC, FUNC,
0, 0, 0, 0, 0, "function" } },
};
for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
if (!pflag) {
for (i = 0; i < NTSPEC; i++)
ttab[i].tt_psz = ttab[i].tt_sz;
}
}

126
usr.bin/xlint/common/lint.h Normal file
View File

@ -0,0 +1,126 @@
/* $NetBSD: lint.h,v 1.3 2002/01/31 22:44:00 tv 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_CONFIG_H
#include "config.h"
#else
#define HAVE_DECL_SYS_SIGNAME 1
#endif
#include <sys/types.h>
#include <stddef.h>
#include <err.h>
#include <inttypes.h>
#include <stdio.h>
#include "param.h"
/*
* Type specifiers, used in type structures (type_t) and otherwere.
*/
typedef enum {
NOTSPEC = 0,
SIGNED, /* keyword "signed", only used in the parser */
UNSIGN, /* keyword "unsigned", only used in the parser */
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 */
QUAD, /* (signed) long long */
UQUAD, /* unsigned long long */
FLOAT, /* float */
DOUBLE, /* double or, with tflag, long float */
LDOUBLE, /* long double */
VOID, /* void */
STRUCT, /* structure tag */
UNION, /* union tag */
ENUM, /* enum tag */
PTR, /* pointer */
ARRAY, /* array */
FUNC, /* function */
NTSPEC
} tspec_t;
/*
* size of types, name and classification
*/
typedef struct {
int tt_sz; /* size in bits */
int tt_psz; /* size, different from tt_sz
if pflag is set */
tspec_t tt_styp; /* signed counterpart */
tspec_t tt_utyp; /* unsigned counterpart */
u_int tt_isityp : 1; /* 1 if integer type */
u_int tt_isutyp : 1; /* 1 if unsigned integer type */
u_int tt_isftyp : 1; /* 1 if floating point type */
u_int tt_isatyp : 1; /* 1 if arithmetic type */
u_int tt_issclt : 1; /* 1 if scalar type */
char *tt_name; /* Bezeichnung des Typs */
} ttab_t;
#define size(t) (ttab[t].tt_sz)
#define psize(t) (ttab[t].tt_psz)
#define styp(t) (ttab[t].tt_styp)
#define utyp(t) (ttab[t].tt_utyp)
#define isityp(t) (ttab[t].tt_isityp)
#define isutyp(t) (ttab[t].tt_isutyp)
#define isftyp(t) (ttab[t].tt_isftyp)
#define isatyp(t) (ttab[t].tt_isatyp)
#define issclt(t) (ttab[t].tt_issclt)
extern ttab_t ttab[];
typedef enum {
NODECL, /* until now not declared */
DECL, /* declared */
TDEF, /* tentative defined */
DEF /* defined */
} def_t;
/*
* Following structure contains 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_nxt; /* next free byte in buffer */
} ob_t;
#include "externs.h"

View File

@ -0,0 +1,59 @@
/* $NetBSD: lp64.h,v 1.1 2002/01/18 20:39:23 thorpej Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* 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 for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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.
*/
/*
* Type sizes for LP64 platforms (long, pointer: 64-bit)
*/
#define CHAR_SIZE (CHAR_BIT)
#define SHORT_SIZE (2 * CHAR_BIT)
#define INT_SIZE (4 * CHAR_BIT)
#define LONG_SIZE (8 * CHAR_BIT)
#define QUAD_SIZE (8 * CHAR_BIT)
#define PTR_SIZE (8 * CHAR_BIT)
#define TARG_INT_MAX ((int32_t) (((uint32_t) -1) >> 1))
#define TARG_INT_MIN ((-TARG_INT_MAX) - 1)
#define TARG_UINT_MAX ((uint32_t) -1)
#define TARG_QUAD_MAX ((int64_t) (((uint64_t) -1) >> 1))
#define TARG_QUAD_MIN ((-TARG_QUAD_MAX) - 1)
#define TARG_UQUAD_MAX ((uint64_t) -1)
#define TARG_LONG_MAX TARG_QUAD_MAX
#define TARG_LONG_MIN TARG_QUAD_MIN
#define TARG_ULONG_MAX TARG_UQUAD_MAX

View File

@ -0,0 +1,88 @@
/* $NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv 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.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv Exp $");
#endif
#include <stdlib.h>
#include <string.h>
#include "lint.h"
void *
xmalloc(size_t s)
{
void *p;
if ((p = malloc(s)) == NULL)
nomem();
return (p);
}
void *
xcalloc(size_t n, size_t s)
{
void *p;
if ((p = calloc(n, s)) == NULL)
nomem();
return (p);
}
void *
xrealloc(void *p, size_t s)
{
if ((p = realloc(p, s)) == NULL)
nomem();
return (p);
}
char *
xstrdup(const char *s)
{
char *s2;
if ((s2 = strdup(s)) == NULL)
nomem();
return (s2);
}
void
nomem(void)
{
errx(1, "virtual memory exhausted");
}

View File

@ -0,0 +1,88 @@
/* $NetBSD: param.h,v 1.1 2002/01/18 20:39:24 thorpej 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.
*/
/*
* Minimun size of string buffer. If this is not enough, the buffer
* is enlarged in steps of STRBLEN bytes.
*/
#define STRBLEN 256
/*
* This defines the size of memory blocks which are used to allocate
* memory in larger chunks.
*/
#define MBLKSIZ ((size_t)0x4000)
/*
* Sizes of hash tables
* Should be a prime. Possible primes are
* 307, 401, 503, 601, 701, 809, 907, 1009, 1103, 1201, 1301, 1409, 1511.
*
* HSHSIZ1 symbol table 1st pass
* HSHSIZ2 symbol table 2nd pass
* THSHSIZ2 type table 2nd pass
*/
#define HSHSIZ1 503
#define HSHSIZ2 1009
#define THSHSIZ2 1009
/*
* Pull in target-specific parameters.
*/
#include "targparam.h"
/*
* Make sure this matches wchar_t.
*/
#define WCHAR INT
/*
* long double only in ANSI C.
*
* And the sparc64 long double code generation is broken.
*/
#if !defined(__sparc64__) && defined(__STDC__)
typedef long double ldbl_t;
#else
typedef double ldbl_t;
#endif
/*
* Some traditional compilers are not able to assign structures.
*/
#ifdef __STDC__
#define STRUCT_ASSIGN(dest, src) (dest) = (src)
#else
#define STRUCT_ASSIGN(dest, src) (void)memcpy(&(dest), &(src), \
sizeof (dest));
#endif

View File

@ -1,19 +1,49 @@
# $NetBSD: Makefile,v 1.3 1995/07/04 01:53:05 cgd Exp $
# $NetBSD: Makefile,v 1.25 2002/02/01 01:32:20 ross Exp $
PROG= lint1
SRCS= cgram.c scan.c mem1.c mem.c err.c main1.c decl.c tree.c func.c \
init.c emit.c emit1.c
NOMAN=
LDADD+= -ll
DPADD+= ${LIBL}
YFLAGS= -d
CFLAGS+=-I.
LINTFLAGS=-aehpz
CLEANFILES+=y.tab.h cgram.c scan.c
.include <bsd.own.mk>
BINDIR= /usr/libexec
PROG= lint1
SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
init.c emit.c emit1.c inittyp.c
MAN= lint.7
YHEADER=
# XXX: -O causes the gcc to die on the i386, when compiling tree.o
CFLAGS+= -DXXX_BROKEN_GCC
CPPFLAGS+= -I${.CURDIR} -I.
.if ${OBJECT_FMT} == "a.out"
CPPFLAGS+= -DTARGET_OBJFMT_AOUT
.elif ${OBJECT_FMT} == "COFF"
CPPFLAGS+= -DTARGET_OBJFMT_COFF
.elif ${OBJECT_FMT} == "ELF"
CPPFLAGS+= -DTARGET_OBJFMT_ELF
.else
.BEGIN:
@echo "Unrecognized OBJECT_FMT ${OBJECT_FMT}"
@false
.endif
LINTFLAGS= -aehpz
WFORMAT=1 #hopeless
BINDIR= /usr/libexec
scan.c: cgram.h
CLEANFILES+= ${MAN}
.if ${USETOOLS} == "yes"
LINT1= ${TOOLDIR}/libexec/${MACHINE_GNU_PLATFORM}-lint1
.endif
LINT1?= ./${PROG}
${MAN}: makeman ${LINT1:C/^\.\///} Makefile
sh ${.ALLSRC:M*makeman} ${LINT1} -m >${.TARGET}
LDADD+= -lm
DPADD+= ${LIBM}
.ifndef HOSTPROG
LDADD+= -ll
DPADD+= ${LIBL}
.include <bsd.prog.mk>
.endif

View File

@ -1,7 +1,8 @@
%{
/* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */
/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,11 +33,13 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $");
#endif
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "lint1.h"
@ -55,10 +58,52 @@ int blklev;
*/
int mblklev;
static int toicon __P((tnode_t *));
static void idecl __P((sym_t *, int));
static void ignuptorp __P((void));
/*
* Save the no-warns state and restore it to avoid the problem where
* if (expr) { stmt } / * NOLINT * / stmt;
*/
static int onowarn = -1;
static int toicon(tnode_t *);
static void idecl(sym_t *, int, sbuf_t *);
static void ignuptorp(void);
#ifdef DEBUG
static __inline void CLRWFLGS(void);
static __inline void CLRWFLGS(void)
{
printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__);
clrwflgs();
onowarn = -1;
}
static __inline void SAVE(void);
static __inline void SAVE(void)
{
if (onowarn != -1)
abort();
printf("%s, %d: save flags %s %d = %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__, nowarn);
onowarn = nowarn;
}
static __inline void RESTORE(void);
static __inline void RESTORE(void)
{
if (onowarn != -1) {
nowarn = onowarn;
printf("%s, %d: restore flags %s %d = %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__, nowarn);
onowarn = -1;
} else
CLRWFLGS();
}
#else
#define CLRWFLGS() clrwflgs(), onowarn = -1
#define SAVE() onowarn = nowarn
#define RESTORE() (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn))
#endif
%}
%union {
@ -129,6 +174,7 @@ static void ignuptorp __P((void));
%token T_BREAK
%token T_RETURN
%token T_ASM
%token T_SYMBOLRENAME
%left T_COMMA
%right T_ASSIGN T_OPASS
@ -205,6 +251,7 @@ static void ignuptorp __P((void));
%type <y_tnode> opt_expr
%type <y_strg> string
%type <y_strg> string2
%type <y_sb> opt_asm_or_symbolrename
%%
@ -228,13 +275,14 @@ translation_unit:
;
ext_decl:
func_def {
asm_stmnt
| func_def {
glclup(0);
clrwflgs();
CLRWFLGS();
}
| data_def {
glclup(0);
clrwflgs();
CLRWFLGS();
}
;
@ -278,7 +326,7 @@ data_def:
}
| declspecs deftyp type_init_decls T_SEMI
| error T_SEMI {
globclup();
globclup();
}
| error T_RBRACE {
globclup();
@ -712,7 +760,7 @@ enums_with_opt_comma:
error(54);
} else {
/* trailing "," prohibited in enum declaration */
warning(54);
(void)gnuism(54);
}
$$ = $1;
}
@ -757,24 +805,24 @@ type_init_decls:
;
notype_init_decl:
notype_decl opt_asm_spec {
idecl($1, 0);
notype_decl opt_asm_or_symbolrename {
idecl($1, 0, $2);
chksz($1);
}
| notype_decl opt_asm_spec {
idecl($1, 1);
| notype_decl opt_asm_or_symbolrename {
idecl($1, 1, $2);
} T_ASSIGN initializer {
chksz($1);
}
;
type_init_decl:
type_decl opt_asm_spec {
idecl($1, 0);
type_decl opt_asm_or_symbolrename {
idecl($1, 0, $2);
chksz($1);
}
| type_decl opt_asm_spec {
idecl($1, 1);
| type_decl opt_asm_or_symbolrename {
idecl($1, 1, $2);
} T_ASSIGN initializer {
chksz($1);
}
@ -1015,10 +1063,10 @@ vararg_parameter_type_list:
;
parameter_type_list:
parameter_declaration opt_asm_spec {
parameter_declaration {
$$ = $1;
}
| parameter_type_list T_COMMA parameter_declaration opt_asm_spec {
| parameter_type_list T_COMMA parameter_declaration {
$$ = lnklst($1, $3);
}
;
@ -1051,10 +1099,16 @@ parameter_declaration:
}
;
opt_asm_spec:
/* empty */
opt_asm_or_symbolrename: /* expect only one */
/* empty */ {
$$ = NULL;
}
| T_ASM T_LPARN T_STRING T_RPARN {
freeyyv(&$3, T_STRING);
$$ = NULL;
}
| T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
$$ = $3;
}
;
@ -1212,15 +1266,11 @@ opt_stmnt_list:
;
stmnt_list:
stmnt {
clrwflgs();
}
stmnt
| stmnt_list stmnt {
clrwflgs();
}
| stmnt_list error T_SEMI {
clrwflgs();
RESTORE();
}
| stmnt_list error T_SEMI
;
expr_stmnt:
@ -1235,21 +1285,27 @@ expr_stmnt:
selection_stmnt:
if_without_else {
SAVE();
if2();
if3(0);
}
| if_without_else T_ELSE {
SAVE();
if2();
} stmnt {
CLRWFLGS();
if3(1);
}
| if_without_else T_ELSE error {
CLRWFLGS();
if3(0);
}
| switch_expr stmnt {
CLRWFLGS();
switch2();
}
| switch_expr error {
CLRWFLGS();
switch2();
}
;
@ -1262,35 +1318,46 @@ if_without_else:
if_expr:
T_IF T_LPARN expr T_RPARN {
if1($3);
clrwflgs();
CLRWFLGS();
}
;
switch_expr:
T_SWITCH T_LPARN expr T_RPARN {
switch1($3);
clrwflgs();
CLRWFLGS();
}
;
do_stmnt:
do stmnt {
CLRWFLGS();
}
;
iteration_stmnt:
while_expr stmnt {
CLRWFLGS();
while2();
}
| while_expr error {
CLRWFLGS();
while2();
}
| do stmnt do_while_expr {
do2($3);
| do_stmnt do_while_expr {
do2($2);
ftflg = 0;
}
| do error {
CLRWFLGS();
do2(NULL);
}
| for_exprs stmnt {
CLRWFLGS();
for2();
}
| for_exprs error {
CLRWFLGS();
for2();
}
;
@ -1298,7 +1365,7 @@ iteration_stmnt:
while_expr:
T_WHILE T_LPARN expr T_RPARN {
while1($3);
clrwflgs();
CLRWFLGS();
}
;
@ -1317,7 +1384,7 @@ do_while_expr:
for_exprs:
T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
for1($3, $5, $7);
clrwflgs();
CLRWFLGS();
}
;
@ -1375,10 +1442,10 @@ read_until_rparn:
declaration_list:
declaration {
clrwflgs();
CLRWFLGS();
}
| declaration_list declaration {
clrwflgs();
CLRWFLGS();
}
;
@ -1441,7 +1508,7 @@ expr:
term:
T_NAME {
/* XXX realy neccessary? */
/* XXX really necessary? */
if (yychar < 0)
yychar = yylex();
$$ = getnnode(getsym($1), yychar);
@ -1565,15 +1632,34 @@ identifier:
/* ARGSUSED */
int
yyerror(msg)
char *msg;
yyerror(char *msg)
{
error(249);
if (++sytxerr >= 5)
norecover();
return (0);
}
static inline int uq_gt(uint64_t, uint64_t);
static inline int q_gt(int64_t, int64_t);
static inline int
uq_gt(uint64_t a, uint64_t b)
{
return (a > b);
}
static inline int
q_gt(int64_t a, int64_t b)
{
return (a > b);
}
#define q_lt(a, b) q_gt(b, a)
/*
* Gets a node for a constant and returns the value of this constant
* as integer.
@ -1584,8 +1670,7 @@ yyerror(msg)
* expressions, it frees the memory used for the expression.
*/
static int
toicon(tn)
tnode_t *tn;
toicon(tnode_t *tn)
{
int i;
tspec_t t;
@ -1607,12 +1692,14 @@ toicon(tn)
} else {
i = (int)v->v_quad;
if (isutyp(t)) {
if ((u_quad_t)v->v_quad > INT_MAX) {
if (uq_gt((uint64_t)v->v_quad,
(uint64_t)INT_MAX)) {
/* integral constant too large */
warning(56);
}
} else {
if (v->v_quad > INT_MAX || v->v_quad < INT_MIN) {
if (q_gt(v->v_quad, (int64_t)INT_MAX) ||
q_lt(v->v_quad, (int64_t)INT_MIN)) {
/* integral constant too large */
warning(56);
}
@ -1623,25 +1710,46 @@ toicon(tn)
}
static void
idecl(decl, initflg)
sym_t *decl;
int initflg;
idecl(sym_t *decl, int initflg, sbuf_t *rename)
{
char *s;
initerr = 0;
initsym = decl;
switch (dcs->d_ctx) {
case EXTERN:
if (rename != NULL) {
if (decl->s_rename != NULL)
lerror("idecl() 1");
s = getlblk(1, rename->sb_len + 1);
(void)memcpy(s, rename->sb_name, rename->sb_len + 1);
decl->s_rename = s;
freeyyv(&rename, T_NAME);
}
decl1ext(decl, initflg);
break;
case ARG:
if (rename != NULL) {
/* symbol renaming can't be used on function arguments */
error(310);
freeyyv(&rename, T_NAME);
break;
}
(void)decl1arg(decl, initflg);
break;
case AUTO:
if (rename != NULL) {
/* symbol renaming can't be used on automatic variables */
error(311);
freeyyv(&rename, T_NAME);
break;
}
decl1loc(decl, initflg);
break;
default:
lerror("idecl()");
lerror("idecl() 2");
}
if (initflg && !initerr)
@ -1652,8 +1760,8 @@ idecl(decl, initflg)
* Discard all input tokens up to and including the next
* unmatched right paren
*/
void
ignuptorp()
static void
ignuptorp(void)
{
int level;

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
/* $NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $ */
/* $NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,16 +32,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $");
#endif
#include <ctype.h>
#include "lint1.h"
static void outtt __P((sym_t *, sym_t *));
static void outfstrg __P((strg_t *));
static void outtt(sym_t *, sym_t *);
static void outfstrg(strg_t *);
/*
* Write type into the output buffer.
@ -82,8 +84,7 @@ static void outfstrg __P((strg_t *));
* and 'v' (for volatile)
*/
void
outtype(tp)
type_t *tp;
outtype(type_t *tp)
{
int t, s, na;
sym_t *arg;
@ -153,8 +154,7 @@ outtype(tp)
* it uses its own output buffer for conversion
*/
const char *
ttos(tp)
type_t *tp;
ttos(type_t *tp)
{
static ob_t tob;
ob_t tmp;
@ -184,9 +184,12 @@ ttos(tp)
* refers to this tag, this typename is written
*/
static void
outtt(tag, tdef)
sym_t *tag, *tdef;
outtt(sym_t *tag, sym_t *tdef)
{
/*
* 0 is no longer used.
*/
if (tag->s_name != unnamed) {
outint(1);
outname(tag->s_name);
@ -194,7 +197,12 @@ outtt(tag, tdef)
outint(2);
outname(tdef->s_name);
} else {
outint(0);
outint(3);
outint(tag->s_dpos.p_line);
outchar('.');
outint(getfnid(tag->s_dpos.p_file));
outchar('.');
outint(tag->s_dpos.p_uniq);
}
}
@ -206,11 +214,9 @@ outtt(tag, tdef)
* not here
*/
void
outsym(sym, sc, def)
sym_t *sym;
scl_t sc;
def_t def;
outsym(sym_t *sym, scl_t sc, def_t def)
{
/*
* Static function declarations must also be written to the output
* file. Compatibility of function declarations (for both static
@ -266,6 +272,12 @@ outsym(sym, sc, def)
/* name of the symbol */
outname(sym->s_name);
/* renamed name of symbol, if necessary */
if (sym->s_rename) {
outchar('r');
outname(sym->s_rename);
}
/* type of the symbol */
outtype(sym->s_type);
}
@ -277,10 +289,7 @@ outsym(sym, sc, def)
* they are called with proper argument types
*/
void
outfdef(fsym, posp, rval, osdef, args)
sym_t *fsym, *args;
pos_t *posp;
int rval, osdef;
outfdef(sym_t *fsym, pos_t *posp, int rval, int osdef, sym_t *args)
{
int narg;
sym_t *arg;
@ -352,6 +361,12 @@ outfdef(fsym, posp, rval, osdef, args)
/* name of function */
outname(fsym->s_name);
/* renamed name of function, if necessary */
if (fsym->s_rename) {
outchar('r');
outname(fsym->s_rename);
}
/* argument types and return value */
if (osdef) {
narg = 0;
@ -376,13 +391,11 @@ outfdef(fsym, posp, rval, osdef, args)
* (casted to void)
*/
void
outcall(tn, rvused, rvdisc)
tnode_t *tn;
int rvused, rvdisc;
outcall(tnode_t *tn, int rvused, int rvdisc)
{
tnode_t *args, *arg;
int narg, n, i;
quad_t q;
int64_t q;
tspec_t t;
/* reset buffer */
@ -410,7 +423,8 @@ outcall(tn, rvused, rvdisc)
/* informations about arguments */
for (n = 1; n <= narg; n++) {
/* the last argument is the top one in the tree */
for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ;
for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
continue;
arg = arg->tn_left;
if (arg->tn_op == CON) {
if (isityp(t = arg->tn_type->t_tspec)) {
@ -451,7 +465,8 @@ outcall(tn, rvused, rvdisc)
outint(narg);
for (n = 1; n <= narg; n++) {
/* the last argument is the top one in the tree */
for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ;
for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
continue;
outtype(arg->tn_left->tn_type);
}
/* expected type of return value */
@ -463,8 +478,7 @@ outcall(tn, rvused, rvdisc)
* writes them, enclosed in "" and qouted if necessary, to the output buffer
*/
static void
outfstrg(strg)
strg_t *strg;
outfstrg(strg_t *strg)
{
int c, oc, first;
u_char *cp;
@ -563,8 +577,7 @@ outfstrg(strg)
* writes a record if sym was used
*/
void
outusg(sym)
sym_t *sym;
outusg(sym_t *sym)
{
/* reset buffer */
outclr();

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */
/* $NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,28 +31,27 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $");
#endif
#include <sys/types.h>
#include <stdlib.h>
#include <stdarg.h>
#include "lint1.h"
/* number of errors found */
int nerr;
/* number of syntax errors */
int sytxerr;
#include <stdlib.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "lint1.h"
static const char *basename __P((const char *));
static void verror __P((int, va_list));
static void vwarning __P((int, va_list));
static const char *basename(const char *);
static void verror(int, va_list);
static void vwarning(int, va_list);
const char *msgs[] = {
@ -218,7 +217,7 @@ const char *msgs[] = {
"assignment in conditional context", /* 159 */
"operator '==' found where '=' was expected", /* 160 */
"constant in conditional context", /* 161 */
"comparision of %s with %s, op %s", /* 162 */
"comparison of %s with %s, op %s", /* 162 */
"a cast does not yield an lvalue", /* 163 */
"assignment of negative constant to unsigned type", /* 164 */
"constant truncated by assignment", /* 165 */
@ -286,7 +285,7 @@ const char *msgs[] = {
"const object %s should have initializer", /* 227 */
"function cannot return const or volatile object", /* 228 */
"questionable conversion of function pointer", /* 229 */
"nonportable character comparision, op %s", /* 230 */
"nonportable character comparison, op %s", /* 230 */
"argument %s unused in function %s", /* 231 */
"label %s unused in function %s", /* 232 */
"struct %s never defined", /* 233 */
@ -299,7 +298,7 @@ const char *msgs[] = {
"assignment of different structures", /* 240 */
"dubious operation on enum, op %s", /* 241 */
"combination of '%s' and '%s', op %s", /* 242 */
"dubious comparision of enums, op %s", /* 243 */
"dubious comparison of enums, op %s", /* 243 */
"illegal structure pointer combination", /* 244 */
"illegal structure pointer combination, op %s", /* 245 */
"dubious conversion of enum to '%s'", /* 246 */
@ -330,7 +329,7 @@ const char *msgs[] = {
"switch expression must be of type `int' in traditional C", /* 271 */
"empty translation unit", /* 272 */
"bit-field type '%s' invalid in ANSI C", /* 273 */
"ANSI C forbids comparision of %s with %s", /* 274 */
"ANSI C forbids comparison of %s with %s", /* 274 */
"cast discards 'const' from pointer target type", /* 275 */
"", /* 276 */
"initialisation of '%s' with '%s'", /* 277 */
@ -366,15 +365,29 @@ const char *msgs[] = {
"static variable %s set but not used", /* 307 */
"", /* 308 */
"extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */
"symbol renaming can't be used on function arguments", /* 310 */
"symbol renaming can't be used on automatic variables", /* 311 */
"%s C does not support // comments", /* 312 */
};
/*
* print a list of the messages with their ids
*/
void
msglist(void)
{
int i;
for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
printf("%d\t%s\n", i, msgs[i]);
}
/*
* If Fflag is not set basename() returns a pointer to the last
* component of the path, otherwise it returns the argument.
*/
static const char *
basename(path)
const char *path;
basename(const char *path)
{
const char *cp, *cp1, *cp2;
@ -392,26 +405,28 @@ basename(path)
}
static void
verror(n, ap)
int n;
va_list ap;
verror( int n, va_list ap)
{
const char *fn;
if (ERR_ISSET(n, &msgset))
return;
fn = basename(curr_pos.p_file);
(void)printf("%s(%d): ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
nerr++;
}
static void
vwarning(n, ap)
int n;
va_list ap;
vwarning( int n, va_list ap)
{
const char *fn;
if (ERR_ISSET(n, &msgset))
return;
if (nowarn)
/* this warning is suppressed by a LINTED comment */
return;
@ -419,46 +434,28 @@ vwarning(n, ap)
fn = basename(curr_pos.p_file);
(void)printf("%s(%d): warning: ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
if (wflag)
nerr++;
}
void
#ifdef __STDC__
error(int n, ...)
#else
error(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
verror(n, ap);
va_end(ap);
}
void
#ifdef __STDC__
lerror(const char *msg, ...)
#else
lerror(msg, va_alist)
const char *msg;
va_dcl
#endif
{
va_list ap;
const char *fn;
#ifdef __STDC__
va_start(ap, msg);
#else
va_start(ap);
#endif
fn = basename(curr_pos.p_file);
(void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line);
(void)vfprintf(stderr, msg, ap);
@ -468,66 +465,39 @@ lerror(msg, va_alist)
}
void
#ifdef __STDC__
warning(int n, ...)
#else
warning(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
vwarning(n, ap);
va_end(ap);
}
void
#ifdef __STDC__
message(int n, ...)
#else
message(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
const char *fn;
#ifdef __STDC__
if (ERR_ISSET(n, &msgset))
return;
va_start(ap, n);
#else
va_start(ap);
#endif
fn = basename(curr_pos.p_file);
(void)printf("%s(%d): ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
va_end(ap);
}
int
#ifdef __STDC__
gnuism(int n, ...)
#else
gnuism(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
int msg;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
if (sflag && !gflag) {
verror(n, ap);
msg = 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */
/* $NetBSD: externs1.h,v 1.13 2002/01/18 21:01:39 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -42,16 +42,16 @@ extern int eflag;
extern int Fflag;
extern int gflag;
extern int hflag;
extern int pflag;
extern int rflag;
extern int sflag;
extern int tflag;
extern int uflag;
extern int vflag;
extern int yflag;
extern int wflag;
extern int zflag;
extern void norecover __P((void));
extern void norecover(void);
/*
* cgram.y
@ -60,8 +60,8 @@ extern int blklev;
extern int mblklev;
extern int yydebug;
extern int yyerror __P((char *));
extern int yyparse __P((void));
extern int yyerror(char *);
extern int yyparse(void);
/*
* scan.l
@ -70,41 +70,41 @@ extern pos_t curr_pos;
extern pos_t csrc_pos;
extern symt_t symtyp;
extern FILE *yyin;
extern u_quad_t qbmasks[], qlmasks[], qumasks[];
extern uint64_t qbmasks[], qlmasks[], qumasks[];
extern void initscan __P((void));
extern int sign __P((quad_t, tspec_t, int));
extern int msb __P((quad_t, tspec_t, int));
extern quad_t xsign __P((quad_t, tspec_t, int));
extern void clrwflgs __P((void));
extern sym_t *getsym __P((sbuf_t *));
extern void cleanup __P((void));
extern sym_t *pushdown __P((sym_t *));
extern void rmsym __P((sym_t *));
extern void rmsyms __P((sym_t *));
extern void inssym __P((int, sym_t *));
extern void freeyyv __P((void *, int));
extern int yylex __P((void));
extern void initscan(void);
extern int sign(int64_t, tspec_t, int);
extern int msb(int64_t, tspec_t, int);
extern int64_t xsign(int64_t, tspec_t, int);
extern void clrwflgs(void);
extern sym_t *getsym(sbuf_t *);
extern void cleanup(void);
extern sym_t *pushdown(sym_t *);
extern void rmsym(sym_t *);
extern void rmsyms(sym_t *);
extern void inssym(int, sym_t *);
extern void freeyyv(void *, int);
extern int yylex(void);
/*
* mem1.c
*/
extern const char *fnalloc __P((const char *));
extern const char *fnnalloc __P((const char *, size_t));
extern int getfnid __P((const char *));
extern const char *fnalloc(const char *);
extern const char *fnnalloc(const char *, size_t);
extern int getfnid(const char *);
extern void initmem __P((void));
extern void initmem(void);
extern void *getblk __P((size_t));
extern void *getlblk __P((int, size_t));
extern void freeblk __P((void));
extern void freelblk __P((int));
extern void *getblk(size_t);
extern void *getlblk(int, size_t);
extern void freeblk(void);
extern void freelblk(int);
extern void *tgetblk __P((size_t));
extern tnode_t *getnode __P((void));
extern void tfreeblk __P((void));
extern struct mbl *tsave __P((void));
extern void trestor __P((struct mbl *));
extern void *tgetblk(size_t);
extern tnode_t *getnode(void);
extern void tfreeblk(void);
extern struct mbl *tsave(void);
extern void trestor(struct mbl *);
/*
* err.c
@ -113,11 +113,13 @@ extern int nerr;
extern int sytxerr;
extern const char *msgs[];
extern void error __P((int, ...));
extern void warning __P((int, ...));
extern void message __P((int, ...));
extern int gnuism __P((int, ...));
extern void lerror __P((const char *, ...));
extern void msglist(void);
extern void error(int, ...);
extern void warning(int, ...);
extern void message(int, ...);
extern int gnuism(int, ...);
extern void lerror(const char *, ...)
__attribute__((__noreturn__,__format__(__printf__, 1, 2)));
/*
* decl.c
@ -126,82 +128,82 @@ extern dinfo_t *dcs;
extern const char *unnamed;
extern int enumval;
extern void initdecl __P((void));
extern type_t *gettyp __P((tspec_t));
extern type_t *duptyp __P((const type_t *));
extern type_t *tduptyp __P((const type_t *));
extern int incompl __P((type_t *));
extern void setcompl __P((type_t *, int));
extern void addscl __P((scl_t));
extern void addtype __P((type_t *));
extern void addqual __P((tqual_t));
extern void pushdecl __P((scl_t));
extern void popdecl __P((void));
extern void setasm __P((void));
extern void clrtyp __P((void));
extern void deftyp __P((void));
extern int length __P((type_t *, const char *));
extern int getbound __P((type_t *));
extern sym_t *lnklst __P((sym_t *, sym_t *));
extern void chktyp __P((sym_t *));
extern sym_t *decl1str __P((sym_t *));
extern sym_t *bitfield __P((sym_t *, int));
extern pqinf_t *mergepq __P((pqinf_t *, pqinf_t *));
extern sym_t *addptr __P((sym_t *, pqinf_t *));
extern sym_t *addarray __P((sym_t *, int, int));
extern sym_t *addfunc __P((sym_t *, sym_t *));
extern void chkfdef __P((sym_t *, int));
extern sym_t *dname __P((sym_t *));
extern sym_t *iname __P((sym_t *));
extern type_t *mktag __P((sym_t *, tspec_t, int, int));
extern const char *scltoa __P((scl_t));
extern type_t *compltag __P((type_t *, sym_t *));
extern sym_t *ename __P((sym_t *, int, int));
extern void decl1ext __P((sym_t *, int));
extern void cpuinfo __P((sym_t *, sym_t *));
extern int isredec __P((sym_t *, int *));
extern int eqtype __P((type_t *, type_t *, int, int, int *));
extern void compltyp __P((sym_t *, sym_t *));
extern sym_t *decl1arg __P((sym_t *, int));
extern void cluparg __P((void));
extern void decl1loc __P((sym_t *, int));
extern sym_t *aname __P((void));
extern void globclup __P((void));
extern sym_t *decl1abs __P((sym_t *));
extern void chksz __P((sym_t *));
extern void setsflg __P((sym_t *));
extern void setuflg __P((sym_t *, int, int));
extern void chkusage __P((dinfo_t *));
extern void chkusg1 __P((int, sym_t *));
extern void chkglsyms __P((void));
extern void prevdecl __P((int, sym_t *));
extern void initdecl(void);
extern type_t *gettyp(tspec_t);
extern type_t *duptyp(const type_t *);
extern type_t *tduptyp(const type_t *);
extern int incompl(type_t *);
extern void setcompl(type_t *, int);
extern void addscl(scl_t);
extern void addtype(type_t *);
extern void addqual(tqual_t);
extern void pushdecl(scl_t);
extern void popdecl(void);
extern void setasm(void);
extern void clrtyp(void);
extern void deftyp(void);
extern int length(type_t *, const char *);
extern int getbound(type_t *);
extern sym_t *lnklst(sym_t *, sym_t *);
extern void chktyp(sym_t *);
extern sym_t *decl1str(sym_t *);
extern sym_t *bitfield(sym_t *, int);
extern pqinf_t *mergepq(pqinf_t *, pqinf_t *);
extern sym_t *addptr(sym_t *, pqinf_t *);
extern sym_t *addarray(sym_t *, int, int);
extern sym_t *addfunc(sym_t *, sym_t *);
extern void chkfdef(sym_t *, int);
extern sym_t *dname(sym_t *);
extern sym_t *iname(sym_t *);
extern type_t *mktag(sym_t *, tspec_t, int, int);
extern const char *scltoa(scl_t);
extern type_t *compltag(type_t *, sym_t *);
extern sym_t *ename(sym_t *, int, int);
extern void decl1ext(sym_t *, int);
extern void cpuinfo(sym_t *, sym_t *);
extern int isredec(sym_t *, int *);
extern int eqtype(type_t *, type_t *, int, int, int *);
extern void compltyp(sym_t *, sym_t *);
extern sym_t *decl1arg(sym_t *, int);
extern void cluparg(void);
extern void decl1loc(sym_t *, int);
extern sym_t *aname(void);
extern void globclup(void);
extern sym_t *decl1abs(sym_t *);
extern void chksz(sym_t *);
extern void setsflg(sym_t *);
extern void setuflg(sym_t *, int, int);
extern void chkusage(dinfo_t *);
extern void chkusg1(int, sym_t *);
extern void chkglsyms(void);
extern void prevdecl(int, sym_t *);
/*
* tree.c
*/
extern void initmtab __P((void));
extern type_t *incref __P((type_t *, tspec_t));
extern type_t *tincref __P((type_t *, tspec_t));
extern tnode_t *getcnode __P((type_t *, val_t *));
extern tnode_t *getnnode __P((sym_t *, int));
extern tnode_t *getsnode __P((strg_t *));
extern sym_t *strmemb __P((tnode_t *, op_t, sym_t *));
extern tnode_t *build __P((op_t, tnode_t *, tnode_t *));
extern tnode_t *cconv __P((tnode_t *));
extern int typeok __P((op_t, int, tnode_t *, tnode_t *));
extern tnode_t *promote __P((op_t, int, tnode_t *));
extern tnode_t *convert __P((op_t, int, type_t *, tnode_t *));
extern void cvtcon __P((op_t, int, type_t *, val_t *, val_t *));
extern const char *tyname __P((type_t *));
extern tnode_t *bldszof __P((type_t *));
extern tnode_t *cast __P((tnode_t *, type_t *));
extern tnode_t *funcarg __P((tnode_t *, tnode_t *));
extern tnode_t *funccall __P((tnode_t *, tnode_t *));
extern val_t *constant __P((tnode_t *));
extern void expr __P((tnode_t *, int, int));
extern void chkmisc __P((tnode_t *, int, int, int, int, int, int));
extern int conaddr __P((tnode_t *, sym_t **, ptrdiff_t *));
extern strg_t *catstrg __P((strg_t *, strg_t *));
extern void initmtab(void);
extern type_t *incref(type_t *, tspec_t);
extern type_t *tincref(type_t *, tspec_t);
extern tnode_t *getcnode(type_t *, val_t *);
extern tnode_t *getnnode(sym_t *, int);
extern tnode_t *getsnode(strg_t *);
extern sym_t *strmemb(tnode_t *, op_t, sym_t *);
extern tnode_t *build(op_t, tnode_t *, tnode_t *);
extern tnode_t *cconv(tnode_t *);
extern int typeok(op_t, int, tnode_t *, tnode_t *);
extern tnode_t *promote(op_t, int, tnode_t *);
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
extern const char *tyname(type_t *);
extern tnode_t *bldszof(type_t *);
extern tnode_t *cast(tnode_t *, type_t *);
extern tnode_t *funcarg(tnode_t *, tnode_t *);
extern tnode_t *funccall(tnode_t *, tnode_t *);
extern val_t *constant(tnode_t *);
extern void expr(tnode_t *, int, int);
extern void chkmisc(tnode_t *, int, int, int, int, int, int);
extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *catstrg(strg_t *, strg_t *);
/*
* func.c
@ -221,42 +223,44 @@ extern pos_t scflpos;
extern int ccflg;
extern int llibflg;
extern int nowarn;
extern int bitfieldtype_ok;
extern int plibflg;
extern int quadflg;
extern void pushctrl __P((int));
extern void popctrl __P((int));
extern void chkreach __P((void));
extern void funcdef __P((sym_t *));
extern void funcend __P((void));
extern void label __P((int, sym_t *, tnode_t *));
extern void if1 __P((tnode_t *));
extern void if2 __P((void));
extern void if3 __P((int));
extern void switch1 __P((tnode_t *));
extern void switch2 __P((void));
extern void while1 __P((tnode_t *));
extern void while2 __P((void));
extern void do1 __P((void));
extern void do2 __P((tnode_t *));
extern void for1 __P((tnode_t *, tnode_t *, tnode_t *));
extern void for2 __P((void));
extern void dogoto __P((sym_t *));
extern void docont __P((void));
extern void dobreak __P((void));
extern void doreturn __P((tnode_t *));
extern void glclup __P((int));
extern void argsused __P((int));
extern void constcond __P((int));
extern void fallthru __P((int));
extern void notreach __P((int));
extern void lintlib __P((int));
extern void linted __P((int));
extern void varargs __P((int));
extern void printflike __P((int));
extern void scanflike __P((int));
extern void protolib __P((int));
extern void longlong __P((int));
extern void pushctrl(int);
extern void popctrl(int);
extern void chkreach(void);
extern void funcdef(sym_t *);
extern void funcend(void);
extern void label(int, sym_t *, tnode_t *);
extern void if1(tnode_t *);
extern void if2(void);
extern void if3(int);
extern void switch1(tnode_t *);
extern void switch2(void);
extern void while1(tnode_t *);
extern void while2(void);
extern void do1(void);
extern void do2(tnode_t *);
extern void for1(tnode_t *, tnode_t *, tnode_t *);
extern void for2(void);
extern void dogoto(sym_t *);
extern void docont(void);
extern void dobreak(void);
extern void doreturn(tnode_t *);
extern void glclup(int);
extern void argsused(int);
extern void constcond(int);
extern void fallthru(int);
extern void notreach(int);
extern void lintlib(int);
extern void linted(int);
extern void varargs(int);
extern void printflike(int);
extern void scanflike(int);
extern void protolib(int);
extern void longlong(int);
extern void bitfieldtype(int);
/*
* init.c
@ -265,17 +269,17 @@ extern int initerr;
extern sym_t *initsym;
extern int startinit;
extern void prepinit __P((void));
extern void initrbr __P((void));
extern void initlbr __P((void));
extern void mkinit __P((tnode_t *));
extern void prepinit(void);
extern void initrbr(void);
extern void initlbr(void);
extern void mkinit(tnode_t *);
/*
* emit.c
*/
extern void outtype __P((type_t *));
extern const char *ttos __P((type_t *));
extern void outsym __P((sym_t *, scl_t, def_t));
extern void outfdef __P((sym_t *, pos_t *, int, int, sym_t *));
extern void outcall __P((tnode_t *, int, int));
extern void outusg __P((sym_t *));
extern void outtype(type_t *);
extern const char *ttos(type_t *);
extern void outsym(sym_t *, scl_t, def_t);
extern void outfdef(sym_t *, pos_t *, int, int, sym_t *);
extern void outcall(tnode_t *, int, int);
extern void outusg(sym_t *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $ */
/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,15 +31,16 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $");
#endif
#include <stdlib.h>
#include <string.h>
#include "lint1.h"
#include "y.tab.h"
#include "cgram.h"
/*
* Contains a pointer to the symbol table entry of the current function
@ -128,6 +129,12 @@ int llibflg;
*/
int nowarn;
/*
* Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE
* directive.
*/
int bitfieldtype_ok;
/*
* Nonzero if complaints about use of "long long" are suppressed in
* the next statement or declaration.
@ -138,8 +145,7 @@ int quadflg;
* Puts a new element at the top of the stack used for control statements.
*/
void
pushctrl(env)
int env;
pushctrl(int env)
{
cstk_t *ci;
@ -153,8 +159,7 @@ pushctrl(env)
* Removes the top element of the stack used for control statements.
*/
void
popctrl(env)
int env;
popctrl(int env)
{
cstk_t *ci;
clst_t *cl;
@ -179,7 +184,7 @@ popctrl(env)
* Prints a warning if a statement cannot be reached.
*/
void
chkreach()
chkreach(void)
{
if (!reached && !rchflg) {
/* statement not reached */
@ -199,8 +204,7 @@ chkreach()
* redeclaration etc..
*/
void
funcdef(fsym)
sym_t *fsym;
funcdef(sym_t *fsym)
{
int n, warn;
sym_t *arg, *sym, *rdsym;
@ -322,7 +326,7 @@ funcdef(fsym)
}
if (dcs->d_notyp)
/* return value is implizitly declared to be int */
/* return value is implicitly declared to be int */
fsym->s_rimpl = 1;
reached = 1;
@ -332,7 +336,7 @@ funcdef(fsym)
* Called at the end of a function definition.
*/
void
funcend()
funcend(void)
{
sym_t *arg;
int n;
@ -368,7 +372,7 @@ funcend()
/*
* write the information about the function definition to the
* output file
* inline functions explicitely declared extern are written as
* inline functions explicitly declared extern are written as
* declarations only.
*/
if (dcs->d_scl == EXTERN && funcsym->s_inline) {
@ -398,14 +402,12 @@ funcend()
* tn expression if typ == T_CASE
*/
void
label(typ, sym, tn)
int typ;
sym_t *sym;
tnode_t *tn;
label(int typ, sym_t *sym, tnode_t *tn)
{
cstk_t *ci;
clst_t *cl;
val_t *v, *nv;
val_t *v;
val_t nv;
tspec_t t;
switch (typ) {
@ -422,7 +424,8 @@ label(typ, sym, tn)
case T_CASE:
/* find the stack entry for the innermost switch statement */
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* case not in switch */
@ -462,28 +465,28 @@ label(typ, sym, tn)
* to the type of the switch expression
*/
v = constant(tn);
nv = xcalloc(1, sizeof (val_t));
cvtcon(CASE, 0, ci->c_swtype, nv, v);
(void) memset(&nv, 0, sizeof nv);
cvtcon(CASE, 0, ci->c_swtype, &nv, v);
free(v);
/* look if we had this value already */
for (cl = ci->c_clst; cl != NULL; cl = cl->cl_nxt) {
if (cl->cl_val.v_quad == nv->v_quad)
if (cl->cl_val.v_quad == nv.v_quad)
break;
}
if (cl != NULL && isutyp(nv->v_tspec)) {
if (cl != NULL && isutyp(nv.v_tspec)) {
/* duplicate case in switch, %lu */
error(200, (u_long)nv->v_quad);
error(200, (u_long)nv.v_quad);
} else if (cl != NULL) {
/* duplicate case in switch, %ld */
error(199, (long)nv->v_quad);
error(199, (long)nv.v_quad);
} else {
/*
* append the value to the list of
* case values
*/
cl = xcalloc(1, sizeof (clst_t));
STRUCT_ASSIGN(cl->cl_val, *nv);
STRUCT_ASSIGN(cl->cl_val, nv);
cl->cl_nxt = ci->c_clst;
ci->c_clst = cl;
}
@ -494,7 +497,8 @@ label(typ, sym, tn)
case T_DEFAULT:
/* find the stack entry for the innermost switch statement */
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* default outside switch */
@ -519,9 +523,9 @@ label(typ, sym, tn)
* T_IF T_LPARN expr T_RPARN
*/
void
if1(tn)
tnode_t *tn;
if1(tnode_t *tn)
{
if (tn != NULL)
tn = cconv(tn);
if (tn != NULL)
@ -535,8 +539,9 @@ if1(tn)
* if_without_else T_ELSE
*/
void
if2()
if2(void)
{
cstk->c_rchif = reached ? 1 : 0;
reached = 1;
}
@ -546,9 +551,9 @@ if2()
* if_without_else T_ELSE stmnt
*/
void
if3(els)
int els;
if3(int els)
{
if (els) {
reached |= cstk->c_rchif;
} else {
@ -561,8 +566,7 @@ if3(els)
* T_SWITCH T_LPARN expr T_RPARN
*/
void
switch1(tn)
tnode_t *tn;
switch1(tnode_t *tn)
{
tspec_t t;
type_t *tp;
@ -613,9 +617,9 @@ switch1(tn)
* switch_expr stmnt
*/
void
switch2()
switch2(void)
{
int nenum, nclab;
int nenum = 0, nclab = 0;
sym_t *esym;
clst_t *cl;
@ -668,9 +672,9 @@ switch2()
* T_WHILE T_LPARN expr T_RPARN
*/
void
while1(tn)
tnode_t *tn;
while1(tnode_t *tn)
{
if (!reached) {
/* loop not entered at top */
warning(207);
@ -705,8 +709,9 @@ while1(tn)
* while_expr error
*/
void
while2()
while2(void)
{
/*
* The end of the loop can be reached if it is no endless loop
* or there was a break statement which was reached.
@ -721,8 +726,9 @@ while2()
* T_DO
*/
void
do1()
do1(void)
{
if (!reached) {
/* loop not entered at top */
warning(207);
@ -738,9 +744,9 @@ do1()
* do error
*/
void
do2(tn)
tnode_t *tn;
do2(tnode_t *tn)
{
/*
* If there was a continue statement the expression controlling the
* loop is reached.
@ -782,9 +788,9 @@ do2(tn)
* T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN
*/
void
for1(tn1, tn2, tn3)
tnode_t *tn1, *tn2, *tn3;
for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
{
/*
* If there is no initialisation expression it is possible that
* it is intended not to enter the loop at top.
@ -843,7 +849,7 @@ for1(tn1, tn2, tn3)
* for_exprs error
*/
void
for2()
for2(void)
{
pos_t cpos, cspos;
tnode_t *tn3;
@ -888,9 +894,9 @@ for2()
* T_GOTO error T_SEMI
*/
void
dogoto(lab)
sym_t *lab;
dogoto(sym_t *lab)
{
setuflg(lab, 0, 0);
chkreach();
@ -902,7 +908,7 @@ dogoto(lab)
* T_BREAK T_SEMI
*/
void
dobreak()
dobreak(void)
{
cstk_t *ci;
@ -928,11 +934,12 @@ dobreak()
* T_CONTINUE T_SEMI
*/
void
docont()
docont(void)
{
cstk_t *ci;
for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* continue outside loop */
@ -951,14 +958,14 @@ docont()
* T_RETURN expr T_SEMI
*/
void
doreturn(tn)
tnode_t *tn;
doreturn(tnode_t *tn)
{
tnode_t *ln, *rn;
cstk_t *ci;
op_t op;
for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) ;
for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt)
continue;
if (tn != NULL) {
ci->c_retval = 1;
@ -1020,8 +1027,7 @@ doreturn(tn)
* Especially remove informations about unused lint comments.
*/
void
glclup(silent)
int silent;
glclup(int silent)
{
pos_t cpos;
@ -1072,9 +1078,9 @@ glclup(silent)
* for usage. A missing argument is taken to be 0.
*/
void
argsused(n)
int n;
argsused(int n)
{
if (n == -1)
n = 0;
@ -1098,9 +1104,9 @@ argsused(n)
* to the function definition. A missing argument is taken to be 0.
*/
void
varargs(n)
int n;
varargs(int n)
{
if (n == -1)
n = 0;
@ -1124,9 +1130,9 @@ varargs(n)
* used the check the types of remaining arguments.
*/
void
printflike(n)
int n;
printflike(int n)
{
if (n == -1)
n = 0;
@ -1150,9 +1156,9 @@ printflike(n)
* used the check the types of remaining arguments.
*/
void
scanflike(n)
int n;
scanflike(int n)
{
if (n == -1)
n = 0;
@ -1175,9 +1181,9 @@ scanflike(n)
*/
/* ARGSUSED */
void
constcond(n)
int n;
constcond(int n)
{
ccflg = 1;
}
@ -1187,9 +1193,9 @@ constcond(n)
*/
/* ARGSUSED */
void
fallthru(n)
int n;
fallthru(int n)
{
ftflg = 1;
}
@ -1199,18 +1205,18 @@ fallthru(n)
*/
/* ARGSUSED */
void
notreach(n)
int n;
notreach(int n)
{
reached = 0;
rchflg = 1;
}
/* ARGSUSED */
void
lintlib(n)
int n;
lintlib(int n)
{
if (dcs->d_ctx != EXTERN) {
/* must be outside function: ** %s ** */
warning(280, "LINTLIBRARY");
@ -1225,21 +1231,39 @@ lintlib(n)
*/
/* ARGSUSED */
void
linted(n)
int n;
linted(int n)
{
#ifdef DEBUG
printf("%s, %d: nowarn = 1\n", curr_pos.p_file, curr_pos.p_line);
#endif
nowarn = 1;
}
/*
* Suppress bitfield type errors on the current line.
*/
/* ARGSUSED */
void
bitfieldtype(int n)
{
#ifdef DEBUG
printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file,
curr_pos.p_line);
#endif
bitfieldtype_ok = 1;
}
/*
* PROTOTLIB in conjunction with LINTLIBRARY can be used to handle
* prototypes like function definitions. This is done if the argument
* to PROTOLIB is nonzero. Otherwise prototypes are handled normaly.
*/
void
protolib(n)
int n;
protolib(int n)
{
if (dcs->d_ctx != EXTERN) {
/* must be outside function: ** %s ** */
warning(280, "PROTOLIB");
@ -1254,8 +1278,8 @@ protolib(n)
*/
/* ARGSUSED */
void
longlong(n)
int n;
longlong(int n)
{
quadflg = 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $ */
/* $NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $");
#endif
#include <stdlib.h>
@ -40,7 +41,7 @@ static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $";
#include "lint1.h"
/*
* initerr is set as soon as a fatal error occured in an initialisation.
* initerr is set as soon as a fatal error occurred in an initialisation.
* The effect is that the rest of the initialisation is ignored (parsed
* by yacc, expression trees built, but no initialisation takes place).
*/
@ -53,12 +54,12 @@ sym_t *initsym;
istk_t *initstk;
static void popi2 __P((void));
static void popinit __P((int));
static void pushinit __P((void));
static void testinit __P((void));
static void nextinit __P((int));
static int strginit __P((tnode_t *));
static void popi2(void);
static void popinit(int);
static void pushinit(void);
static void testinit(void);
static void nextinit(int);
static int strginit(tnode_t *);
/*
@ -66,7 +67,7 @@ static int strginit __P((tnode_t *));
* which is to be initialized on it.
*/
void
prepinit()
prepinit(void)
{
istk_t *istk;
@ -93,7 +94,7 @@ prepinit()
}
static void
popi2()
popi2(void)
{
istk_t *istk;
sym_t *m;
@ -124,9 +125,9 @@ popi2()
}
static void
popinit(brace)
int brace;
popinit(int brace)
{
if (brace) {
/*
* Take all entries, including the first which requires
@ -150,7 +151,7 @@ popinit(brace)
}
static void
pushinit()
pushinit(void)
{
istk_t *istk;
int cnt;
@ -235,7 +236,7 @@ pushinit()
}
static void
testinit()
testinit(void)
{
istk_t *istk;
@ -266,9 +267,9 @@ testinit()
}
static void
nextinit(brace)
int brace;
nextinit(int brace)
{
if (!brace) {
if (initstk->i_type == NULL &&
!issclt(initstk->i_subt->t_tspec)) {
@ -303,8 +304,9 @@ nextinit(brace)
}
void
initlbr()
initlbr(void)
{
if (initerr)
return;
@ -325,8 +327,9 @@ initlbr()
}
void
initrbr()
initrbr(void)
{
if (initerr)
return;
@ -334,8 +337,7 @@ initrbr()
}
void
mkinit(tn)
tnode_t *tn;
mkinit(tnode_t *tn)
{
ptrdiff_t offs;
sym_t *sym;
@ -351,7 +353,7 @@ mkinit(tn)
/*
* Do not test for automatic aggregat initialisation. If the
* initalizer starts with a brace we have the warning already.
* initializer starts with a brace we have the warning already.
* If not, an error will be printed that the initializer must
* be enclosed by braces.
*/
@ -412,7 +414,7 @@ mkinit(tn)
tmem = tsave();
expr(tn, 1, 0);
trestor(tmem);
if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) {
/*
* Bit-fields can be initialized in trad. C only by integer
@ -446,8 +448,7 @@ mkinit(tn)
static int
strginit(tn)
tnode_t *tn;
strginit(tnode_t *tn)
{
tspec_t t;
istk_t *istk;

View File

@ -1,6 +1,7 @@
/* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */
/* $NetBSD: lint1.h,v 1.12 2002/01/31 19:33:27 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -34,14 +35,29 @@
#include "lint.h"
#include "op.h"
/* XXX - works for most systems, but the whole ALIGN thing needs to go away */
#ifndef ALIGN
#define ALIGN(x) (((x) + 7) & ~7)
#endif
/*
* Describes the position of a declaration or anything else.
*/
typedef struct {
int p_line;
const char *p_file;
int p_uniq; /* uniquifier */
} pos_t;
/* Copies curr_pos, keeping things unique. */
#define UNIQUE_CURR_POS(pos) \
do { \
STRUCT_ASSIGN((pos), curr_pos); \
curr_pos.p_uniq++; \
if (curr_pos.p_file == csrc_pos.p_file) \
csrc_pos.p_uniq++; \
} while (0)
/*
* Strings cannot be referenced to simply by a pointer to its first
* char. This is because strings can contain NUL characters other than the
@ -76,7 +92,7 @@ typedef struct {
int v_ansiu; /* set if an integer constant is
unsigned in ANSI C */
union {
quad_t _v_quad; /* integers */
int64_t _v_quad; /* integers */
ldbl_t _v_ldbl; /* floats */
} v_u;
} val_t;
@ -132,11 +148,11 @@ typedef struct type {
str_t *_t_str; /* struct/union tag */
enum_t *_t_enum; /* enum tag */
struct sym *_t_args; /* arguments (if t_proto) */
struct {
u_int _t_flen : 8; /* length of bit-field */
u_int _t_foffs : 24; /* offset of bit-field */
} _t_u;
} t_u;
struct {
u_int _t_flen : 8; /* length of bit-field */
u_int _t_foffs : 24; /* offset of bit-field */
} t_b;
struct type *t_subt; /* element type (arrays), return value
(functions), or type pointer points to */
} type_t;
@ -146,8 +162,8 @@ typedef struct type {
#define t_field t_u._t_field
#define t_enum t_u._t_enum
#define t_args t_u._t_args
#define t_flen t_u._t_u._t_flen
#define t_foffs t_u._t_u._t_foffs
#define t_flen t_b._t_flen
#define t_foffs t_b._t_foffs
/*
* types of symbols
@ -187,6 +203,7 @@ typedef enum {
*/
typedef struct sym {
const char *s_name; /* name */
const char *s_rename; /* renamed symbol's given name */
pos_t s_dpos; /* position of last (prototype)definition,
prototypedeclaration, no-prototype-def.,
tentative definition or declaration,
@ -378,3 +395,20 @@ typedef struct cstk {
} cstk_t;
#include "externs1.h"
#define ERR_SETSIZE 1024
#define __NERRBITS (sizeof(unsigned int))
typedef struct err_set {
unsigned int errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
} err_set;
#define ERR_SET(n, p) \
((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
#define ERR_CLR(n, p) \
((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
#define ERR_ISSET(n, p) \
((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS)))
#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
extern err_set msgset;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $ */
/* $NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,14 +31,18 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $");
#endif
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include "lint1.h"
@ -49,7 +53,7 @@ int yflag;
* Print warnings if an assignment of an integertype to another integertype
* causes an implizit narrowing conversion. If aflag is 1, these warnings
* are printed only if the source type is at least as wide as long. If aflag
* is greather then 1, they are always printed.
* is greater than 1, they are always printed.
*/
int aflag;
@ -71,6 +75,9 @@ int Fflag;
/* Enable some extensions of gcc */
int gflag;
/* Treat warnings as errors */
int wflag;
/*
* Apply a number of heuristic tests to attempt to intuit bugs, improve
* style, and reduce waste.
@ -104,16 +111,22 @@ int vflag = 1;
/* Complain about structures which are never defined. */
int zflag = 1;
static void usage __P((void));
err_set msgset;
static void usage(void);
int main(int, char *[]);
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int c;
char *ptr;
while ((c = getopt(argc, argv, "abcdeghprstuvyzF")) != -1) {
setprogname(argv[0]);
ERR_ZERO(&msgset);
while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
switch (c) {
case 'a': aflag++; break;
case 'b': bflag = 1; break;
@ -128,10 +141,35 @@ main(argc, argv)
case 's': sflag = 1; break;
case 't': tflag = 1; break;
case 'u': uflag = 0; break;
case 'w': wflag = 1; break;
case 'v': vflag = 0; break;
case 'y': yflag = 1; break;
case 'z': zflag = 0; break;
case '?': usage();
case 'm':
msglist();
return(0);
case 'X':
for (ptr = strtok(optarg, ","); ptr;
ptr = strtok(NULL, ",")) {
char *eptr;
long msg = strtol(ptr, &eptr, 0);
if ((msg == LONG_MIN || msg == LONG_MAX) &&
errno == ERANGE)
err(1, "invalid error message id '%s'",
ptr);
if (*eptr || ptr == eptr || msg < 0 ||
msg >= ERR_SETSIZE)
errx(1, "invalid error message id '%s'",
ptr);
ERR_SET(msg, &msgset);
}
break;
case '?':
default:
usage();
break;
}
}
argc -= optind;
@ -168,14 +206,16 @@ main(argc, argv)
}
static void
usage()
usage(void)
{
(void)fprintf(stderr, "usage: lint1 [-abcdeghprstuvyzF] src dest\n");
(void)fprintf(stderr,
"Usage: %s [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n",
getprogname());
exit(1);
}
void
norecover()
norecover(void)
{
/* cannot recover from previous errors */
error(224);

View File

@ -0,0 +1,94 @@
#!/bin/sh
# $NetBSD$
#
# Copyright (c) 2000 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
# 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 the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``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 FOUNDATION OR CONTRIBUTORS
# 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.
cat << \__EOF
.\" $NetBSD$
.\"
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Christos Zoulas.
.\"
.\" 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 the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``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 FOUNDATION OR CONTRIBUTORS
.\" 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.
.Dd July 5, 2000
.Dt LINT 7
.Os
.Sh NAME
.Nm lint
.Nd Lint error message list
.Sh DESCRIPTION
The following is a list of message id's and messages produced by
.Xr lint 1 .
It is intended to be used with
.Fl X
flag of
.Xr lint 1 .
.Pp
.Bd -ragged -offset indent -compact
.Bl -column "Id# Message"
__EOF
"$@" | sed -e 's/^/.It /' -e 's/\\/\\e/g' -e "s/'/\\'/"
echo ".El"
echo ".Ed"

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $ */
/* $NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $");
#endif
#include <sys/types.h>
@ -41,7 +42,6 @@ static char rcsid[] = "$NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include "lint1.h"
@ -57,15 +57,13 @@ typedef struct fn {
static fn_t *fnames;
static fn_t *srchfn __P((const char *, size_t));
static fn_t *srchfn(const char *, size_t);
/*
* Look for a Filename of length l.
*/
static fn_t *
srchfn(s, len)
const char *s;
size_t len;
srchfn(const char *s, size_t len)
{
fn_t *fn;
@ -80,16 +78,14 @@ srchfn(s, len)
* Return a shared string for filename s.
*/
const char *
fnalloc(s)
const char *s;
fnalloc(const char *s)
{
return (s != NULL ? fnnalloc(s, strlen(s)) : NULL);
}
const char *
fnnalloc(s, len)
const char *s;
size_t len;
fnnalloc(const char *s, size_t len)
{
fn_t *fn;
@ -121,8 +117,7 @@ fnnalloc(s, len)
* Get id of a filename.
*/
int
getfnid(s)
const char *s;
getfnid(const char *s)
{
fn_t *fn;
@ -163,12 +158,12 @@ static mbl_t *frmblks;
/* length of new allocated memory blocks */
static size_t mblklen;
static void *xgetblk __P((mbl_t **, size_t));
static void xfreeblk __P((mbl_t **));
static mbl_t *xnewblk __P((void));
static void *xgetblk(mbl_t **, size_t);
static void xfreeblk(mbl_t **);
static mbl_t *xnewblk(void);
static mbl_t *
xnewblk()
xnewblk(void)
{
mbl_t *mb;
int prot, flags;
@ -182,8 +177,6 @@ xnewblk()
mb->blk = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
if (mb->blk == (void *)-1)
err(1, "can't map memory");
if (ALIGN((u_long)mb->blk) != (u_long)mb->blk)
errx(1, "mapped address is not aligned");
mb->size = mblklen;
@ -199,9 +192,7 @@ xnewblk()
* zero'd in xfreeblk().
*/
static void *
xgetblk(mbp, s)
mbl_t **mbp;
size_t s;
xgetblk(mbl_t **mbp, size_t s)
{
mbl_t *mb;
void *p;
@ -230,8 +221,7 @@ xgetblk(mbp, s)
* used memory to zero.
*/
static void
xfreeblk(fmbp)
mbl_t **fmbp;
xfreeblk(mbl_t **fmbp)
{
mbl_t *mb;
@ -244,7 +234,7 @@ xfreeblk(fmbp)
}
void
initmem()
initmem(void)
{
int pgsz;
@ -254,15 +244,14 @@ initmem()
mblks = xcalloc(nmblks = ML_INC, sizeof (mbl_t *));
}
/*
* Allocate memory associated with level l.
*/
void *
getlblk(l, s)
int l;
size_t s;
getlblk(int l, size_t s)
{
while (l >= nmblks) {
mblks = xrealloc(mblks, (nmblks + ML_INC) * sizeof (mbl_t *));
(void)memset(&mblks[nmblks], 0, ML_INC * sizeof (mbl_t *));
@ -272,9 +261,9 @@ getlblk(l, s)
}
void *
getblk(s)
size_t s;
getblk(size_t s)
{
return (getlblk(mblklev, s));
}
@ -282,15 +271,16 @@ getblk(s)
* Free all memory associated with level l.
*/
void
freelblk(l)
int l;
freelblk(int l)
{
xfreeblk(&mblks[l]);
}
void
freeblk()
freeblk(void)
{
freelblk(mblklev);
}
@ -301,9 +291,9 @@ freeblk()
static mbl_t *tmblk;
void *
tgetblk(s)
size_t s;
tgetblk(size_t s)
{
return (xgetblk(&tmblk, s));
}
@ -311,17 +301,19 @@ tgetblk(s)
* Get memory for a new tree node.
*/
tnode_t *
getnode()
getnode(void)
{
return (tgetblk(sizeof (tnode_t)));
}
/*
* Free all memory which is allocated by the the current expression.
* Free all memory which is allocated by the current expression.
*/
void
tfreeblk()
tfreeblk(void)
{
xfreeblk(&tmblk);
}
@ -331,7 +323,7 @@ tfreeblk()
* used to restore the memory.
*/
mbl_t *
tsave()
tsave(void)
{
mbl_t *tmem;
@ -346,9 +338,9 @@ tsave()
* tfreeblk() frees the restored memory.
*/
void
trestor(tmem)
mbl_t *tmem;
trestor(mbl_t *tmem)
{
tfreeblk();
if (tmblk != NULL) {
free(tmblk->blk);

View File

@ -48,7 +48,7 @@ typedef struct {
u_int m_tlansiu : 1; /* warning if left op. is unsign. in ANSI C */
u_int m_transiu : 1; /* warning if right op. is unsign. in ANSI C */
u_int m_tpconf : 1; /* test possible precedence confusion */
u_int m_comp : 1; /* op. performs comparision */
u_int m_comp : 1; /* op. performs comparison */
u_int m_enumop : 1; /* valid operation on enums */
u_int m_badeop : 1; /* dubious operation on enums */
u_int m_eqwarn : 1; /* warning if on operand stems from == */

View File

@ -1,7 +1,8 @@
%{
/* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */
/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,8 +33,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $");
#endif
#include <stdlib.h>
@ -43,44 +45,42 @@ static char rcsid[] = "$NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $";
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <err.h>
#include "lint1.h"
#include "y.tab.h"
#include "cgram.h"
#define CHAR_MASK (~(~0 << CHAR_BIT))
/* XXX declaration of strtouq() is missing in stdlib.h ? */
extern u_quad_t strtouq __P((const char *, char **, int));
#define YY_NO_UNPUT
/* Current position (its also updated when an included file is parsed) */
pos_t curr_pos = { 1, "" };
pos_t curr_pos = { 1, "", 0 };
/*
* Current position in C source (not updated when an included file is
* parsed).
*/
pos_t csrc_pos = { 1, "" };
pos_t csrc_pos = { 1, "", 0 };
static void incline __P((void));
static void badchar __P((int));
static sbuf_t *allocsb __P((void));
static void freesb __P((sbuf_t *));
static int inpc __P((void));
static int hash __P((const char *));
static sym_t *search __P((sbuf_t *));
static int name __P((void));
static int keyw __P((sym_t *));
static int icon __P((int));
static int fcon __P((void));
static int operator __P((int, op_t));
static int ccon __P((void));
static int wccon __P((void));
static int getescc __P((int));
static void directive __P((void));
static void comment __P((void));
static int string __P((void));
static int wcstrg __P((void));
static void incline(void);
static void badchar(int);
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 name(void);
static int keyw(sym_t *);
static int icon(int);
static int fcon(void);
static int operator(int, op_t);
static int ccon(void);
static int wccon(void);
static int getescc(int);
static void directive(void);
static void comment(void);
static void slashslashcomment(void);
static int string(void);
static int wcstrg(void);
%}
@ -154,22 +154,26 @@ EX ([eE][+-]?[0-9]+)
\n incline();
\t|" "|\f|\v ;
"/*" comment();
"//" slashslashcomment();
. badchar(yytext[0]);
%%
static void
incline()
incline(void)
{
curr_pos.p_line++;
if (curr_pos.p_file == csrc_pos.p_file)
curr_pos.p_uniq = 0;
if (curr_pos.p_file == csrc_pos.p_file) {
csrc_pos.p_line++;
csrc_pos.p_uniq = 0;
}
}
static void
badchar(c)
int c;
badchar(int c)
{
/* unknown character \%o */
error(250, c);
}
@ -212,6 +216,7 @@ static struct kwtab {
{ "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 },
{ "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 },
{ "int", T_TYPE, 0, INT, 0, 0, 0 },
{ "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 },
{ "long", T_TYPE, 0, LONG, 0, 0, 0 },
{ "register", T_SCLASS, REG, 0, 0, 0, 0 },
{ "return", T_RETURN, 0, 0, 0, 0, 0 },
@ -238,13 +243,13 @@ static struct kwtab {
static sym_t *symtab[HSHSIZ1];
/* bit i of the entry with index i is set */
u_quad_t qbmasks[sizeof(u_quad_t) * CHAR_BIT];
uint64_t qbmasks[sizeof(uint64_t) * CHAR_BIT];
/* least significant i bits are set in the entry with index i */
u_quad_t qlmasks[sizeof(u_quad_t) * CHAR_BIT + 1];
uint64_t qlmasks[sizeof(uint64_t) * CHAR_BIT + 1];
/* least significant i bits are not set in the entry with index i */
u_quad_t qumasks[sizeof(u_quad_t) * CHAR_BIT + 1];
uint64_t qumasks[sizeof(uint64_t) * CHAR_BIT + 1];
/* free list for sbuf structures */
static sbuf_t *sbfrlst;
@ -258,12 +263,12 @@ symt_t symtyp;
* in a extra table for each name we found.
*/
void
initscan()
initscan(void)
{
struct kwtab *kw;
sym_t *sym;
int h, i;
u_quad_t uq;
uint64_t uq;
for (kw = kwtab; kw->kw_name != NULL; kw++) {
if (kw->kw_stdc && tflag)
@ -288,21 +293,21 @@ initscan()
}
/* initialize bit-masks for quads */
for (i = 0; i < sizeof (u_quad_t) * CHAR_BIT; i++) {
qbmasks[i] = (u_quad_t)1 << i;
uq = ~(u_quad_t)0 << i;
for (i = 0; i < sizeof (uint64_t) * CHAR_BIT; i++) {
qbmasks[i] = (uint64_t)1 << i;
uq = ~(uint64_t)0 << i;
qumasks[i] = uq;
qlmasks[i] = ~uq;
}
qumasks[i] = 0;
qlmasks[i] = ~(u_quad_t)0;
qlmasks[i] = ~(uint64_t)0;
}
/*
* Get a free sbuf structure, if possible from the free list
*/
static sbuf_t *
allocsb()
allocsb(void)
{
sbuf_t *sb;
@ -319,9 +324,9 @@ allocsb()
* Put a sbuf structure to the free list
*/
static void
freesb(sb)
sbuf_t *sb;
freesb(sbuf_t *sb)
{
sb->sb_nxt = sbfrlst;
sbfrlst = sb;
}
@ -331,7 +336,7 @@ freesb(sb)
* Increment line count(s) if necessary.
*/
static int
inpc()
inpc(void)
{
int c;
@ -341,8 +346,7 @@ inpc()
}
static int
hash(s)
const char *s;
hash(const char *s)
{
u_int v;
const u_char *us;
@ -371,7 +375,7 @@ hash(s)
* to the symbol table entry.
*/
static int
name()
name(void)
{
char *s;
sbuf_t *sb;
@ -409,8 +413,7 @@ name()
}
static sym_t *
search(sb)
sbuf_t *sb;
search(sbuf_t *sb)
{
sym_t *sym;
@ -423,10 +426,9 @@ search(sb)
return (NULL);
}
static int
keyw(sym)
sym_t *sym;
keyw(sym_t *sym)
{
int t;
@ -445,16 +447,15 @@ keyw(sym)
* The value is returned in yylval. icon() (and yylex()) returns T_CON.
*/
static int
icon(base)
int base;
icon(int base)
{
int l_suffix, u_suffix;
int len;
const char *cp;
char c, *eptr;
tspec_t typ;
u_long ul;
u_quad_t uq;
u_long ul = 0;
uint64_t uq = 0;
int ansiu;
static tspec_t contypes[2][3] = {
{ INT, LONG, QUAD },
@ -509,7 +510,7 @@ icon(base)
warning(252);
/*
* If the value is to big for the current type, we must choose
* If the value is to big for the current type, we must choose
* another type.
*/
ansiu = 0;
@ -555,21 +556,45 @@ icon(base)
}
break;
/* LINTED (enumeration values not handled in switch) */
case STRUCT:
case VOID:
case LDOUBLE:
case FUNC:
case ARRAY:
case PTR:
case ENUM:
case UNION:
case SIGNED:
case NOTSPEC:
case DOUBLE:
case FLOAT:
case UQUAD:
case ULONG:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
break;
case NTSPEC: /* this value unused */
break;
}
if (typ != QUAD && typ != UQUAD) {
if (isutyp(typ)) {
uq = ul;
} else {
uq = (quad_t)(long)ul;
uq = (int64_t)(long)ul;
}
}
uq = (u_quad_t)xsign((quad_t)uq, typ, -1);
uq = (uint64_t)xsign((int64_t)uq, typ, -1);
(yylval.y_val = xcalloc(1, sizeof (val_t)))->v_tspec = typ;
yylval.y_val->v_ansiu = ansiu;
yylval.y_val->v_quad = (quad_t)uq;
yylval.y_val->v_quad = (int64_t)uq;
return (T_CON);
}
@ -581,22 +606,18 @@ icon(base)
* to the width of type t.
*/
int
sign(q, t, len)
quad_t q;
tspec_t t;
int len;
sign(int64_t q, tspec_t t, int len)
{
if (t == PTR || isutyp(t))
return (0);
return (msb(q, t, len));
}
int
msb(q, t, len)
quad_t q;
tspec_t t;
int len;
msb(int64_t q, tspec_t t, int len)
{
if (len <= 0)
len = size(t);
return ((q & qbmasks[len - 1]) != 0);
@ -605,12 +626,10 @@ msb(q, t, len)
/*
* Extends the sign of q.
*/
quad_t
xsign(q, t, len)
quad_t q;
tspec_t t;
int len;
int64_t
xsign(int64_t q, tspec_t t, int len)
{
if (len <= 0)
len = size(t);
@ -627,17 +646,17 @@ xsign(q, t, len)
* representation. Type and value are returned in yylval. fcon()
* (and yylex()) returns T_CON.
* XXX Currently it is not possible to convert constants of type
* long double which are greater then DBL_MAX.
* long double which are greater than DBL_MAX.
*/
static int
fcon()
fcon(void)
{
const char *cp;
int len;
tspec_t typ;
char c, *eptr;
double d;
float f;
float f = 0;
cp = yytext;
len = yyleng;
@ -667,7 +686,7 @@ fcon()
if (typ == FLOAT) {
f = (float)d;
if (isinf(f)) {
if (!finite(f)) {
/* floating-point constant out of range */
warning(248);
f = f > 0 ? FLT_MAX : -FLT_MAX;
@ -685,10 +704,9 @@ fcon()
}
static int
operator(t, o)
int t;
op_t o;
operator(int t, op_t o)
{
yylval.y_op = o;
return (t);
}
@ -697,7 +715,7 @@ operator(t, o)
* Called if lex found a leading \'.
*/
static int
ccon()
ccon(void)
{
int n, val, c;
char cv;
@ -727,7 +745,7 @@ ccon()
cv = (char)val;
val = cv;
}
yylval.y_val = xcalloc(1, sizeof (val_t));
yylval.y_val->v_tspec = INT;
yylval.y_val->v_quad = val;
@ -739,7 +757,7 @@ ccon()
* Called if lex found a leading L\'
*/
static int
wccon()
wccon(void)
{
static char buf[MB_LEN_MAX + 1];
int i, c;
@ -789,11 +807,10 @@ wccon()
* string.
*
* Returns -1 if the end of the character constant or string is reached,
* -2 if the EOF is reached, and the charachter otherwise.
* -2 if the EOF is reached, and the character otherwise.
*/
static int
getescc(d)
int d;
getescc(int d)
{
static int pbc = -1;
int n, c, v;
@ -808,9 +825,12 @@ getescc(d)
return (-1);
switch (c) {
case '\n':
/* newline in string or char constant */
error(254);
return (-2);
if (tflag) {
/* newline in string or char constant */
error(254);
return (-2);
}
return (c);
case EOF:
return (-2);
case '\\':
@ -833,11 +853,7 @@ getescc(d)
if (tflag)
/* \a undefined in traditional C */
warning(81);
#ifdef __STDC__
return ('\a');
#else
return ('\007');
#endif
case 'b':
return ('\b');
case 'f':
@ -852,11 +868,7 @@ getescc(d)
if (tflag)
/* \v undefined in traditional C */
warning(264);
#ifdef __STDC__
return ('\v');
#else
return ('\013');
#endif
case '8': case '9':
/* bad octal digit %c */
warning(77, c);
@ -930,7 +942,7 @@ getescc(d)
* # lineno "filename"
*/
static void
directive()
directive(void)
{
const char *cp, *fn;
char c, *eptr;
@ -939,9 +951,10 @@ directive()
static int first = 1;
/* Go to first non-whitespace after # */
for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) ;
for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++)
continue;
if (!isdigit(c)) {
if (!isdigit((unsigned char)c)) {
error:
/* undefined or invalid # directive */
warning(255);
@ -952,7 +965,8 @@ directive()
goto error;
if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0')
goto error;
while ((c = *cp++) == ' ' || c == '\t') ;
while ((c = *cp++) == ' ' || c == '\t')
continue;
if (c != '\0') {
if (c != '"')
goto error;
@ -963,11 +977,18 @@ directive()
goto error;
if ((fnl = cp++ - fn) > PATH_MAX)
goto error;
while ((c = *cp++) == ' ' || c == '\t') ;
while ((c = *cp++) == ' ' || c == '\t')
continue;
#if 0
if (c != '\0')
warning("extra character(s) after directive");
#endif
/* empty string means stdin */
if (fnl == 0) {
fn = "{standard input}";
fnl = 16; /* strlen (fn) */
}
curr_pos.p_file = fnnalloc(fn, fnl);
/*
* If this is the first directive, the name is the name
@ -981,13 +1002,17 @@ directive()
}
}
curr_pos.p_line = (int)ln - 1;
if (curr_pos.p_file == csrc_pos.p_file)
curr_pos.p_uniq = 0;
if (curr_pos.p_file == csrc_pos.p_file) {
csrc_pos.p_line = (int)ln - 1;
csrc_pos.p_uniq = 0;
}
}
/*
* Handle lint comments. Following comments are currently understood:
* ARGSUSEDn
* BITFIELDTYPE
* CONSTCOND CONSTANTCOND CONSTANTCONDITION
* FALLTHRU FALLTHROUGH
* LINTLIBRARY
@ -1002,15 +1027,16 @@ directive()
* parsed and a function which handles this comment is called.
*/
static void
comment()
comment(void)
{
int c, lc;
static struct {
const char *keywd;
int arg;
void (*func) __P((int));
void (*func)(int);
} keywtab[] = {
{ "ARGSUSED", 1, argsused },
{ "BITFIELDTYPE", 0, bitfieldtype },
{ "CONSTCOND", 0, constcond },
{ "CONSTANTCOND", 0, constcond },
{ "CONSTANTCONDITION", 0, constcond },
@ -1034,7 +1060,8 @@ comment()
eoc = 0;
/* Skip white spaces after the start of the comment */
while ((c = inpc()) != EOF && isspace(c)) ;
while ((c = inpc()) != EOF && isspace(c))
continue;
/* Read the potential keyword to keywd */
l = 0;
@ -1099,6 +1126,22 @@ comment()
}
}
/*
* Handle // style comments
*/
static void
slashslashcomment(void)
{
int c;
if (sflag < 2 && !gflag)
/* // comments only supported in C99 */
(void)gnuism(312, tflag ? "traditional" : "ANSI");
while ((c = inpc()) != EOF && c != '\n')
continue;
}
/*
* Clear flags for lint comments LINTED, LONGLONG and CONSTCOND.
* clrwflgs() is called after function definitions and global and
@ -1107,8 +1150,9 @@ comment()
* (if, switch, for, while).
*/
void
clrwflgs()
clrwflgs(void)
{
nowarn = 0;
quadflg = 0;
ccflg = 0;
@ -1120,7 +1164,7 @@ clrwflgs()
* by the parser are responsible for freeing this buffer.
*/
static int
string()
string(void)
{
u_char *s;
int c;
@ -1151,7 +1195,7 @@ string()
}
static int
wcstrg()
wcstrg(void)
{
char *s;
int c, i, n, wi;
@ -1221,8 +1265,7 @@ wcstrg()
* XXX calls to getsym() should be delayed until decl1*() is called
*/
sym_t *
getsym(sb)
sbuf_t *sb;
getsym(sbuf_t *sb)
{
dinfo_t *di;
char *s;
@ -1270,7 +1313,7 @@ getsym(sb)
di = dcs;
}
STRUCT_ASSIGN(sym->s_dpos, curr_pos);
UNIQUE_CURR_POS(sym->s_dpos);
if ((sym->s_kind = symtyp) != FLAB)
sym->s_type = gettyp(INT);
@ -1293,9 +1336,9 @@ getsym(sb)
* back to the symbol table.
*/
void
rmsym(sym)
sym_t *sym;
rmsym(sym_t *sym)
{
if ((*sym->s_rlink = sym->s_link) != NULL)
sym->s_link->s_rlink = sym->s_rlink;
sym->s_blklev = -1;
@ -1307,8 +1350,7 @@ rmsym(sym)
* table.
*/
void
rmsyms(syms)
sym_t *syms;
rmsyms(sym_t *syms)
{
sym_t *sym;
@ -1326,9 +1368,7 @@ rmsyms(syms)
* Put a symbol into the symbol table
*/
void
inssym(bl, sym)
int bl;
sym_t *sym;
inssym(int bl, sym_t *sym)
{
int h;
@ -1348,7 +1388,7 @@ inssym(bl, sym)
* level 0.
*/
void
cleanup()
cleanup(void)
{
sym_t *sym, *nsym;
int i;
@ -1371,8 +1411,7 @@ cleanup()
* Create a new symbol with the name of an existing symbol.
*/
sym_t *
pushdown(sym)
sym_t *sym;
pushdown(sym_t *sym)
{
int h;
sym_t *nsym;
@ -1382,7 +1421,7 @@ pushdown(sym)
if (sym->s_blklev > blklev)
lerror("pushdown()");
nsym->s_name = sym->s_name;
STRUCT_ASSIGN(nsym->s_dpos, curr_pos);
UNIQUE_CURR_POS(nsym->s_dpos);
nsym->s_kind = sym->s_kind;
nsym->s_blklev = blklev;
@ -1402,9 +1441,7 @@ pushdown(sym)
* The type of information in yylval is described by tok.
*/
void
freeyyv(sp, tok)
void *sp;
int tok;
freeyyv(void *sp, int tok)
{
if (tok == T_NAME || tok == T_TYPENAME) {
sbuf_t *sb = *(sbuf_t **)sp;
@ -1422,5 +1459,5 @@ freeyyv(sp, tok)
lerror("fryylv() 1");
}
free(strg);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
# $NetBSD: Makefile,v 1.2 1995/07/03 21:24:39 cgd Exp $
# $NetBSD: Makefile,v 1.12 2002/01/18 20:39:32 thorpej Exp $
.PATH: ${.CURDIR}/../lint1
PROG= lint2
SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c
NOMAN=
CFLAGS+=-I${.CURDIR}/../lint1
LINTFLAGS=-abehrz
BINDIR= /usr/libexec
PROG= lint2
SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c \
inittyp.c
NOMAN= # defined
LINTFLAGS= -abehrz
WFORMAT=1 # hopeless
BINDIR= /usr/libexec
.ifndef HOSTPROG
.include <bsd.prog.mk>
.endif

View File

@ -1,6 +1,7 @@
/* $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $ */
/* $NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,138 +32,44 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $");
#endif
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include <stdlib.h>
#include "lint2.h"
/* various type information */
ttab_t ttab[NTSPEC];
static void chkund __P((hte_t *));
static void chkdnu __P((hte_t *));
static void chkdnud __P((hte_t *));
static void chkmd __P((hte_t *));
static void chkvtui __P((hte_t *, sym_t *, sym_t *));
static void chkvtdi __P((hte_t *, sym_t *, sym_t *));
static void chkfaui __P((hte_t *, sym_t *, sym_t *));
static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *,
fcall_t *, fcall_t *, type_t *, type_t *));
static void chkrvu __P((hte_t *, sym_t *));
static void chkadecl __P((hte_t *, sym_t *, sym_t *));
static void printflike __P((hte_t *,fcall_t *, int,
const char *, type_t **));
static void scanflike __P((hte_t *, fcall_t *, int,
const char *, type_t **));
static void badfmt __P((hte_t *, fcall_t *));
static void inconarg __P((hte_t *, fcall_t *, int));
static void tofewarg __P((hte_t *, fcall_t *));
static void tomanyarg __P((hte_t *, fcall_t *));
static int eqtype __P((type_t *, type_t *, int, int, int, int *));
static int eqargs __P((type_t *, type_t *, int *));
static int mnoarg __P((type_t *, int *));
void
inittyp()
{
int i;
static struct {
tspec_t it_tspec;
ttab_t it_ttab;
} ittab[] = {
{ SIGNED, { 0, 0,
SIGNED, UNSIGN,
0, 0, 0, 0, 0, "signed" } },
{ UNSIGN, { 0, 0,
SIGNED, UNSIGN,
0, 0, 0, 0, 0, "unsigned" } },
{ CHAR, { CHAR_BIT, CHAR_BIT,
SCHAR, UCHAR,
1, 0, 0, 1, 1, "char" } },
{ SCHAR, { CHAR_BIT, CHAR_BIT,
SCHAR, UCHAR,
1, 0, 0, 1, 1, "signed char" } },
{ UCHAR, { CHAR_BIT, CHAR_BIT,
SCHAR, UCHAR,
1, 1, 0, 1, 1, "unsigned char" } },
{ SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT,
SHORT, USHORT,
1, 0, 0, 1, 1, "short" } },
{ USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT,
SHORT, USHORT,
1, 1, 0, 1, 1, "unsigned short" } },
{ INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
INT, UINT,
1, 0, 0, 1, 1, "int" } },
{ UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT,
INT, UINT,
1, 1, 0, 1, 1, "unsigned int" } },
{ LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT,
LONG, ULONG,
1, 0, 0, 1, 1, "long" } },
{ ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT,
LONG, ULONG,
1, 1, 0, 1, 1, "unsigned long" } },
{ QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT,
QUAD, UQUAD,
1, 0, 0, 1, 1, "long long" } },
{ UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT,
QUAD, UQUAD,
1, 1, 0, 1, 1, "unsigned long long" } },
{ FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT,
FLOAT, FLOAT,
0, 0, 1, 1, 1, "float" } },
{ DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT,
DOUBLE, DOUBLE,
0, 0, 1, 1, 1, "double" } },
{ LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT,
LDOUBLE, LDOUBLE,
0, 0, 1, 1, 1, "long double" } },
{ VOID, { -1, -1,
VOID, VOID,
0, 0, 0, 0, 0, "void" } },
{ STRUCT, { -1, -1,
STRUCT, STRUCT,
0, 0, 0, 0, 0, "struct" } },
{ UNION, { -1, -1,
UNION, UNION,
0, 0, 0, 0, 0, "union" } },
{ ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
ENUM, ENUM,
1, 0, 0, 1, 1, "enum" } },
{ PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT,
PTR, PTR,
0, 1, 0, 0, 1, "pointer" } },
{ ARRAY, { -1, -1,
ARRAY, ARRAY,
0, 0, 0, 0, 0, "array" } },
{ FUNC, { -1, -1,
FUNC, FUNC,
0, 0, 0, 0, 0, "function" } },
};
for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
if (!pflag) {
for (i = 0; i < NTSPEC; i++)
ttab[i].tt_psz = ttab[i].tt_sz;
}
}
static void chkund(hte_t *);
static void chkdnu(hte_t *);
static void chkdnud(hte_t *);
static void chkmd(hte_t *);
static void chkvtui(hte_t *, sym_t *, sym_t *);
static void chkvtdi(hte_t *, sym_t *, sym_t *);
static void chkfaui(hte_t *, sym_t *, sym_t *);
static void chkau(hte_t *, int, sym_t *, sym_t *, pos_t *,
fcall_t *, fcall_t *, type_t *, type_t *);
static void chkrvu(hte_t *, sym_t *);
static void chkadecl(hte_t *, sym_t *, sym_t *);
static void printflike(hte_t *,fcall_t *, int, const char *, type_t **);
static void scanflike(hte_t *, fcall_t *, int, const char *, type_t **);
static void badfmt(hte_t *, fcall_t *);
static void inconarg(hte_t *, fcall_t *, int);
static void tofewarg(hte_t *, fcall_t *);
static void tomanyarg(hte_t *, fcall_t *);
static int eqtype(type_t *, type_t *, int, int, int, int *);
static int eqargs(type_t *, type_t *, int *);
static int mnoarg(type_t *, int *);
/*
* If there is a symbol named "main", mark it as used.
*/
void
mainused()
mainused(void)
{
hte_t *hte;
@ -174,8 +81,7 @@ mainused()
* Performs all tests for a single name
*/
void
chkname(hte)
hte_t *hte;
chkname(hte_t *hte)
{
sym_t *sym, *def, *pdecl, *decl;
@ -220,8 +126,7 @@ chkname(hte)
* Print a warning if the name has been used, but not defined.
*/
static void
chkund(hte)
hte_t *hte;
chkund(hte_t *hte)
{
fcall_t *fcall;
usym_t *usym;
@ -242,8 +147,7 @@ chkund(hte)
* Print a warning if the name has been defined, but never used.
*/
static void
chkdnu(hte)
hte_t *hte;
chkdnu(hte_t *hte)
{
sym_t *sym;
@ -260,33 +164,33 @@ chkdnu(hte)
}
/*
* Print a warning if the name has been declared, but is not used
* Print a warning if the variable has been declared, but is not used
* or defined.
*/
static void
chkdnud(hte)
hte_t *hte;
chkdnud(hte_t *hte)
{
sym_t *sym;
if (hte->h_syms == NULL || hte->h_used || hte->h_def)
return;
if ((sym = hte->h_syms) != NULL) {
if (sym->s_def != DECL)
errx(1, "internal error: chkdnud() 1");
/* %s declared( %s ), but never used or defined */
msg(2, hte->h_name, mkpos(&sym->s_pos));
}
sym = hte->h_syms;
if (TP(sym->s_type)->t_tspec == FUNC)
return;
if (sym->s_def != DECL)
errx(1, "internal error: chkdnud() 1");
/* %s declared( %s ), but never used or defined */
msg(2, hte->h_name, mkpos(&sym->s_pos));
}
/*
* Print a warning if there is more then one definition for
* Print a warning if there is more than one definition for
* this name.
*/
static void
chkmd(hte)
hte_t *hte;
chkmd(hte_t *hte)
{
sym_t *sym, *def1;
char *pos1;
@ -323,9 +227,7 @@ chkmd(hte)
* call as it's done for function arguments.
*/
static void
chkvtui(hte, def, decl)
hte_t *hte;
sym_t *def, *decl;
chkvtui(hte_t *hte, sym_t *def, sym_t *decl)
{
fcall_t *call;
char *pos1;
@ -386,9 +288,7 @@ chkvtui(hte, def, decl)
* types of return values are tested.
*/
static void
chkvtdi(hte, def, decl)
hte_t *hte;
sym_t *def, *decl;
chkvtdi(hte_t *hte, sym_t *def, sym_t *decl)
{
sym_t *sym;
type_t *tp1, *tp2;
@ -427,12 +327,10 @@ chkvtdi(hte, def, decl)
* of the same function.
*/
static void
chkfaui(hte, def, decl)
hte_t *hte;
sym_t *def, *decl;
chkfaui(hte_t *hte, sym_t *def, sym_t *decl)
{
type_t *tp1, *tp2, **ap1, **ap2;
pos_t *pos1p;
pos_t *pos1p = NULL;
fcall_t *calls, *call, *call1;
int n, as;
char *pos1;
@ -442,7 +340,7 @@ chkfaui(hte, def, decl)
return;
/*
* If we find a function definition, we use this for comparision,
* If we find a function definition, we use this for comparison,
* otherwise the first prototype we can find. If there is no
* definition or prototype declaration, the first function call
* is used.
@ -537,13 +435,8 @@ chkfaui(hte, def, decl)
*
*/
static void
chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
hte_t *hte;
int n;
sym_t *def, *decl;
pos_t *pos1p;
fcall_t *call1, *call;
type_t *arg1, *arg2;
chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
fcall_t *call1, fcall_t *call, type_t *arg1, type_t *arg2)
{
/* LINTED (automatic hides external declaration: warn) */
int promote, asgn, warn;
@ -577,7 +470,7 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
/*
* Other lint implementations print warnings as soon as the type
* of an argument does not match exactly the expected type. The
* result are lots of warnings which are really not neccessary.
* result are lots of warnings which are really not necessary.
* We print a warning only if
* (0) at least one type is not an interger type and types differ
* (1) hflag is set and types differ
@ -670,11 +563,16 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
}
}
} else if (t1 == PTR && isityp(t2) && psize(t1) == psize(t2)) {
} else if (t1 == PTR && isityp(t2)) {
for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
if (ai->a_num == n)
break;
}
/*
* Vendor implementations of lint (e.g. HP-UX, Digital UNIX)
* don't care about the size of the integer argument,
* only whether or not it is zero. We do the same.
*/
if (ai != NULL && ai->a_zero)
return;
}
@ -690,17 +588,12 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
* string fmt.
*/
static void
printflike(hte, call, n, fmt, ap)
hte_t *hte;
fcall_t *call;
int n;
const char *fmt;
type_t **ap;
printflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int fwidth, prec, left, sign, space, alt, zero;
tspec_t sz, t1, t2;
tspec_t sz, t1, t2 = NOTSPEC;
type_t *tp;
fp = fmt;
@ -920,18 +813,13 @@ printflike(hte, call, n, fmt, ap)
* string fmt.
*/
static void
scanflike(hte, call, n, fmt, ap)
hte_t *hte;
fcall_t *call;
int n;
const char *fmt;
type_t **ap;
scanflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int noasgn, fwidth;
tspec_t sz, t1, t2;
type_t *tp;
tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC;
type_t *tp = NULL;
fp = fmt;
fc = *fp++;
@ -955,7 +843,7 @@ scanflike(hte, call, n, fmt, ap)
noasgn = 1;
fc = *fp++;
}
if (isdigit(fc)) {
fwidth = 1;
do { fc = *fp++; } while (isdigit(fc));
@ -1116,38 +1004,33 @@ scanflike(hte, call, n, fmt, ap)
}
static void
badfmt(hte, call)
hte_t *hte;
fcall_t *call;
badfmt(hte_t *hte, fcall_t *call)
{
/* %s: malformed format string\t%s */
msg(13, hte->h_name, mkpos(&call->f_pos));
}
static void
inconarg(hte, call, n)
hte_t *hte;
fcall_t *call;
int n;
inconarg(hte_t *hte, fcall_t *call, int n)
{
/* %s, arg %d inconsistent with format\t%s(%d) */
msg(14, hte->h_name, n, mkpos(&call->f_pos));
}
static void
tofewarg(hte, call)
hte_t *hte;
fcall_t *call;
tofewarg(hte_t *hte, fcall_t *call)
{
/* %s: too few args for format \t%s */
msg(15, hte->h_name, mkpos(&call->f_pos));
}
static void
tomanyarg(hte, call)
hte_t *hte;
fcall_t *call;
tomanyarg(hte_t *hte, fcall_t *call)
{
/* %s: too many args for format \t%s */
msg(16, hte->h_name, mkpos(&call->f_pos));
}
@ -1158,9 +1041,7 @@ tomanyarg(hte, call)
* or return values which are always or sometimes ignored.
*/
static void
chkrvu(hte, def)
hte_t *hte;
sym_t *def;
chkrvu(hte_t *hte, sym_t *def)
{
fcall_t *call;
int used, ignored;
@ -1176,7 +1057,7 @@ chkrvu(hte, def)
/* function has return value */
used = ignored = 0;
for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
used |= call->f_rused;
used |= call->f_rused || call->f_rdisc;
ignored |= !call->f_rused && !call->f_rdisc;
}
/*
@ -1208,9 +1089,7 @@ chkrvu(hte, def)
* Print warnings for inconsistent argument declarations.
*/
static void
chkadecl(hte, def, decl)
hte_t *hte;
sym_t *def, *decl;
chkadecl(hte_t *hte, sym_t *def, sym_t *decl)
{
/* LINTED (automatic hides external declaration: warn) */
int osdef, eq, warn, n;
@ -1280,8 +1159,8 @@ chkadecl(hte, def, decl)
*
* ignqual if set, ignore qualifiers of outhermost type; used for
* function arguments
* promote if set, promote left type before comparision; used for
* comparisions of arguments with parameters of old style
* promote if set, promote left type before comparison; used for
* comparisons of arguments with parameters of old style
* definitions
* asgn left indirected type must have at least the same qualifiers
* like right indirected type (for assignments and function
@ -1290,9 +1169,7 @@ chkadecl(hte, def, decl)
* an incompatible prototype declaration
*/
static int
eqtype(tp1, tp2, ignqual, promot, asgn, warn)
type_t *tp1, *tp2;
int ignqual, promot, asgn, *warn;
eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *warn)
{
tspec_t t, to;
int indir;
@ -1322,7 +1199,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
return (1);
}
if (t != tp2->t_tspec) {
/*
* Give pointer to types which differ only in
@ -1339,6 +1216,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
} else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
return (tp1->t_uniqpos.p_line ==
tp2->t_uniqpos.p_line &&
tp1->t_uniqpos.p_file ==
tp2->t_uniqpos.p_file &&
tp1->t_uniqpos.p_uniq ==
tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@ -1366,6 +1250,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
} else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
return (tp1->t_uniqpos.p_line ==
tp2->t_uniqpos.p_line &&
tp1->t_uniqpos.p_file ==
tp2->t_uniqpos.p_file &&
tp1->t_uniqpos.p_uniq ==
tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@ -1404,9 +1295,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
* Compares arguments of two prototypes
*/
static int
eqargs(tp1, tp2, warn)
type_t *tp1, *tp2;
int *warn;
eqargs(type_t *tp1, type_t *tp2, int *warn)
{
type_t **a1, **a2;
@ -1440,9 +1329,7 @@ eqargs(tp1, tp2, warn)
* is applied on it
*/
static int
mnoarg(tp, warn)
type_t *tp;
int *warn;
mnoarg(type_t *tp, int *warn)
{
type_t **arg;
tspec_t t;
@ -1459,4 +1346,3 @@ mnoarg(tp, warn)
}
return (1);
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $ */
/* $NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,24 +32,23 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $");
#endif
#include <err.h>
#include "lint2.h"
static void outtype __P((type_t *));
static void outdef __P((hte_t *, sym_t *));
static void dumpname __P((hte_t *));
static void outtype(type_t *);
static void outdef(hte_t *, sym_t *);
static void dumpname(hte_t *);
static void outfiles(void);
/*
* Write type into the output buffer.
*/
static void
outtype(tp)
type_t *tp;
outtype(type_t *tp)
{
int t, s, na;
tspec_t ts;
@ -105,9 +105,15 @@ outtype(tp)
} else if (tp->t_istynam) {
outint(2);
outname(tp->t_tynam->h_name);
} else {
outint(0);
}
} else if (tp->t_isuniqpos) {
outint(3);
outint(tp->t_uniqpos.p_line);
outchar('.');
outint(tp->t_uniqpos.p_file);
outchar('.');
outint(tp->t_uniqpos.p_uniq);
} else
errx(1, "internal error: outtype() 2");
} else if (ts == FUNC && tp->t_args != NULL) {
na = 0;
for (ap = tp->t_args; *ap != NULL; ap++)
@ -128,10 +134,9 @@ outtype(tp)
* Write a definition.
*/
static void
outdef(hte, sym)
hte_t *hte;
sym_t *sym;
outdef(hte_t *hte, sym_t *sym)
{
/* reset output buffer */
outclr();
@ -180,8 +185,7 @@ outdef(hte, sym)
* Write the first definition of a name into the lint library.
*/
static void
dumpname(hte)
hte_t *hte;
dumpname(hte_t *hte)
{
sym_t *sym, *def;
@ -191,7 +195,7 @@ dumpname(hte)
/*
* If there is a definition, write it. Otherwise write a tentative
* definition. This is neccessary because more than one tentative
* definition. This is necessary because more than one tentative
* definition is allowed (except with sflag).
*/
def = NULL;
@ -213,8 +217,7 @@ dumpname(hte)
* Write a new lint library.
*/
void
outlib(name)
const char *name;
outlib(const char *name)
{
/* Open of output file and initialisation of the output buffer */
outopen(name);
@ -228,9 +231,67 @@ outlib(name)
outchar('s');
outstrg(name);
/*
* print the names of all files references by unnamed
* struct/union/enum declarations.
*/
outfiles();
/* write all definitions with external linkage */
forall(dumpname);
/* close the output */
outclose();
}
/*
* Write out the name of a file referenced by a type.
*/
struct outflist {
short ofl_num;
struct outflist *ofl_next;
};
static struct outflist *outflist;
int
addoutfile(short num)
{
struct outflist *ofl, **pofl;
int i;
ofl = outflist;
pofl = &outflist;
i = 1; /* library is 0 */
while (ofl != NULL) {
if (ofl->ofl_num == num)
break;
pofl = &ofl->ofl_next;
ofl = ofl->ofl_next;
i++;
}
if (ofl == NULL) {
ofl = *pofl = xmalloc(sizeof (struct outflist));
ofl->ofl_num = num;
ofl->ofl_next = NULL;
}
return (i);
}
static void
outfiles(void)
{
struct outflist *ofl;
int i;
for (ofl = outflist, i = 1; ofl != NULL; ofl = ofl->ofl_next, i++) {
/* reset output buffer */
outclr();
outint(i);
outchar('s');
outstrg(fnames[ofl->ofl_num]);
}
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: externs2.h,v 1.2 1995/07/03 21:24:46 cgd Exp $ */
/* $NetBSD: externs2.h,v 1.7 2001/05/28 12:40:38 lukem Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -38,7 +39,6 @@ extern int xflag;
extern int uflag;
extern int Cflag;
extern const char *libname;
extern int pflag;
extern int sflag;
extern int tflag;
extern int Hflag;
@ -49,9 +49,14 @@ extern int Fflag;
/*
* hash.c
*/
extern void inithash __P((void));
extern hte_t *hsearch __P((const char *, int));
extern void forall __P((void (*)(hte_t *)));
extern void _inithash(hte_t ***);
extern hte_t *_hsearch(hte_t **, const char *, int);
extern void _forall(hte_t **, void (*)(hte_t *));
extern void _destroyhash(hte_t **);
#define inithash() _inithash(NULL);
#define hsearch(a, b) _hsearch(NULL, (a), (b))
#define forall(a) _forall(NULL, (a))
/*
* read.c
@ -59,29 +64,30 @@ extern void forall __P((void (*)(hte_t *)));
extern const char **fnames;
extern type_t **tlst;
extern void readfile __P((const char *));
extern void mkstatic __P((hte_t *));
extern void readfile(const char *);
extern void mkstatic(hte_t *);
/*
* mem2.c
*/
extern void initmem __P((void));
extern void *xalloc __P((size_t));
extern void initmem(void);
extern void *xalloc(size_t);
/*
* chk.c
*/
extern void inittyp __P((void));
extern void mainused __P((void));
extern void chkname __P((hte_t *));
extern void inittyp(void);
extern void mainused(void);
extern void chkname(hte_t *);
/*
* msg.c
*/
extern void msg __P((int, ...));
extern const char *mkpos __P((pos_t *));
extern void msg(int, ...);
extern const char *mkpos(pos_t *);
/*
* emit2.c
*/
extern void outlib __P((const char *));
extern void outlib(const char *);
extern int addoutfile(short);

View File

@ -1,4 +1,4 @@
/* $NetBSD: hash.c,v 1.2 1995/07/03 21:24:47 cgd Exp $ */
/* $NetBSD: hash.c,v 1.7 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,36 +31,45 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: hash.c,v 1.2 1995/07/03 21:24:47 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: hash.c,v 1.7 2002/01/21 19:49:52 tv Exp $");
#endif
#include <stddef.h>
#include <string.h>
/*
* XXX Really need a generalized hash table package
*/
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "lint2.h"
/* pointer to hash table, initialized in inithash() */
static hte_t **htab;
static int hash __P((const char *));
static int hash(const char *);
/*
* Initialize hash table.
*/
void
inithash()
_inithash(hte_t ***tablep)
{
htab = xcalloc(HSHSIZ2, sizeof (hte_t *));
if (tablep == NULL)
tablep = &htab;
*tablep = xcalloc(HSHSIZ2, sizeof (hte_t *));
}
/*
* Compute hash value from a string.
*/
static int
hash(s)
const char *s;
hash(const char *s)
{
u_int v;
const u_char *us;
@ -78,15 +87,16 @@ hash(s)
* given name exists and mknew is set, create a new one.
*/
hte_t *
hsearch(s, mknew)
const char *s;
int mknew;
_hsearch(hte_t **table, const char *s, int mknew)
{
int h;
hte_t *hte;
if (table == NULL)
table = htab;
h = hash(s);
for (hte = htab[h]; hte != NULL; hte = hte->h_link) {
for (hte = table[h]; hte != NULL; hte = hte->h_link) {
if (strcmp(hte->h_name, s) == 0)
break;
}
@ -95,13 +105,20 @@ hsearch(s, mknew)
return (hte);
/* create a new hte */
hte = xalloc(sizeof (hte_t));
hte = xmalloc(sizeof (hte_t));
hte->h_name = xstrdup(s);
hte->h_used = 0;
hte->h_def = 0;
hte->h_static = 0;
hte->h_syms = NULL;
hte->h_lsym = &hte->h_syms;
hte->h_calls = NULL;
hte->h_lcall = &hte->h_calls;
hte->h_usyms = NULL;
hte->h_lusym = &hte->h_usyms;
hte->h_link = htab[h];
htab[h] = hte;
hte->h_link = table[h];
hte->h_hte = NULL;
table[h] = hte;
return (hte);
}
@ -110,14 +127,38 @@ hsearch(s, mknew)
* Call function f for each name in the hash table.
*/
void
forall(f)
void (*f) __P((hte_t *));
_forall(hte_t **table, void (*f)(hte_t *))
{
int i;
hte_t *hte;
if (table == NULL)
table = htab;
for (i = 0; i < HSHSIZ2; i++) {
for (hte = htab[i]; hte != NULL; hte = hte->h_link)
for (hte = table[i]; hte != NULL; hte = hte->h_link)
(*f)(hte);
}
}
/*
* Free all contents of the hash table that this module allocated.
*/
void
_destroyhash(hte_t **table)
{
int i;
hte_t *hte, *nexthte;
if (table == NULL)
err(1, "_destroyhash called on main hash table");
for (i = 0; i < HSHSIZ2; i++) {
for (hte = table[i]; hte != NULL; hte = nexthte) {
free((void *)hte->h_name);
nexthte = hte->h_link;
free(hte);
}
}
free(table);
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: lint2.h,v 1.2 1995/07/03 21:24:49 cgd Exp $ */
/* $NetBSD: lint2.h,v 1.5 2000/06/14 06:49:23 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -45,6 +46,7 @@ typedef struct type {
u_int t_proto : 1; /* this is a prototype */
u_int t_istag : 1; /* tag with _t_tag valid */
u_int t_istynam : 1; /* tag with _t_tynam valid */
u_int t_isuniqpos : 1; /* tag with _t_uniqpos valid */
union {
int _t_dim; /* if the type is an ARRAY than this
is the dimension of the array. */
@ -52,6 +54,13 @@ typedef struct type {
t_isenum, STRUCT or UNION */
struct hte *_t_tynam; /* hash table entry of typename if
t_isenum, STRUCT or UNION */
struct {
int p_line;
short p_file;
int p_uniq;
} _t_uniqpos; /* unique position, for untagged
untyped STRUCTs, UNIONS, and ENUMs,
if t_isuniqpos */
struct type **_t_args; /* list of argument types if this
is a prototype */
} t_u;
@ -59,10 +68,11 @@ typedef struct type {
type, type of return value) */
} type_t;
#define t_dim t_u._t_dim
#define t_tag t_u._t_tag
#define t_tynam t_u._t_tynam
#define t_args t_u._t_args
#define t_dim t_u._t_dim
#define t_tag t_u._t_tag
#define t_tynam t_u._t_tynam
#define t_uniqpos t_u._t_uniqpos
#define t_args t_u._t_args
/*
* argument information
@ -90,7 +100,7 @@ typedef struct {
u_short p_line; /* line number in p_src */
u_short p_isrc; /* index of (included) file */
u_short p_iline; /* line number in p_iline */
} pos_t;
} pos_t;
/*
* Used for definitions and declarations
@ -107,7 +117,7 @@ typedef struct sym {
u_int s_def : 3; /* DECL, TDEF or DEF */
#else
def_t s_def;
#endif
#endif
u_int s_rval : 1; /* function has return value */
u_int s_osdef : 1; /* old style function definition */
u_int s_static : 1; /* symbol is static */
@ -169,6 +179,7 @@ typedef struct hte {
usym_t *h_usyms; /* usage info */
usym_t **h_lusym; /* points to u_nxt of last usage info */
struct hte *h_link; /* next hte with same hash function */
struct hte *h_hte; /* pointer to other htes (for renames */
} hte_t;
/* maps type indices into pointers to type structs */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $ */
/* $NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz Exp $");
#endif
#include <stdio.h>
@ -58,7 +59,7 @@ const char *libname;
int pflag;
/*
* warnings for (tentative) definitions of the same name in more then
* warnings for (tentative) definitions of the same name in more than
* one translation unit
*/
int sflag;
@ -83,13 +84,12 @@ int Fflag;
*/
const char **libs;
static void usage __P((void));
static void usage(void);
int main(int, char *[]);
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int c, i;
size_t len;
@ -133,8 +133,9 @@ main(argc, argv)
Fflag = 1;
break;
case 'l':
for (i = 0; libs[i] != NULL; i++) ;
libs = xrealloc(libs, (i + 2) * sizeof (char *));
for (i = 0; libs[i] != NULL; i++)
continue;
libs = xrealloc(libs, (i + 2) * sizeof (char *));
libs[i] = xstrdup(optarg);
libs[i + 1] = NULL;
break;
@ -142,7 +143,7 @@ main(argc, argv)
usage();
}
}
argc -= optind;
argv += optind;
@ -181,10 +182,9 @@ main(argc, argv)
}
static void
usage()
usage(void)
{
(void)fprintf(stderr,
"usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $ */
/* $NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
#endif
#include <sys/param.h>
@ -40,7 +41,6 @@ static char rcsid[] = "$NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $";
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include "lint2.h"
@ -54,7 +54,7 @@ static size_t nxtfree;
static void *mbuf;
void
initmem()
initmem(void)
{
int pgsz;
@ -70,13 +70,13 @@ initmem()
* need never to be freed.
*/
void *
xalloc(sz)
size_t sz;
xalloc(size_t sz)
{
void *ptr;
int prot, flags;
sz = ALIGN(sz);
/* Align to at least 8 bytes. */
sz = (sz + 7) & ~7L;
if (nxtfree + sz > mblklen) {
/* use mmap() instead of malloc() to avoid malloc overhead. */
prot = PROT_READ | PROT_WRITE;
@ -84,8 +84,6 @@ xalloc(sz)
mbuf = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
if (mbuf == (void *)-1)
err(1, "can't map memory");
if (ALIGN((u_long)mbuf) != (u_long)mbuf)
errx(1, "mapped address is not aligned");
(void)memset(mbuf, 0, mblklen);
nxtfree = 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd Exp $ */
/* $NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,22 +31,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
#endif
#include <string.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <string.h>
#include "lint2.h"
static const char *msgs[] = {
"%s used( %s ), but not defined", /* 0 */
"%s defined( %s ), but never used", /* 1 */
@ -66,29 +61,17 @@ static const char *msgs[] = {
"%s: too few args for format \t%s", /* 15 */
"%s: too many args for format \t%s", /* 16 */
"%s function value must be declared before use \t%s :: %s",/* 17 */
"%s renamed multiple times \t%s :: %s", /* 18 */
};
static const char *basename __P((const char *));
static const char *lbasename(const char *);
#ifdef __STDC__
void
msg(int n, ...)
{
#else
void
msg(va_alist)
va_dcl
int n;
{
#endif
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
n = va_arg(ap, int);
#endif
(void)vprintf(msgs[n], ap);
(void)printf("\n");
@ -100,8 +83,7 @@ msg(va_alist)
* Return a pointer to the last component of a path.
*/
static const char *
basename(path)
const char *path;
lbasename(const char *path)
{
const char *cp, *cp1, *cp2;
@ -122,8 +104,7 @@ basename(path)
* Create a string which describes a position in a source file.
*/
const char *
mkpos(posp)
pos_t *posp;
mkpos(pos_t *posp)
{
size_t len;
const char *fn;
@ -140,7 +121,7 @@ mkpos(posp)
}
qm = !Hflag && posp->p_src != posp->p_isrc;
len = strlen(fn = basename(fnames[src]));
len = strlen(fn = lbasename(fnames[src]));
len += 3 * sizeof (u_short) + 4;
if (len > blen)
@ -154,4 +135,3 @@ mkpos(posp)
return (buf);
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */
/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,16 +32,16 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $");
#endif
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include "lint2.h"
@ -78,33 +79,34 @@ static thtab_t **thtab; /* hash table */
type_t **tlst; /* array for indexed access */
static size_t tlstlen; /* length of tlst */
static hte_t **renametab;
/* index of current C source file (as spezified at the command line) */
static int csrcfile;
static void inperr __P((void));
static void setsrc __P((const char *));
static void setfnid __P((int, const char *));
static void funccall __P((pos_t *, const char *));
static void decldef __P((pos_t *, const char *));
static void usedsym __P((pos_t *, const char *));
static u_short inptype __P((const char *, const char **));
static int gettlen __P((const char *, const char **));
static u_short findtype __P((const char *, size_t, int));
static u_short storetyp __P((type_t *, const char *, size_t, int));
static int thash __P((const char *, size_t));
static char *inpqstrg __P((const char *, const char **));
static const char *inpname __P((const char *, const char **));
static int getfnidx __P((const char *));
static void inperr(void);
static void setsrc(const char *);
static void setfnid(int, const char *);
static void funccall(pos_t *, const char *);
static void decldef(pos_t *, const char *);
static void usedsym(pos_t *, const char *);
static u_short inptype(const char *, const char **);
static int gettlen(const char *, const char **);
static u_short findtype(const char *, size_t, int);
static u_short storetyp(type_t *, const char *, size_t, int);
static int thash(const char *, size_t);
static char *inpqstrg(const char *, const char **);
static const char *inpname(const char *, const char **);
static int getfnidx(const char *);
void
readfile(name)
const char *name;
readfile(const char *name)
{
FILE *inp;
size_t len;
const char *cp;
char *line, *eptr, rt;
char *line, *eptr, rt = '\0';
int cline, isrc, iline;
pos_t pos;
@ -117,6 +119,8 @@ readfile(name)
if (thtab == NULL)
thtab = xcalloc(THSHSIZ2, sizeof (thtab_t));
_inithash(&renametab);
srcfile = getfnidx(name);
if ((inp = fopen(name, "r")) == NULL)
@ -193,6 +197,8 @@ readfile(name)
}
_destroyhash(renametab);
if (ferror(inp))
err(1, "read error on %s", name);
@ -201,8 +207,9 @@ readfile(name)
static void
inperr()
inperr(void)
{
errx(1, "input file error: %s", fnames[srcfile]);
}
@ -211,23 +218,22 @@ inperr()
* currently read.
*/
static void
setsrc(cp)
const char *cp;
setsrc(const char *cp)
{
csrcfile = getfnidx(cp);
}
/*
* setfnid() gets as input an index as used in an input file and the
* associated file name. If neccessary, it creates a new lint2 file
* associated file name. If necessary, it creates a new lint2 file
* name index for this file name and creates the mapping of the index
* as used in the input file to the index used in lint2.
*/
static void
setfnid(fid, cp)
int fid;
const char *cp;
setfnid(int fid, const char *cp)
{
if (fid == -1)
inperr();
@ -249,15 +255,14 @@ setfnid(fid, cp)
* Process a function call record (c-record).
*/
static void
funccall(posp, cp)
pos_t *posp;
const char *cp;
funccall(pos_t *posp, const char *cp)
{
arginf_t *ai, **lai;
char c, *eptr;
int rused, rdisc;
hte_t *hte;
fcall_t *fcall;
const char *name;
fcall = xalloc(sizeof (fcall_t));
STRUCT_ASSIGN(fcall->f_pos, *posp);
@ -311,7 +316,14 @@ funccall(posp, cp)
fcall->f_rdisc = rdisc;
/* read name of function */
hte = hsearch(inpname(cp, &cp), 1);
name = inpname(cp, &cp);
/* first look it up in the renaming table, then in the normal table */
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
hte->h_used = 1;
fcall->f_type = inptype(cp, &cp);
@ -327,14 +339,13 @@ funccall(posp, cp)
* Process a declaration or definition (d-record).
*/
static void
decldef(posp, cp)
pos_t *posp;
const char *cp;
decldef(pos_t *posp, const char *cp)
{
sym_t *symp, sym;
char c, *ep;
int used;
hte_t *hte;
char c, *ep, *pos1;
int used, renamed;
hte_t *hte, *renamehte = NULL;
const char *name, *rename;
(void)memset(&sym, 0, sizeof (sym));
STRUCT_ASSIGN(sym.s_pos, *posp);
@ -412,8 +423,35 @@ decldef(posp, cp)
}
}
/* read symbol name */
hte = hsearch(inpname(cp, &cp), 1);
/* read symbol name, doing renaming if necessary */
name = inpname(cp, &cp);
renamed = 0;
if (*cp == 'r') {
cp++;
name = xstrdup(name);
rename = inpname(cp, &cp);
/* enter it and see if it's already been renamed */
renamehte = _hsearch(renametab, name, 1);
if (renamehte->h_hte == NULL) {
hte = hsearch(rename, 1);
renamehte->h_hte = hte;
renamed = 1;
} else if (strcmp((hte = renamehte->h_hte)->h_name, rename)) {
pos1 = xstrdup(mkpos(&renamehte->h_syms->s_pos));
/* %s renamed multiple times\t%s :: %s */
msg(18, name, pos1, mkpos(&sym.s_pos));
free(pos1);
}
free((char *)name);
} else {
/* it might be a previously-done rename */
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
}
hte->h_used |= used;
if (sym.s_def == DEF || sym.s_def == TDEF)
hte->h_def = 1;
@ -449,6 +487,10 @@ decldef(posp, cp)
}
*hte->h_lsym = symp;
hte->h_lsym = &symp->s_nxt;
/* XXX hack so we can remember where a symbol was renamed */
if (renamed)
renamehte->h_syms = symp;
}
if (*cp != '\0')
@ -459,12 +501,11 @@ decldef(posp, cp)
* Read an u-record (emited by lint1 if a symbol was used).
*/
static void
usedsym(posp, cp)
pos_t *posp;
const char *cp;
usedsym(pos_t *posp, const char *cp)
{
usym_t *usym;
hte_t *hte;
const char *name;
usym = xalloc(sizeof (usym_t));
STRUCT_ASSIGN(usym->u_pos, *posp);
@ -473,7 +514,12 @@ usedsym(posp, cp)
if (*cp++ != 'x')
inperr();
hte = hsearch(inpname(cp, &cp), 1);
name = inpname(cp, &cp);
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
hte->h_used = 1;
*hte->h_lusym = usym;
@ -484,13 +530,12 @@ usedsym(posp, cp)
* Read a type and return the index of this type.
*/
static u_short
inptype(cp, epp)
const char *cp, **epp;
inptype(const char *cp, const char **epp)
{
char c, s, *eptr;
const char *ep;
type_t *tp;
int narg, i, osdef;
int narg, i, osdef = 0;
size_t tlen;
u_short tidx;
int h;
@ -600,8 +645,6 @@ inptype(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
tp->t_istag = 1;
tp->t_tag = hsearch(inpname(cp, &cp), 1);
@ -610,9 +653,42 @@ inptype(cp, epp)
tp->t_istynam = 1;
tp->t_tynam = hsearch(inpname(cp, &cp), 1);
break;
case '3':
tp->t_isuniqpos = 1;
tp->t_uniqpos.p_line = strtol(cp, &eptr, 10);
cp = eptr;
cp++;
/* xlate to 'global' file name. */
tp->t_uniqpos.p_file =
addoutfile(inpfns[strtol(cp, &eptr, 10)]);
cp = eptr;
cp++;
tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10);
cp = eptr;
break;
}
break;
/* LINTED (enumeration value(s) not handled in switch) */
case LONG:
case VOID:
case LDOUBLE:
case DOUBLE:
case FLOAT:
case UQUAD:
case QUAD:
case ULONG:
case UINT:
case INT:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
case SIGNED:
case NOTSPEC:
break;
case NTSPEC:
abort();
}
*epp = cp;
@ -623,8 +699,7 @@ inptype(cp, epp)
* Get the length of a type string.
*/
static int
gettlen(cp, epp)
const char *cp, **epp;
gettlen(const char *cp, const char **epp)
{
const char *cp1;
char c, s, *eptr;
@ -769,19 +844,56 @@ gettlen(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
(void)inpname(cp, &cp);
break;
case '2':
(void)inpname(cp, &cp);
break;
case '3':
/* unique position: line.file.uniquifier */
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
break;
default:
inperr();
}
break;
/* LINTED (enumeration value(s) not handled in switch) */
case FLOAT:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
case SIGNED:
case NOTSPEC:
case INT:
case UINT:
case DOUBLE:
case LDOUBLE:
case VOID:
case ULONG:
case QUAD:
case UQUAD:
case LONG:
break;
case NTSPEC:
abort();
}
*epp = cp;
@ -792,10 +904,7 @@ gettlen(cp, epp)
* Search a type by it's type string.
*/
static u_short
findtype(cp, len, h)
const char *cp;
size_t len;
int h;
findtype(const char *cp, size_t len, int h)
{
thtab_t *thte;
@ -814,14 +923,9 @@ findtype(cp, len, h)
* if we read the same type string from the input file.
*/
static u_short
storetyp(tp, cp, len, h)
type_t *tp;
const char *cp;
size_t len;
int h;
storetyp(type_t *tp, const char *cp, size_t len, int h)
{
/* 0 ist reserved */
static u_int tidx = 1;
static u_int tidx = 1; /* 0 is reserved */
thtab_t *thte;
char *name;
@ -854,9 +958,7 @@ storetyp(tp, cp, len, h)
* Hash function for types
*/
static int
thash(s, len)
const char *s;
size_t len;
thash(const char *s, size_t len)
{
u_int v;
@ -872,8 +974,7 @@ thash(s, len)
* Read a string enclosed by "". This string may contain quoted chars.
*/
static char *
inpqstrg(src, epp)
const char *src, **epp;
inpqstrg(const char *src, const char **epp)
{
char *strg, *dst;
size_t slen;
@ -899,11 +1000,7 @@ inpqstrg(src, epp)
c = '\t';
break;
case 'v':
#ifdef __STDC__
c = '\v';
#else
c = '\013';
#endif
break;
case 'b':
c = '\b';
@ -915,11 +1012,7 @@ inpqstrg(src, epp)
c = '\f';
break;
case 'a':
#ifdef __STDC__
c = '\a';
#else
c = '\007';
#endif
break;
case '\\':
c = '\\';
@ -964,8 +1057,7 @@ inpqstrg(src, epp)
* Read the name of a symbol in static memory.
*/
static const char *
inpname(cp, epp)
const char *cp, **epp;
inpname(const char *cp, const char **epp)
{
static char *buf;
static size_t blen = 0;
@ -980,7 +1072,7 @@ inpname(cp, epp)
buf = xrealloc(buf, blen = len + 1);
for (i = 0; i < len; i++) {
c = *cp++;
if (!isalnum(c) && c != '_')
if (!isalnum((unsigned char)c) && c != '_')
inperr();
buf[i] = c;
}
@ -995,8 +1087,7 @@ inpname(cp, epp)
* a new entry and return the index of the newly created entry.
*/
static int
getfnidx(fn)
const char *fn;
getfnidx(const char *fn)
{
int i;
@ -1022,8 +1113,7 @@ getfnidx(fn)
* Separate symbols with static and external linkage.
*/
void
mkstatic(hte)
hte_t *hte;
mkstatic(hte_t *hte)
{
sym_t *sym1, **symp, *sym;
fcall_t **callp, *call;
@ -1067,16 +1157,22 @@ mkstatic(hte)
* XXX this entry should be put at the beginning of the list to
* avoid to process the same symbol twice.
*/
for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) ;
nhte->h_link = xalloc(sizeof (hte_t));
for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link)
continue;
nhte->h_link = xmalloc(sizeof (hte_t));
nhte = nhte->h_link;
nhte->h_name = hte->h_name;
nhte->h_static = 1;
nhte->h_used = 1;
nhte->h_def = 1; /* error in lint1 */
nhte->h_static = 1;
nhte->h_syms = NULL;
nhte->h_lsym = &nhte->h_syms;
nhte->h_calls = NULL;
nhte->h_lcall = &nhte->h_calls;
nhte->h_usyms = NULL;
nhte->h_lusym = &nhte->h_usyms;
nhte->h_link = NULL;
nhte->h_hte = NULL;
/*
* move all symbols used in this translation unit into the new

View File

@ -1,20 +1,22 @@
# $NetBSD: Makefile,v 1.2 1995/07/03 21:25:05 cgd Exp $
# $NetBSD: Makefile,v 1.7 2000/06/14 20:22:19 matt Exp $
.include <bsd.own.mk>
LIBS= llib-lposix.ln llib-lstdc.ln
all: ${LIBS}
.if ${MKLINT} != "no"
FILES= ${LIBS}
FILESDIR= ${LINTLIBDIR}
install:
install ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${NONBINMODE} \
${LIBS} ${DESTDIR}${LINTLIBDIR}
realall: ${LIBS}
.endif
clean cleanall:
rm -f ${LIBS}
CLEANFILES+= ${LIBS}
llib-lposix.ln: llib-lposix
lint -Cposix ${.ALLSRC}
${LINT} ${LINTFLAGS} -Cposix ${.ALLSRC}
llib-lstdc.ln: llib-lstdc
lint -Cstdc ${.ALLSRC}
${LINT} ${LINTFLAGS} -Cstdc ${.ALLSRC}
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: llib-lposix,v 1.2 1995/07/03 21:25:09 cgd Exp $ */
/* $NetBSD$ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl

View File

@ -1,4 +1,4 @@
/* $NetBSD: llib-lstdc,v 1.3 1995/07/03 21:39:28 cgd Exp $ */
/* $NetBSD: llib-lstdc,v 1.2 1995/07/03 21:25:11 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl

View File

@ -1,17 +1,14 @@
# $NetBSD: Makefile,v 1.2 1995/07/03 21:25:14 cgd Exp $
# $NetBSD: Makefile,v 1.11 2001/10/25 02:22:56 thorpej Exp $
.PATH: ${.CURDIR}/../lint1
.PATH: ${.CURDIR}/../lint1
PROG= xlint
SRCS= xlint.c mem.c
MAN= lint.1
PROG= xlint
SRCS= xlint.c mem.c
PROGNAME= lint
MAN= lint.1
CFLAGS+=-I${.CURDIR}/../lint1
CPPFLAGS+= -I${.CURDIR}/../lint1
realinstall:
install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${PROG} ${DESTDIR}${BINDIR}/lint
.include "${.CURDIR}/../../Makefile.inc"
.ifndef HOSTPROG
.include <bsd.prog.mk>
.endif

View File

@ -1,5 +1,6 @@
.\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $
.\" $NetBSD: lint.1,v 1.20 2001/12/08 19:27:56 wiz Exp $
.\"
.\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
.\" Copyright (c) 1994, 1995 Jochen Pohl
.\" All Rights Reserved.
.\"
@ -29,37 +30,81 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd August 28, 1994
.Dd May 24, 2001
.Dt LINT 1
.Os NetBSD
.Os
.Sh NAME
.Nm lint
.Nd a C program verifier.
.Nd a C program verifier
.Sh SYNOPSIS
.Nm lint
.Op Fl abceghprvxzHFV
.Op Fl s Ns | Ns Fl t
.Op Fl i Ns | Ns Fl nu
.Op Fl D Ns Ar name Ns Op =def
.Op Fl U Ns Ar name
.Op Fl I Ns Ar directory
.Op Fl L Ns Ar directory
.Op Fl l Ns Ar library
.Op Fl o Ns Ar outputfile
.Nm
.Op Fl abceghprvwxzHFV
.Bk -words
.Op Fl s | Fl t
.Ek
.Bk -words
.Op Fl i | Fl nu
.Ek
.Bk -words
.Op Fl D Ar name Ns Op =def
.Ek
.Bk -words
.Op Fl U Ar name
.Ek
.Bk -words
.Op Fl I Ar directory
.Ek
.Bk -words
.Op Fl d Ar directory
.Ek
.Bk -words
.Op Fl L Ar directory
.Ek
.Bk -words
.Op Fl l Ar library
.Ek
.Bk -words
.Op Fl o Ar outputfile
.Ek
.Bk -words
.Op Fl B Ar directory
.Ek
.Bk -words
.Op Fl X Ar id Ns Op ,id ...
.Ek
.Ar
.Nm lint
.Op Fl abceghprvzHFV
.Op Fl s Ns | Ns Fl t
.Fl C Ns Ar library
.Op Fl D Ns Ar name Ns Op =def
.Op Fl I Ns Ar directory
.Op Fl U Ns Ar name
.Op Fl abceghprvwzHFV
.Bk -words
.Op Fl s | Fl t
.Ek
.Bk -words
.Fl C Ar library
.Ek
.Bk -words
.Op Fl D Ar name Ns Op =def
.Ek
.Bk -words
.Op Fl U Ar name
.Ek
.Bk -words
.Op Fl I Ar directory
.Ek
.Bk -words
.Op Fl d Ar directory
.Ek
.Bk -words
.Op Fl B Ar directory
.Ek
.Bk -words
.Op Fl X Ar id Ns Op ,id ...
.Ek
.Ar
.Sh DESCRIPTION
.Nm
attempts to detect features of the named C program files
that are likely to be bugs, to be non-portable, or to be
wasteful. It also performs stricter type checking then does
wasteful. It also performs stricter type checking than does
the C compiler.
.Nm
runs the C preprocessor as its first phase, with the
@ -67,10 +112,10 @@ preprocessor symbol
.Sy lint
defined to allow certain questionable code to be altered
or skipped by
.Nm lint .
.Nm "" .
Therefore, this symbol should be thought of as a reserved
word for all code that is to be checked by
.Nm lint .
.Nm "" .
.Pp
Among the possible problems that are currently noted are
unreachable statements, loops not entered at the top,
@ -90,7 +135,7 @@ are taken to be C source files. Filename arguments with
names ending with
.Pa \&.ln
are taken to be the result of an earlier invocation of
.Nm lint ,
.Nm "" ,
with either the
.Fl i ,
.Fl o
@ -143,6 +188,22 @@ if a complaint stems not from a given source file, but from one of
its included files, the source filename will be printed followed by
a question mark.
.Pp
The special input file name
.Dq Pa -
causes
.Nm
to take input from standard input (until end of file) and process
it as if it were a
.Pa \&.c
file.
If the
.Fl i
flag is given and
.Dq Pa -
is named as one of the input files, the
.Fl o
flag must also be specified to provide an output file name.
.Pp
.Sy Options
.Bl -tag -width Fl
.It Fl a
@ -174,21 +235,25 @@ Complain about unusual operations on
and combinations of
.Sy enum Ns -
and
.Sy integer Ns -Types.
.Sy integer Ns -Types .
.It Fl g
Don't print warnings for some extensions of
.Xr gcc 1
to the C language. Currently these are nonconstant initializers in
automatic aggregate initializations, arithmetic on pointer to void,
trailing commas in enum declarations, C++ -style
.Dq //
comments,
zero sized structures, subscripting of non-lvalue arrays, prototypes
overriding old style function declarations and long long
integer types. The
integer types.
The
.Fl g
flag also turns on the keywords
.Sy asm
and
.Sy inline
(alternate keywords with leading underscores for both
(alternative keywords with leading underscores for both
.Sy asm
and
.Sy inline
@ -204,7 +269,7 @@ file for every
file on the command line. These
.Pa \&.ln
files are the product of
.Nm lint Ns 's
.Nm "" Ns 's
first pass only, and are not checked for compatibility
between functions.
.It Fl n
@ -237,7 +302,7 @@ are defined without leading and trailing underscores. The keywords
.Sy volatile
and
.Sy signed
are not available in traditional C mode (although the alternate
are not available in traditional C mode (although the alternative
keywords with leading underscores still are).
.It Fl u
Do not complain about functions and external variables used
@ -248,13 +313,16 @@ on a subset of files comprising part of a larger program).
.It Fl v
Suppress complaints about unused arguments in functions.
.It Fl x
Report variables refferd to by
Report variables referred to by
.Sy extern
declarations, but never used.
.It Fl z
Do not complain about structures that are never defined
(for example, using a structure pointer without knowing
its contents).
.It Fl B Ns Ar path
Path to use when looking for the lint1 and lint2 binaries. Defualts to
.Pa /usr/libexec .
.It Fl C Ns Ar library
Create a
.Nm
@ -284,6 +352,10 @@ is defined as 1.
Add
.Ar directory
to the list of directories in which to search for include files.
.It Fl d Ns Ar directory
Use
.Ar directory
instead of /usr/include as the default place to find include files.
.It Fl l Ns Ar library
Include the lint library
.Pa llib-l Ns Ar library Ns Pa \&.ln .
@ -306,7 +378,7 @@ followed by a question mark.
Name the output file
.Ar outputfile .
The output file produced is the input that is given to
.Nm lint Ns 's
.Nm "" Ns 's
second pass. The
.Fl o
option simply saves this file in the named output file. If the
@ -327,13 +399,19 @@ for the preprocessor.
.It Fl V
Print the command lines constructed by the controller program to
run the C preprocessor and
.Nm lint Ns 's
.Nm "" Ns 's
first and second pass.
.It Fl w
Treat warnings as errors.
.It Fl X Ar id Ns Op ,id ...
Suppress error messages identified by the list of ids. A list of messages
and ids can be found in
.Xr lint 7 .
.El
.Pp
.Sy Input Grammar
.Pp
.Nm lint Ns 's
.Nm "" Ns 's
first pass reads standard C source files.
.Nm
recognizes the following C comments as commands.
@ -348,6 +426,9 @@ arguments for usage; a missing
is taken to be 0 (this option acts like the
.Fl v
option for the next function).
.It Li /* BITFIELDTYPE */
Suppress error messages about illegal bitfield types if the type
is an integer type, and suppress non-portable bitfield type warnings.
.It Li /* CONSTCOND */ No or Xo
.Li /* CONSTANTCOND */ No or
.Li /* CONSTANTCONDITION */
@ -376,14 +457,14 @@ Also shut off complaints about unused function arguments.
.Xc
Suppresses any intra-file warning except those dealing with
unused variables or functions. This directive should be placed
on the line immediately preceding where the lint warning occured.
on the line immediately preceding where the lint warning occurred.
.It Li /* LONGLONG */
Suppress complaints about use of long long integer types.
.It Li /* NOTREACHED */
At appropriate points, inhibit complaints about unreachable code.
(This comment is typically placed just after calls to functions
like
.Xr exit 2 ).
.Xr exit 3 ) .
.It Li /* PRINTFLIKE Ns Ar n Li */
makes
.Nm
@ -442,7 +523,7 @@ file that corresponds to the
file, and prints all messages that are about just that
source file. After all the source files have been separetely
run through
.Nm lint ,
.Nm "" ,
it is invoked once more (without the
.Fl i
option), listing all the
@ -458,7 +539,7 @@ to be used to
.Nm
only the source files that have been modified since the last
time the set of source files were
.Nm lint Ns No ed .
.Nm "" Ns No ed .
.Sh ENVIRONMENT
.Bl -tag -width Fl
.It Ev LIBDIR
@ -471,6 +552,9 @@ will be used to search for the libraries.
.It Ev TMPDIR
usually the path for temporary files can be redefined by setting
this environment variable.
.It Ev CC
Location of the C compiler program. Defaults to
.Pa /usr/bin/cc .
.El
.Sh FILES
.Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
@ -480,6 +564,7 @@ programs
various prebuilt lint libraries
.It Pa /tmp/lint*
temporaries
.El
.Sh SEE ALSO
.Xr cc 1 ,
.Xr cpp 1 ,
@ -488,7 +573,7 @@ temporaries
Jochen Pohl
.Sh BUGS
The routines
.Xr exit 2 ,
.Xr exit 3 ,
.Xr longjmp 3
and other functions that do not return are not understood; this
causes various incorrect diagnostics.

View File

@ -1,4 +1,4 @@
/* $NetBSD: pathnames.h,v 1.2 1995/07/03 21:25:20 cgd Exp $ */
/* $NetBSD: pathnames.h,v 1.3 1999/04/22 04:40:58 mrg Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,12 @@
*/
/* directory where lint1 and lint2 reside */
#ifndef PATH_LIBEXEC
#define PATH_LIBEXEC "/usr/libexec"
#endif
/* directory where cc(1) resides */
#define PATH_USRBIN "/usr/bin"
/* default library search path */
#define PATH_LINTLIB "/usr/libdata/lint"

View File

@ -1,6 +1,7 @@
/* $NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $ */
/* $NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,33 +32,38 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $");
#endif
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <paths.h>
#include "lint.h"
#include "pathnames.h"
int main(int, char *[]);
/* directory for temporary files */
static const char *tmpdir;
/* path name for cpp output */
static char *cppout;
/* file descriptor for cpp output */
static int cppoutfd = -1;
/* files created by 1st pass */
static char **p1out;
@ -67,11 +73,11 @@ static char **p2in;
/* library which will be created by 2nd pass */
static char *p2out;
/* flags always passed to cpp */
static char **cppflags;
/* flags always passed to cc(1) */
static char **cflags;
/* flags for cpp, controled by sflag/tflag */
static char **lcppflgs;
/* flags for cc(1), controled by sflag/tflag */
static char **lcflags;
/* flags for lint1 */
static char **l1flags;
@ -91,8 +97,10 @@ static char **libs;
/* search path for libraries */
static char **libsrchpath;
static char *libexec_path;
/* flags */
static int iflag, oflag, Cflag, sflag, tflag, Fflag;
static int iflag, oflag, Cflag, sflag, tflag, Fflag, dflag, Bflag;
/* print the commands executed to run the stages of compilation */
static int Vflag;
@ -109,80 +117,80 @@ static int first = 1;
*/
static const char *currfn;
#if !defined(TARGET_PREFIX)
#define TARGET_PREFIX ""
#endif
static const char target_prefix[] = TARGET_PREFIX;
static void appstrg __P((char ***, char *));
static void appcstrg __P((char ***, const char *));
static void applst __P((char ***, char *const *));
static void freelst __P((char ***));
static char *concat2 __P((const char *, const char *));
static char *concat3 __P((const char *, const char *, const char *));
static void terminate __P((int));
static const char *basename __P((const char *, int));
static void appdef __P((char ***, const char *));
static void usage __P((void));
static void fname __P((const char *, int));
static void runchild __P((const char *, char *const *, const char *));
static void findlibs __P((char *const *));
static int rdok __P((const char *));
static void lint2 __P((void));
static void cat __P((char *const *, const char *));
static void appstrg(char ***, char *);
static void appcstrg(char ***, const char *);
static void applst(char ***, char *const *);
static void freelst(char ***);
static char *concat2(const char *, const char *);
static char *concat3(const char *, const char *, const char *);
static void terminate(int) __attribute__((__noreturn__));
static const char *lbasename(const char *, int);
static void appdef(char ***, const char *);
static void usage(void);
static void fname(const char *);
static void runchild(const char *, char *const *, const char *, int);
static void findlibs(char *const *);
static int rdok(const char *);
static void lint2(void);
static void cat(char *const *, const char *);
/*
* Some functions to deal with lists of strings.
* Take care that we get no surprises in case of asyncron signals.
*/
static void
appstrg(lstp, s)
char ***lstp, *s;
appstrg(char ***lstp, char *s)
{
char **lst, **olst;
int i;
olst = *lstp;
for (i = 0; olst[i] != NULL; i++) ;
lst = xmalloc((i + 2) * sizeof (char *));
(void)memcpy(lst, olst, i * sizeof (char *));
for (i = 0; olst[i] != NULL; i++)
continue;
lst = xrealloc(olst, (i + 2) * sizeof (char *));
lst[i] = s;
lst[i + 1] = NULL;
*lstp = lst;
}
}
static void
appcstrg(lstp, s)
char ***lstp;
const char *s;
appcstrg(char ***lstp, const char *s)
{
appstrg(lstp, xstrdup(s));
}
static void
applst(destp, src)
char ***destp;
char *const *src;
applst(char ***destp, char *const *src)
{
int i, k;
char **dest, **odest;
odest = *destp;
for (i = 0; odest[i] != NULL; i++) ;
for (k = 0; src[k] != NULL; k++) ;
dest = xmalloc((i + k + 1) * sizeof (char *));
(void)memcpy(dest, odest, i * sizeof (char *));
for (i = 0; odest[i] != NULL; i++)
continue;
for (k = 0; src[k] != NULL; k++)
continue;
dest = xrealloc(odest, (i + k + 1) * sizeof (char *));
for (k = 0; src[k] != NULL; k++)
dest[i + k] = xstrdup(src[k]);
dest[i + k] = NULL;
*destp = dest;
free(odest);
}
static void
freelst(lstp)
char ***lstp;
freelst(char ***lstp)
{
char *s;
int i;
for (i = 0; (*lstp)[i] != NULL; i++) ;
for (i = 0; (*lstp)[i] != NULL; i++)
continue;
while (i-- > 0) {
s = (*lstp)[i];
(*lstp)[i] = NULL;
@ -191,8 +199,7 @@ freelst(lstp)
}
static char *
concat2(s1, s2)
const char *s1, *s2;
concat2(const char *s1, const char *s2)
{
char *s;
@ -204,8 +211,7 @@ concat2(s1, s2)
}
static char *
concat3(s1, s2, s3)
const char *s1, *s2, *s3;
concat3(const char *s1, const char *s2, const char *s3)
{
char *s;
@ -221,11 +227,12 @@ concat3(s1, s2, s3)
* Clean up after a signal.
*/
static void
terminate(signo)
int signo;
terminate(int signo)
{
int i;
if (cppoutfd != -1)
(void)close(cppoutfd);
if (cppout != NULL)
(void)remove(cppout);
@ -248,9 +255,7 @@ terminate(signo)
* Returns strg if the string does not contain delim.
*/
static const char *
basename(strg, delim)
const char *strg;
int delim;
lbasename(const char *strg, int delim)
{
const char *cp, *cp1, *cp2;
@ -265,34 +270,40 @@ basename(strg, delim)
}
static void
appdef(lstp, def)
char ***lstp;
const char *def;
appdef(char ***lstp, const char *def)
{
appstrg(lstp, concat2("-D__", def));
appstrg(lstp, concat3("-D__", def, "__"));
}
static void
usage()
usage(void)
{
(void)printf("lint [-abceghprvxzHF] [-s|-t] [-i|-nu] [-Dname[=def]] [-Uname]\n");
(void)printf(" [-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile] file ...\n");
(void)printf("\n");
(void)printf("lint [-abceghprvzHF] [-s|-t] -Clibrary [-Dname[=def]]\n");
(void)printf(" [-Idirectory] [-Uname] file ...\n");
(void)fprintf(stderr,
"Usage: %s [-abceghprvwxzHF] [-s|-t] [-i|-nu] [-Dname[=def]]"
" [-Uname] [-X <id>[,<id>]...\n", getprogname());
(void)fprintf(stderr,
"\t[-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile]"
" file...\n");
(void)fprintf(stderr,
" %s [-abceghprvwzHF] [-s|-t] -Clibrary [-Dname[=def]]\n"
" [-X <id>[,<id>]...\n", getprogname());
(void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] file"
" ...\n");
terminate(-1);
}
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int c;
char flgbuf[3], *tmp, *s;
size_t len;
struct utsname un;
setprogname(argv[0]);
if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) {
tmpdir = xstrdup(_PATH_TMP);
@ -304,15 +315,16 @@ main(argc, argv)
cppout = xmalloc(strlen(tmpdir) + sizeof ("lint0.XXXXXX"));
(void)sprintf(cppout, "%slint0.XXXXXX", tmpdir);
if (mktemp(cppout) == NULL) {
cppoutfd = mkstemp(cppout);
if (cppoutfd == -1) {
warn("can't make temp");
terminate(-1);
}
p1out = xcalloc(1, sizeof (char *));
p2in = xcalloc(1, sizeof (char *));
cppflags = xcalloc(1, sizeof (char *));
lcppflgs = xcalloc(1, sizeof (char *));
cflags = xcalloc(1, sizeof (char *));
lcflags = xcalloc(1, sizeof (char *));
l1flags = xcalloc(1, sizeof (char *));
l2flags = xcalloc(1, sizeof (char *));
l2libs = xcalloc(1, sizeof (char *));
@ -320,30 +332,25 @@ main(argc, argv)
libs = xcalloc(1, sizeof (char *));
libsrchpath = xcalloc(1, sizeof (char *));
appcstrg(&cppflags, "-lang-c");
appcstrg(&cppflags, "-undef");
appcstrg(&cppflags, "-$");
appcstrg(&cppflags, "-C");
appcstrg(&cppflags, "-Wcomment");
appcstrg(&cppflags, "-D__NetBSD__");
appcstrg(&cppflags, "-Dlint"); /* XXX don't def. with -s */
appdef(&cppflags, "lint");
appdef(&cppflags, "unix");
appcstrg(&lcppflgs, "-Wtraditional");
if (uname(&un) == -1)
err(1, "uname");
appdef(&cppflags, un.machine);
appstrg(&lcppflgs, concat2("-D", un.machine));
#ifdef MACHINE_ARCH
if (strcmp(un.machine, MACHINE_ARCH) != 0) {
appdef(&cppflags, MACHINE_ARCH);
appstrg(&lcppflgs, concat2("-D", MACHINE_ARCH));
}
appcstrg(&cflags, "-E");
appcstrg(&cflags, "-x");
appcstrg(&cflags, "c");
#if 0
appcstrg(&cflags, "-D__attribute__(x)=");
appcstrg(&cflags, "-D__extension__(x)=/*NOSTRICT*/0");
#else
appcstrg(&cflags, "-U__GNUC__");
#endif
appcstrg(&cflags, "-Wp,-$");
appcstrg(&cflags, "-Wp,-CC");
appcstrg(&cflags, "-Wcomment");
appcstrg(&cflags, "-D__LINT__");
appcstrg(&cflags, "-Dlint"); /* XXX don't def. with -s */
appdef(&cflags, "lint");
appcstrg(&lcflags, "-Wtraditional");
appcstrg(&deflibs, "c");
if (signal(SIGHUP, terminate) == SIG_IGN)
@ -352,14 +359,7 @@ main(argc, argv)
(void)signal(SIGQUIT, terminate);
(void)signal(SIGTERM, terminate);
while (argc > optind) {
argc -= optind;
argv += optind;
optind = 0;
c = getopt(argc, argv, "abceghil:no:prstuvxzC:D:FHI:L:U:V");
while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:U:VX:")) != -1) {
switch (c) {
case 'a':
@ -369,6 +369,7 @@ main(argc, argv)
case 'g':
case 'r':
case 'v':
case 'w':
case 'z':
(void)sprintf(flgbuf, "-%c", c);
appcstrg(&l1flags, flgbuf);
@ -384,6 +385,12 @@ main(argc, argv)
appcstrg(&l2flags, flgbuf);
break;
case 'X':
(void)sprintf(flgbuf, "-%c", c);
appcstrg(&l1flags, flgbuf);
appcstrg(&l1flags, optarg);
break;
case 'i':
if (Cflag)
usage();
@ -406,27 +413,29 @@ main(argc, argv)
case 's':
if (tflag)
usage();
freelst(&lcppflgs);
appcstrg(&lcppflgs, "-trigraphs");
appcstrg(&lcppflgs, "-Wtrigraphs");
appcstrg(&lcppflgs, "-pedantic");
appcstrg(&lcppflgs, "-D__STRICT_ANSI__");
freelst(&lcflags);
appcstrg(&lcflags, "-trigraphs");
appcstrg(&lcflags, "-Wtrigraphs");
appcstrg(&lcflags, "-pedantic");
appcstrg(&lcflags, "-D__STRICT_ANSI__");
appcstrg(&l1flags, "-s");
appcstrg(&l2flags, "-s");
sflag = 1;
break;
#if !HAVE_CONFIG_H
case 't':
if (sflag)
usage();
freelst(&lcppflgs);
appcstrg(&lcppflgs, "-traditional");
appstrg(&lcppflgs, concat2("-D", MACHINE));
appstrg(&lcppflgs, concat2("-D", MACHINE_ARCH));
freelst(&lcflags);
appcstrg(&lcflags, "-traditional");
appstrg(&lcflags, concat2("-D", MACHINE));
appstrg(&lcflags, concat2("-D", MACHINE_ARCH));
appcstrg(&l1flags, "-t");
appcstrg(&l2flags, "-t");
tflag = 1;
break;
#endif
case 'x':
appcstrg(&l2flags, "-x");
@ -442,11 +451,20 @@ main(argc, argv)
freelst(&deflibs);
break;
case 'd':
if (dflag)
usage();
dflag = 1;
appcstrg(&cflags, "-nostdinc");
appcstrg(&cflags, "-idirafter");
appcstrg(&cflags, optarg);
break;
case 'D':
case 'I':
case 'U':
(void)sprintf(flgbuf, "-%c", c);
appstrg(&cppflags, concat2(flgbuf, optarg));
appstrg(&cflags, concat2(flgbuf, optarg));
break;
case 'l':
@ -468,21 +486,64 @@ main(argc, argv)
appcstrg(&l2flags, "-H");
break;
case 'B':
Bflag = 1;
libexec_path = xstrdup(optarg);
break;
case 'V':
Vflag = 1;
break;
case '?':
default:
usage();
/* NOTREACHED */
case -1:
/* filename */
fname(argv[0], argc == 1);
first = 0;
optind = 1;
}
}
argc -= optind;
argv += optind;
/*
* To avoid modifying getopt(3)'s state engine midstream, we
* explicitly accept just a few options after the first source file.
*
* In particular, only -l<lib> and -L<libdir> (and these with a space
* after -l or -L) are allowed.
*/
while (argc > 0) {
const char *arg = argv[0];
if (arg[0] == '-') {
char ***list;
/* option */
switch (arg[1]) {
case 'l':
list = &libs;
break;
case 'L':
list = &libsrchpath;
break;
default:
usage();
/* NOTREACHED */
}
if (arg[2])
appcstrg(list, arg + 2);
else if (argc > 1) {
argc--;
appcstrg(list, *++argv);
} else
usage();
} else {
/* filename */
fname(arg);
first = 0;
}
argc--;
argv++;
}
if (first)
@ -517,16 +578,17 @@ main(argc, argv)
* and pass it through lint1 if it is a C source.
*/
static void
fname(name, last)
const char *name;
int last;
fname(const char *name)
{
const char *bn, *suff;
char **args, *ofn, *path;
size_t len;
int is_stdin;
int fd;
bn = basename(name, '/');
suff = basename(bn, '.');
is_stdin = (strcmp(name, "-") == 0);
bn = lbasename(name, '/');
suff = lbasename(bn, '.');
if (strcmp(suff, "ln") == 0) {
/* only for lint2 */
@ -535,14 +597,15 @@ fname(name, last)
return;
}
if (strcmp(suff, "c") != 0 &&
if (!is_stdin && strcmp(suff, "c") != 0 &&
(strncmp(bn, "llib-l", 6) != 0 || bn != suff)) {
warnx("unknown file type: %s\n", name);
return;
}
if (!iflag || !first || !last)
(void)printf("%s:\n", Fflag ? name : bn);
if (!iflag || !first)
(void)printf("%s:\n",
is_stdin ? "{standard input}" : Fflag ? name : bn);
/* build the name of the output file of lint1 */
if (oflag) {
@ -550,6 +613,10 @@ fname(name, last)
outputfn = NULL;
oflag = 0;
} else if (iflag) {
if (is_stdin) {
warnx("-i not supported without -o for standard input");
return;
}
ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2));
len = bn == suff ? strlen(bn) : (suff - 1) - bn;
(void)sprintf(ofn, "%.*s", (int)len, bn);
@ -557,42 +624,68 @@ fname(name, last)
} else {
ofn = xmalloc(strlen(tmpdir) + sizeof ("lint1.XXXXXX"));
(void)sprintf(ofn, "%slint1.XXXXXX", tmpdir);
if (mktemp(ofn) == NULL) {
fd = mkstemp(ofn);
if (fd == -1) {
warn("can't make temp");
terminate(-1);
}
close(fd);
}
if (!iflag)
appcstrg(&p1out, ofn);
args = xcalloc(1, sizeof (char *));
/* run cpp */
/* run cc */
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/cpp"));
(void)sprintf(path, "%s/cpp", PATH_LIBEXEC);
if (getenv("CC") == NULL) {
path = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc"));
(void)sprintf(path, "%s/cc", PATH_USRBIN);
} else {
path = strdup(getenv("CC"));
}
appcstrg(&args, path);
applst(&args, cppflags);
applst(&args, lcppflgs);
applst(&args, cflags);
applst(&args, lcflags);
appcstrg(&args, name);
appcstrg(&args, cppout);
runchild(path, args, cppout);
/* we reuse the same tmp file for cpp output, so rewind and truncate */
if (lseek(cppoutfd, SEEK_SET, (off_t)0) != 0) {
warn("lseek");
terminate(-1);
}
if (ftruncate(cppoutfd, (off_t)0) != 0) {
warn("ftruncate");
terminate(-1);
}
runchild(path, args, cppout, cppoutfd);
free(path);
freelst(&args);
/* run lint1 */
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1"));
(void)sprintf(path, "%s/lint1", PATH_LIBEXEC);
if (!Bflag) {
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") +
strlen(target_prefix));
(void)sprintf(path, "%s/%slint1", PATH_LIBEXEC,
target_prefix);
} else {
/*
* XXX Unclear whether we should be using target_prefix
* XXX here. --thorpej@wasabisystems.com
*/
path = xmalloc(strlen(libexec_path) + sizeof ("/lint1"));
(void)sprintf(path, "%s/lint1", libexec_path);
}
appcstrg(&args, path);
applst(&args, l1flags);
appcstrg(&args, cppout);
appcstrg(&args, ofn);
runchild(path, args, ofn);
runchild(path, args, ofn, -1);
free(path);
freelst(&args);
@ -603,9 +696,7 @@ fname(name, last)
}
static void
runchild(path, args, crfn)
const char *path, *crfn;
char *const *args;
runchild(const char *path, char *const *args, const char *crfn, int fdout)
{
int status, rv, signo, i;
@ -619,7 +710,7 @@ runchild(path, args, crfn)
(void)fflush(stdout);
switch (fork()) {
switch (vfork()) {
case -1:
warn("cannot fork");
terminate(-1);
@ -629,9 +720,15 @@ runchild(path, args, crfn)
break;
case 0:
/* child */
(void)execv(path, args);
/* setup the standard output if necessary */
if (fdout != -1) {
dup2(fdout, STDOUT_FILENO);
close(fdout);
}
(void)execvp(path, args);
warn("cannot exec %s", path);
exit(1);
_exit(1);
/* NOTREACHED */
}
@ -642,7 +739,11 @@ runchild(path, args, crfn)
}
if (WIFSIGNALED(status)) {
signo = WTERMSIG(status);
#if HAVE_DECL_SYS_SIGNAME
warnx("%s got SIG%s", path, sys_signame[signo]);
#else
warnx("%s got signal %d", path, signo);
#endif
terminate(-1);
}
if (WEXITSTATUS(status) != 0)
@ -651,8 +752,7 @@ runchild(path, args, crfn)
}
static void
findlibs(liblst)
char *const *liblst;
findlibs(char *const *liblst)
{
int i, k;
const char *lib, *path;
@ -684,14 +784,13 @@ findlibs(liblst)
}
static int
rdok(path)
const char *path;
rdok(const char *path)
{
struct stat sbuf;
if (stat(path, &sbuf) == -1)
return (0);
if ((sbuf.st_mode & S_IFMT) != S_IFREG)
if (!S_ISREG(sbuf.st_mode))
return (0);
if (access(path, R_OK) == -1)
return (0);
@ -699,30 +798,39 @@ rdok(path)
}
static void
lint2()
lint2(void)
{
char *path, **args;
args = xcalloc(1, sizeof (char *));
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2"));
(void)sprintf(path, "%s/lint2", PATH_LIBEXEC);
if (!Bflag) {
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2") +
strlen(target_prefix));
(void)sprintf(path, "%s/%slint2", PATH_LIBEXEC,
target_prefix);
} else {
/*
* XXX Unclear whether we should be using target_prefix
* XXX here. --thorpej@wasabisystems.com
*/
path = xmalloc(strlen(libexec_path) + sizeof ("/lint2"));
(void)sprintf(path, "%s/lint2", libexec_path);
}
appcstrg(&args, path);
applst(&args, l2flags);
applst(&args, l2libs);
applst(&args, p2in);
runchild(path, args, p2out);
runchild(path, args, p2out, -1);
free(path);
freelst(&args);
free(args);
}
static void
cat(srcs, dest)
char *const *srcs;
const char *dest;
cat(char *const *srcs, const char *dest)
{
int ifd, ofd, i;
char *src, *buf;
@ -758,4 +866,3 @@ cat(srcs, dest)
(void)close(ofd);
free(buf);
}