1988-09-20 16:44:27 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1988-09-20 16:44:27 +00:00
|
|
|
/* Lint evaluation order checking */
|
|
|
|
|
|
|
|
#include "lint.h"
|
|
|
|
|
|
|
|
#ifdef LINT
|
|
|
|
|
|
|
|
#include <alloc.h> /* for st_free */
|
1989-02-02 13:57:07 +00:00
|
|
|
#include "interface.h"
|
1988-09-26 11:37:38 +00:00
|
|
|
#include "assert.h"
|
1990-12-06 14:56:42 +00:00
|
|
|
#ifdef ANSI
|
|
|
|
#include <flt_arith.h>
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* ANSI */
|
1988-09-20 16:44:27 +00:00
|
|
|
#include "arith.h" /* definition arith */
|
|
|
|
#include "label.h" /* definition label */
|
|
|
|
#include "expr.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "code.h" /* RVAL etc */
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "level.h"
|
|
|
|
#include "l_lint.h"
|
|
|
|
#include "l_state.h"
|
|
|
|
|
|
|
|
extern char *symbol2str();
|
|
|
|
|
1989-02-02 13:57:07 +00:00
|
|
|
PRIVATE check_ev_order();
|
|
|
|
|
|
|
|
check_and_merge(expr, espp, esp)
|
|
|
|
struct expr *expr;
|
1988-09-20 16:44:27 +00:00
|
|
|
struct expr_state **espp, *esp;
|
|
|
|
{
|
1989-02-02 13:57:07 +00:00
|
|
|
/* Checks for undefined evaluation orders in case of a non-sequencing operator.
|
1988-09-20 16:44:27 +00:00
|
|
|
* In addition the sets of used and set variables of both expressions are
|
|
|
|
* united.
|
|
|
|
* *espp will be pointing to this new list. esp is used for this list.
|
|
|
|
*/
|
|
|
|
register struct expr_state **pp, *p1, *p2;
|
1989-02-02 13:57:07 +00:00
|
|
|
int oper = expr->OP_OPER;
|
|
|
|
int is_sequencer =
|
|
|
|
(oper == '?' || oper == OR || oper == AND || oper ==',');
|
1988-09-20 16:44:27 +00:00
|
|
|
|
|
|
|
for (p1 = *espp; p1; p1 = p1->next) {
|
1989-02-02 13:57:07 +00:00
|
|
|
/* scan the list esp for the same variable */
|
1988-09-20 16:44:27 +00:00
|
|
|
p2 = esp;
|
|
|
|
pp = &esp;
|
|
|
|
while (p2) {
|
1989-02-02 13:57:07 +00:00
|
|
|
if ( /* p1 and p2 refer to the same location */
|
1988-09-20 16:44:27 +00:00
|
|
|
p1->es_idf == p2->es_idf
|
|
|
|
&& p1->es_offset == p2->es_offset
|
|
|
|
) {
|
1989-02-02 13:57:07 +00:00
|
|
|
/* check */
|
|
|
|
if (!is_sequencer)
|
|
|
|
check_ev_order(p1, p2, expr);
|
|
|
|
|
|
|
|
/* merge the info */
|
1988-09-20 16:44:27 +00:00
|
|
|
p1->es_used |= p2->es_used;
|
1989-02-02 13:57:07 +00:00
|
|
|
p1->es_referred |= p2->es_referred;
|
1988-09-20 16:44:27 +00:00
|
|
|
p1->es_set |= p2->es_set;
|
1989-02-02 13:57:07 +00:00
|
|
|
|
|
|
|
/* and remove the entry from esp */
|
1988-09-20 16:44:27 +00:00
|
|
|
*pp = p2->next;
|
|
|
|
free_expr_state(p2);
|
|
|
|
p2 = *pp;
|
|
|
|
}
|
|
|
|
else {
|
1989-02-02 13:57:07 +00:00
|
|
|
/* skip over the entry in esp */
|
1988-09-20 16:44:27 +00:00
|
|
|
pp = &p2->next;
|
|
|
|
p2 = p2->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1989-02-02 13:57:07 +00:00
|
|
|
/* If there is anything left in the list esp, this is put in
|
|
|
|
front of the list *espp is now pointing to, and *espp will be
|
|
|
|
left pointing to this new list.
|
|
|
|
*/
|
1988-09-20 16:44:27 +00:00
|
|
|
if (!esp)
|
|
|
|
return;
|
|
|
|
p1 = *espp;
|
|
|
|
*espp = esp;
|
|
|
|
while (esp->next)
|
|
|
|
esp = esp->next;
|
|
|
|
esp->next = p1;
|
|
|
|
}
|
|
|
|
|
1989-02-02 13:57:07 +00:00
|
|
|
PRIVATE
|
|
|
|
check_ev_order(esp1, esp2, expr)
|
1988-09-20 16:44:27 +00:00
|
|
|
struct expr_state *esp1, *esp2;
|
1989-02-02 13:57:07 +00:00
|
|
|
struct expr *expr;
|
1988-09-20 16:44:27 +00:00
|
|
|
{
|
|
|
|
if ( (esp1->es_used && esp2->es_set)
|
|
|
|
|| (esp1->es_set && esp2->es_used)
|
|
|
|
|| (esp1->es_set && esp2->es_set)
|
|
|
|
) {
|
1989-02-02 13:57:07 +00:00
|
|
|
expr_warning(expr,
|
|
|
|
"result of %s depends on evaluation order on %s",
|
|
|
|
symbol2str(expr->OP_OPER),
|
1988-09-20 16:44:27 +00:00
|
|
|
esp1->es_idf->id_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|