* Copyright (c) 1983 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)check.c 5.4 (Berkeley) %G%";
* Check a tree for semantic correctness.
* Check that the nodes in a tree have the correct arguments
* in order to be evaluated. Basically the error checking here
* frees the evaluation routines from worrying about anything
* except dynamic errors, e.g. subscript out of range.
if (varIsSet("$unsafeassign")) {
if (size(p1
->nodetype
) != size(p2
->nodetype
)) {
error("incompatible sizes");
} else if (not compatible(p1
->nodetype
, p2
->nodetype
)) {
error("incompatible types");
if (p
->value
.lcon
< 0 or p
->value
.lcon
> NSIG
) {
error("invalid signal number");
if (p
->value
.lcon
!= DEFSIG
and (
p
->value
.lcon
< 0 or p
->value
.lcon
> NSIG
)
error("invalid signal number");
if (p
->value
.arg
[0] != nil
) {
if (p
->value
.arg
[0]->op
== O_SYM
) {
f
= p
->value
.arg
[0]->value
.sym
;
error("\"%s\" is not a block", symname(f
));
fprintf(stderr
, "expected a symbol, found \"");
prtree(stderr
, p
->value
.arg
[0]);
if (p
->value
.arg
[0]->op
== O_SYM
) {
f
= p
->value
.arg
[0]->value
.sym
;
if (not isblock(f
) or ismodule(f
)) {
error("\"%s\" is not a procedure or function", symname(f
));
error("\"%s\" is empty", symname(f
));
if (not isroutine(p
->value
.arg
[0]->nodetype
)) {
prtree(stderr
, p
->value
.arg
[0]);
fprintf(stderr
, "\" not call-able");
if (p
->value
.arg
[0]->op
== O_SYM
and
p
->value
.arg
[0]->value
.sym
== nil
) {
error("symbol not defined");
* Check arguments to a trace command.
} else if (exp
->op
== O_LCON
or exp
->op
== O_QLINE
) {
error("unexpected \"at\" or \"in\"");
} else if (place
!= nil
and (place
->op
== O_QLINE
or place
->op
== O_LCON
)) {
if (exp
->op
!= O_RVAL
and exp
->op
!= O_SYM
and exp
->op
!= O_CALL
) {
error("can't trace expressions");
* Check arguments to a stop command.
if (exp
->op
!= O_RVAL
and exp
->op
!= O_SYM
and exp
->op
!= O_LCON
) {
fprintf(stderr
, "expected variable, found ");
} else if (place
!= nil
) {
if (place
->op
== O_SYM
) {
* Check to see that the given node specifies some subprogram.
* Nil is ok since that means the entire program.
fprintf(stderr
, "expected subprogram, found ");
} else if (ismodule(b
->value
.sym
)) {
find(p
, outer
->name
) where p
->block
== outer
endfind(p
);
error("\"%s\" is not a subprogram", symname(b
->value
.sym
));
} else if (ismodule(p
)) {
b
->value
.sym
->class == VAR
and
b
->value
.sym
->name
== b
->value
.sym
->block
->name
and
b
->value
.sym
->block
->class == FUNC
b
->value
.sym
= b
->value
.sym
->block
;
} else if (not isblock(b
->value
.sym
)) {
error("\"%s\" is not a subprogram", symname(b
->value
.sym
));
* Check to make sure a node corresponds to a source line.
} else if (p
->op
!= O_QLINE
and p
->op
!= O_LCON
) {
error("expected source line number, found \"%t\"", p
);
* Check to make sure a node corresponds to an address.
error("missing address");
} else if (p
->op
!= O_LCON
and p
->op
!= O_QLINE
) {
fprintf(stderr
, "expected address, found \"");