xref: /original-bsd/old/dbx/operators.c (revision 1808f06c)
18436d65eSdist /*
2be26f981Sbostic  * Copyright (c) 1983 The Regents of the University of California.
3be26f981Sbostic  * All rights reserved.
4be26f981Sbostic  *
5*1808f06cSbostic  * %sccs.include.redist.c%
68436d65eSdist  */
725d1907eSlinton 
88436d65eSdist #ifndef lint
9*1808f06cSbostic static char sccsid[] = "@(#)operators.c	5.3 (Berkeley) 06/01/90";
10be26f981Sbostic #endif /* not lint */
1125d1907eSlinton 
1225d1907eSlinton /*
1325d1907eSlinton  * Tree node classes.
1425d1907eSlinton  */
1525d1907eSlinton 
1625d1907eSlinton #include "defs.h"
1725d1907eSlinton #include "operators.h"
1825d1907eSlinton 
1925d1907eSlinton #ifndef public
2025d1907eSlinton typedef struct {
2125d1907eSlinton     char numargs;
2225d1907eSlinton     char opflags;
2325d1907eSlinton     String opstring;
2425d1907eSlinton } Opinfo;
2525d1907eSlinton 
2625d1907eSlinton typedef enum {
2725d1907eSlinton     O_NOP,
28c94e17c4Slinton     O_NAME, O_SYM, O_LCON, O_CCON, O_FCON, O_SCON,
2925d1907eSlinton     O_RVAL, O_INDEX, O_INDIR, O_DOT,
3025d1907eSlinton     O_COMMA,
3125d1907eSlinton 
3225d1907eSlinton     O_ITOF, O_ADD, O_ADDF, O_SUB, O_SUBF, O_NEG, O_NEGF,
3325d1907eSlinton     O_MUL, O_MULF, O_DIVF, O_DIV, O_MOD,
3425d1907eSlinton 
3525d1907eSlinton     O_AND, O_OR,
3625d1907eSlinton 
3725d1907eSlinton     O_LT, O_LTF, O_LE, O_LEF, O_GT, O_GTF, O_GE, O_GEF,
3825d1907eSlinton     O_EQ, O_EQF, O_NE, O_NEF,
3925d1907eSlinton 
4025d1907eSlinton     O_ALIAS,		/* rename a command */
4125d1907eSlinton     O_ASSIGN,		/* assign a value to a program variable */
4225d1907eSlinton     O_CALL,		/* call a procedure in the program */
4325d1907eSlinton     O_CATCH,		/* catch a signal before program does */
4425d1907eSlinton     O_CHFILE,		/* change (or print) the current source file */
4525d1907eSlinton     O_CONT,		/* continue execution */
465671facbScsvaf     O_DEBUG,		/* invoke a dbx internal debugging routine */
4725d1907eSlinton     O_DELETE,		/* remove a trace/stop */
4825d1907eSlinton     O_DUMP,		/* dump out variables */
4925d1907eSlinton     O_EDIT,		/* edit a file (or function) */
5025d1907eSlinton     O_FUNC,		/* set the current function */
5125d1907eSlinton     O_GRIPE,		/* send mail to debugger support person */
5225d1907eSlinton     O_HELP,		/* print a synopsis of debugger commands */
5325d1907eSlinton     O_IGNORE,		/* let program catch signal */
5425d1907eSlinton     O_LIST,		/* list source lines */
5525d1907eSlinton     O_PRINT,		/* print the values of a list of expressions */
5625d1907eSlinton     O_PSYM,		/* print symbol information */
5725d1907eSlinton     O_RUN,		/* start up program */
5825d1907eSlinton     O_SKIP,		/* skip the current line */
5925d1907eSlinton     O_SOURCE,		/* read commands from a file */
6025d1907eSlinton     O_STATUS,		/* display currently active trace/stop's */
6125d1907eSlinton     O_STEP,		/* execute a single line */
6225d1907eSlinton     O_STOP,		/* stop on an event */
6325d1907eSlinton     O_STOPI,		/* stop on an event at an instruction boundary */
6425d1907eSlinton     O_TRACE,		/* trace something on an event */
6525d1907eSlinton     O_TRACEI,		/* trace at the instruction level */
6625d1907eSlinton     O_WHATIS,		/* print the declaration of a variable */
6725d1907eSlinton     O_WHERE,		/* print a stack trace */
6825d1907eSlinton     O_WHEREIS,		/* print all the symbols with the given name */
6925d1907eSlinton     O_WHICH,		/* print out full qualification of a symbol */
7025d1907eSlinton     O_EXAMINE,		/* examine program instructions/data */
7125d1907eSlinton 
7225d1907eSlinton     O_ADDEVENT,		/* add an event */
7325d1907eSlinton     O_ENDX,		/* end of program reached */
7425d1907eSlinton     O_IF,		/* if first arg is true, do commands in second arg */
7525d1907eSlinton     O_ONCE,		/* add a "one-time" event, delete when first reached */
7625d1907eSlinton     O_PRINTCALL,	/* print out the current procedure and its arguments */
7725d1907eSlinton     O_PRINTIFCHANGED,	/* print the value of the argument if it has changed */
7825d1907eSlinton     O_PRINTRTN,		/* print out the routine and value that just returned */
7925d1907eSlinton     O_PRINTSRCPOS,	/* print out the current source position */
80c94e17c4Slinton     O_PROCRTN,		/* call completed */
8125d1907eSlinton     O_QLINE,		/* filename, line number */
8225d1907eSlinton     O_STOPIFCHANGED,	/* stop if the value of the argument has changed */
8325d1907eSlinton     O_STOPX,		/* stop execution */
8425d1907eSlinton     O_TRACEON,		/* begin tracing source line, variable, or all lines */
8525d1907eSlinton     O_TRACEOFF,		/* end tracing source line, variable, or all lines */
8625d1907eSlinton 
8767e9467eSlinton     O_TYPERENAME,	/* state the type of an expression */
882f6b6db0Ssam     O_RERUN,		/* re-run program with the same arguments as before */
892f6b6db0Ssam     O_RETURN,		/* continue execution until procedure returns */
902f6b6db0Ssam     O_UP,		/* move current function up the call stack */
912f6b6db0Ssam     O_DOWN,		/* move current function down the call stack */
92c94e17c4Slinton     O_CALLPROC,		/* call command */
93c94e17c4Slinton     O_SEARCH,		/* regular expression pattern search through source */
94c94e17c4Slinton     O_SET,		/* set a debugger variable */
95c94e17c4Slinton     O_UNSET,		/* unset a debugger variable */
96c94e17c4Slinton     O_UNALIAS,		/* remove an alias */
9767e9467eSlinton 
9825d1907eSlinton     O_LASTOP
9925d1907eSlinton } Operator;
10025d1907eSlinton 
10125d1907eSlinton /*
10225d1907eSlinton  * Operator flags and predicates.
10325d1907eSlinton  */
10425d1907eSlinton 
10525d1907eSlinton #define null 0
10625d1907eSlinton #define LEAF 01
10725d1907eSlinton #define UNARY 02
10825d1907eSlinton #define BINARY 04
10925d1907eSlinton #define BOOL 010
11025d1907eSlinton #define REALOP 020
11125d1907eSlinton #define INTOP 040
11225d1907eSlinton 
11325d1907eSlinton #define isbitset(a, m)	((a&m) == m)
11425d1907eSlinton #define isleaf(o)	isbitset(opinfo[ord(o)].opflags, LEAF)
11525d1907eSlinton #define isunary(o)	isbitset(opinfo[ord(o)].opflags, UNARY)
11625d1907eSlinton #define isbinary(o)	isbitset(opinfo[ord(o)].opflags, BINARY)
11725d1907eSlinton #define isreal(o)	isbitset(opinfo[ord(o)].opflags, REALOP)
11825d1907eSlinton #define isint(o)	isbitset(opinfo[ord(o)].opflags, INTOP)
11925d1907eSlinton #define isboolean(o)	isbitset(opinfo[ord(o)].opflags, BOOL)
12025d1907eSlinton 
12125d1907eSlinton #define degree(o)	(opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY))
12225d1907eSlinton #define nargs(o)	(opinfo[ord(o)].numargs)
12325d1907eSlinton 
12425d1907eSlinton #endif
12525d1907eSlinton 
12625d1907eSlinton /*
12725d1907eSlinton  * Operator information structure.
12825d1907eSlinton  */
12925d1907eSlinton 
13025d1907eSlinton public Opinfo opinfo[] ={
13125d1907eSlinton /* O_NOP */		0,	null,		0,
13225d1907eSlinton /* O_NAME */		-1,	LEAF,		0,
13325d1907eSlinton /* O_SYM */		-1,	LEAF,		0,
13425d1907eSlinton /* O_LCON */		-1,	LEAF,		0,
135c94e17c4Slinton /* O_CCON */		-1,	LEAF,		0,
13625d1907eSlinton /* O_FCON */		-1,	LEAF,		0,
13725d1907eSlinton /* O_SCON */		-1,	LEAF,		0,
13825d1907eSlinton /* O_RVAL */		1,	UNARY,		0,
139c94e17c4Slinton /* O_INDEX */		2,	null,		0,
14025d1907eSlinton /* O_INDIR */		1,	UNARY,		"^",
14125d1907eSlinton /* O_DOT */		2,	null,		".",
142c94e17c4Slinton /* O_COMMA */		2,	null,		",",
14325d1907eSlinton /* O_ITOF */		1,	UNARY|INTOP,	0,
14425d1907eSlinton /* O_ADD */		2,	BINARY|INTOP,	"+",
14525d1907eSlinton /* O_ADDF */		2,	BINARY|REALOP,	"+",
14625d1907eSlinton /* O_SUB */		2,	BINARY|INTOP,	"-",
14725d1907eSlinton /* O_SUBF */		2,	BINARY|REALOP,	"-",
14825d1907eSlinton /* O_NEG */		1,	UNARY|INTOP,	"-",
14925d1907eSlinton /* O_NEGF */		1,	UNARY|REALOP,	"-",
15025d1907eSlinton /* O_MUL */		2,	BINARY|INTOP,	"*",
15125d1907eSlinton /* O_MULF */		2,	BINARY|REALOP,	"*",
15225d1907eSlinton /* O_DIVF */		2,	BINARY|REALOP,	"/",
15325d1907eSlinton /* O_DIV */		2,	BINARY|INTOP,	" div ",
15425d1907eSlinton /* O_MOD */		2,	BINARY|INTOP,	" mod ",
15525d1907eSlinton /* O_AND */		2,	BINARY|INTOP,	" and ",
15625d1907eSlinton /* O_OR */		2,	BINARY|INTOP,	" or ",
15725d1907eSlinton /* O_LT */		2,	BINARY|INTOP,	" < ",
15825d1907eSlinton /* O_LTF */		2,	BINARY|REALOP,	" < ",
15925d1907eSlinton /* O_LE */		2,	BINARY|INTOP,	" <= ",
16025d1907eSlinton /* O_LEF */		2,	BINARY|REALOP,	" <= ",
16125d1907eSlinton /* O_GT */		2,	BINARY|INTOP,	" > ",
16225d1907eSlinton /* O_GTF */		2,	BINARY|REALOP,	" > ",
16325d1907eSlinton /* O_GE */		2,	BINARY|INTOP,	" >= ",
16425d1907eSlinton /* O_GEF */		2,	BINARY|REALOP,	" >= ",
16525d1907eSlinton /* O_EQ */		2,	BINARY|INTOP,	" = ",
16625d1907eSlinton /* O_EQF */		2,	BINARY|REALOP,	" = ",
16725d1907eSlinton /* O_NE */		2,	BINARY|INTOP,	" <> ",
16825d1907eSlinton /* O_NEF */		2,	BINARY|REALOP,	" <> ",
16925d1907eSlinton 
17025d1907eSlinton /* O_ALIAS */		2,	null,		"alias",
171c94e17c4Slinton /* O_ASSIGN */		2,	null,		" := ",
17225d1907eSlinton /* O_CALL */		2,	null,		"call",
173c94e17c4Slinton /* O_CATCH */		0,	null,		"catch",
17425d1907eSlinton /* O_CHFILE */		0,	null,		"file",
17525d1907eSlinton /* O_CONT */		0,	null,		"cont",
1765671facbScsvaf /* O_DEBUG */		0,	null,		"debug",
1772f6b6db0Ssam /* O_DELETE */		1,	null,		"delete",
178c94e17c4Slinton /* O_DUMP */		1,	null,		"dump",
17925d1907eSlinton /* O_EDIT */		0,	null,		"edit",
18025d1907eSlinton /* O_FUNC */		1,	null,		"func",
18125d1907eSlinton /* O_GRIPE */		0,	null,		"gripe",
18225d1907eSlinton /* O_HELP */		0,	null,		"help",
183c94e17c4Slinton /* O_IGNORE */		0,	null,		"ignore",
18425d1907eSlinton /* O_LIST */		2,	null,		"list",
18525d1907eSlinton /* O_PRINT */		1,	null,		"print",
18625d1907eSlinton /* O_PSYM */		1,	null,		"psym",
18725d1907eSlinton /* O_RUN */		0,	null,		"run",
18825d1907eSlinton /* O_SKIP */		0,	null,		"skip",
18925d1907eSlinton /* O_SOURCE */		0,	null,		"source",
19025d1907eSlinton /* O_STATUS */		0,	null,		"status",
19125d1907eSlinton /* O_STEP */		0,	null,		"step",
19225d1907eSlinton /* O_STOP */		3,	null,		"stop",
19325d1907eSlinton /* O_STOPI */		3,	null,		"stopi",
19425d1907eSlinton /* O_TRACE */		3,	null,		"trace",
19525d1907eSlinton /* O_TRACEI */		3,	null,		"tracei",
19625d1907eSlinton /* O_WHATIS */		1,	null,		"whatis",
19725d1907eSlinton /* O_WHERE */		0,	null,		"where",
19825d1907eSlinton /* O_WHEREIS */		1,	null,		"whereis",
19925d1907eSlinton /* O_WHICH */		1,	null,		"which",
20025d1907eSlinton /* O_EXAMINE */		0,	null,		"examine",
20125d1907eSlinton 
20225d1907eSlinton /* O_ADDEVENT */	0,	null,		"when",
20325d1907eSlinton /* O_ENDX */		0,	null,		nil,
20425d1907eSlinton /* O_IF */		0,	null,		"if",
20525d1907eSlinton /* O_ONCE */		0,	null,		"once",
20625d1907eSlinton /* O_PRINTCALL */	1,	null,		"printcall",
20725d1907eSlinton /* O_PRINTIFCHANGED */	1,	null,		"printifchanged",
20825d1907eSlinton /* O_PRINTRTN */	1,	null,		"printrtn",
20925d1907eSlinton /* O_PRINTSRCPOS */	1,	null,		"printsrcpos",
21025d1907eSlinton /* O_PROCRTN */		1,	null,		"procrtn",
21125d1907eSlinton /* O_QLINE */		2,	null,		nil,
21225d1907eSlinton /* O_STOPIFCHANGED */	1,	null,		"stopifchanged",
21325d1907eSlinton /* O_STOPX */		0,	null,		"stop",
21425d1907eSlinton /* O_TRACEON */		1,	null,		"traceon",
21525d1907eSlinton /* O_TRACEOFF */	1,	null,		"traceoff",
21672ac7b2aSsam /* O_TYPERENAME */	2,	UNARY,		"type rename",
2172f6b6db0Ssam /* O_RERUN */		0,	null,		"rerun",
2182f6b6db0Ssam /* O_RETURN */		1,	null,		"return",
2192f6b6db0Ssam /* O_UP */		1,	UNARY,		"up",
2202f6b6db0Ssam /* O_DOWN */		1,	UNARY,		"down",
221c94e17c4Slinton /* O_CALLPROC */	2,	null,		"call",
222c94e17c4Slinton /* O_SEARCH */		2,	null,		"search",
223c94e17c4Slinton /* O_SET */		2,	null,		"set",
224c94e17c4Slinton /* O_UNSET */		1,	null,		"unset",
225c94e17c4Slinton /* O_UNALIAS */		1,	null,		"unalias",
22625d1907eSlinton };
227