* Copyright (c) 1980 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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
static char sccsid
[] = "@(#)predicates.c 5.2 (Berkeley) 4/16/91";
* The basic tests on a symbol.
* Test if a symbol is a parameter. This is true if there
* is a cycle from s->func to s via chain pointers.
for (t
= s
->func
; t
!= NIL
; t
= t
->chain
) {
* Test if a symbol is a var parameter, i.e. has class REF.
return (BOOLEAN
) s
->class == REF
;
* Test if a symbol is a variable (actually any addressible quantity
return s
->class == VAR
|| s
->class == FVAR
|| s
->class == REF
;
* Test if a symbol is a block, e.g. function, procedure, or the
return(s
->class == FUNC
|| s
->class == PROC
|| s
->class == PROG
);
* Test if a symbol is builtin, that is, a predefined type or
return(s
->blkno
== 0 && s
->class != PROG
&& s
->class != VAR
);
* Compatible tests if two types are compatible. The issue
* is complicated a bit by ranges.
* Integers and reals are not compatible since they cannot always be mixed.
BOOLEAN
compatible(t1
, t2
)
if (t1
->type
== t2
->type
) {
if (t1
->class == RANGE
&& t2
->class == RANGE
) {
} else if ((t1
->class == SCAL
|| t1
->class == CONST
) &&
(t2
->class == SCAL
|| t2
->class == CONST
)) {
} else if (t1
->type
== t_char
&&
t1
->class == ARRAY
&& t2
->class == ARRAY
) {
* A kludge here for "nil". Should be handled better.
* Opens a pandora's box for integer/pointer compatibility.
} else if ((t1
->class == RANGE
&& t2
->class == PTR
) ||
(t2
->class == RANGE
&& t1
->class == PTR
)) {
* Predicate to test if a symbol should be printed. We don't print
* files, for example, simply because there's no good way to do it.
* The symbol must be within the given function.
BOOLEAN
should_print(s
, f
)
if (s
->func
!= f
|| (s
->class != VAR
&& s
->class != FVAR
)) {
} else if (s
->chain
!= NIL
) {
if (t
== NIL
|| t
->class == FILET
|| t
->class == SET
) {
* Test if the name of a symbol is uniquely defined or not.
t
= st_lookup(symtab
, s
->symbol
);
panic("symbol name vanished");
while (t
!= NIL
&& (s
== t
|| !streq(t
->symbol
, s
->symbol
))) {