xref: /csrg-svn/old/dbx/operators.c (revision 9674)
1*9674Slinton /* Copyright (c) 1982 Regents of the University of California */
2*9674Slinton 
3*9674Slinton static char sccsid[] = "@(#)@(#)operators.c 1.1 12/15/82";
4*9674Slinton 
5*9674Slinton /*
6*9674Slinton  * Tree node classes.
7*9674Slinton  */
8*9674Slinton 
9*9674Slinton #include "defs.h"
10*9674Slinton #include "operators.h"
11*9674Slinton 
12*9674Slinton #ifndef public
13*9674Slinton typedef struct {
14*9674Slinton     char numargs;
15*9674Slinton     char opflags;
16*9674Slinton     String opstring;
17*9674Slinton } Opinfo;
18*9674Slinton 
19*9674Slinton typedef enum {
20*9674Slinton     O_NOP,
21*9674Slinton     O_NAME, O_SYM, O_LCON, O_FCON, O_SCON,
22*9674Slinton     O_RVAL, O_INDEX, O_INDIR, O_DOT,
23*9674Slinton     O_COMMA,
24*9674Slinton 
25*9674Slinton     O_ITOF, O_ADD, O_ADDF, O_SUB, O_SUBF, O_NEG, O_NEGF,
26*9674Slinton     O_MUL, O_MULF, O_DIVF, O_DIV, O_MOD,
27*9674Slinton 
28*9674Slinton     O_AND, O_OR,
29*9674Slinton 
30*9674Slinton     O_LT, O_LTF, O_LE, O_LEF, O_GT, O_GTF, O_GE, O_GEF,
31*9674Slinton     O_EQ, O_EQF, O_NE, O_NEF,
32*9674Slinton 
33*9674Slinton     O_ALIAS,		/* rename a command */
34*9674Slinton     O_ASSIGN,		/* assign a value to a program variable */
35*9674Slinton     O_CALL,		/* call a procedure in the program */
36*9674Slinton     O_CATCH,		/* catch a signal before program does */
37*9674Slinton     O_CHFILE,		/* change (or print) the current source file */
38*9674Slinton     O_CONT,		/* continue execution */
39*9674Slinton     O_DELETE,		/* remove a trace/stop */
40*9674Slinton     O_DUMP,		/* dump out variables */
41*9674Slinton     O_EDIT,		/* edit a file (or function) */
42*9674Slinton     O_FUNC,		/* set the current function */
43*9674Slinton     O_GRIPE,		/* send mail to debugger support person */
44*9674Slinton     O_HELP,		/* print a synopsis of debugger commands */
45*9674Slinton     O_IGNORE,		/* let program catch signal */
46*9674Slinton     O_LIST,		/* list source lines */
47*9674Slinton     O_PRINT,		/* print the values of a list of expressions */
48*9674Slinton     O_PSYM,		/* print symbol information */
49*9674Slinton     O_RUN,		/* start up program */
50*9674Slinton     O_SKIP,		/* skip the current line */
51*9674Slinton     O_SOURCE,		/* read commands from a file */
52*9674Slinton     O_STATUS,		/* display currently active trace/stop's */
53*9674Slinton     O_STEP,		/* execute a single line */
54*9674Slinton     O_STOP,		/* stop on an event */
55*9674Slinton     O_STOPI,		/* stop on an event at an instruction boundary */
56*9674Slinton     O_TRACE,		/* trace something on an event */
57*9674Slinton     O_TRACEI,		/* trace at the instruction level */
58*9674Slinton     O_WHATIS,		/* print the declaration of a variable */
59*9674Slinton     O_WHERE,		/* print a stack trace */
60*9674Slinton     O_WHEREIS,		/* print all the symbols with the given name */
61*9674Slinton     O_WHICH,		/* print out full qualification of a symbol */
62*9674Slinton     O_EXAMINE,		/* examine program instructions/data */
63*9674Slinton 
64*9674Slinton     O_ADDEVENT,		/* add an event */
65*9674Slinton     O_ENDX,		/* end of program reached */
66*9674Slinton     O_IF,		/* if first arg is true, do commands in second arg */
67*9674Slinton     O_ONCE,		/* add a "one-time" event, delete when first reached */
68*9674Slinton     O_PRINTCALL,	/* print out the current procedure and its arguments */
69*9674Slinton     O_PRINTIFCHANGED,	/* print the value of the argument if it has changed */
70*9674Slinton     O_PRINTRTN,		/* print out the routine and value that just returned */
71*9674Slinton     O_PRINTSRCPOS,	/* print out the current source position */
72*9674Slinton     O_PROCRTN,		/* CALLPROC completed */
73*9674Slinton     O_QLINE,		/* filename, line number */
74*9674Slinton     O_STOPIFCHANGED,	/* stop if the value of the argument has changed */
75*9674Slinton     O_STOPX,		/* stop execution */
76*9674Slinton     O_TRACEON,		/* begin tracing source line, variable, or all lines */
77*9674Slinton     O_TRACEOFF,		/* end tracing source line, variable, or all lines */
78*9674Slinton 
79*9674Slinton     O_LASTOP
80*9674Slinton } Operator;
81*9674Slinton 
82*9674Slinton /*
83*9674Slinton  * Operator flags and predicates.
84*9674Slinton  */
85*9674Slinton 
86*9674Slinton #define null 0
87*9674Slinton #define LEAF 01
88*9674Slinton #define UNARY 02
89*9674Slinton #define BINARY 04
90*9674Slinton #define BOOL 010
91*9674Slinton #define REALOP 020
92*9674Slinton #define INTOP 040
93*9674Slinton 
94*9674Slinton #define isbitset(a, m)	((a&m) == m)
95*9674Slinton #define isleaf(o)	isbitset(opinfo[ord(o)].opflags, LEAF)
96*9674Slinton #define isunary(o)	isbitset(opinfo[ord(o)].opflags, UNARY)
97*9674Slinton #define isbinary(o)	isbitset(opinfo[ord(o)].opflags, BINARY)
98*9674Slinton #define isreal(o)	isbitset(opinfo[ord(o)].opflags, REALOP)
99*9674Slinton #define isint(o)	isbitset(opinfo[ord(o)].opflags, INTOP)
100*9674Slinton #define isboolean(o)	isbitset(opinfo[ord(o)].opflags, BOOL)
101*9674Slinton 
102*9674Slinton #define degree(o)	(opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY))
103*9674Slinton #define nargs(o)	(opinfo[ord(o)].numargs)
104*9674Slinton 
105*9674Slinton #endif
106*9674Slinton 
107*9674Slinton /*
108*9674Slinton  * Operator information structure.
109*9674Slinton  */
110*9674Slinton 
111*9674Slinton public Opinfo opinfo[] ={
112*9674Slinton /* O_NOP */		0,	null,		0,
113*9674Slinton /* O_NAME */		-1,	LEAF,		0,
114*9674Slinton /* O_SYM */		-1,	LEAF,		0,
115*9674Slinton /* O_LCON */		-1,	LEAF,		0,
116*9674Slinton /* O_FCON */		-1,	LEAF,		0,
117*9674Slinton /* O_SCON */		-1,	LEAF,		0,
118*9674Slinton /* O_RVAL */		1,	UNARY,		0,
119*9674Slinton /* O_INDEX */		2,	BINARY,		0,
120*9674Slinton /* O_INDIR */		1,	UNARY,		"^",
121*9674Slinton /* O_DOT */		2,	null,		".",
122*9674Slinton /* O_COMMA */		2,	BINARY,		",",
123*9674Slinton /* O_ITOF */		1,	UNARY|INTOP,	0,
124*9674Slinton /* O_ADD */		2,	BINARY|INTOP,	"+",
125*9674Slinton /* O_ADDF */		2,	BINARY|REALOP,	"+",
126*9674Slinton /* O_SUB */		2,	BINARY|INTOP,	"-",
127*9674Slinton /* O_SUBF */		2,	BINARY|REALOP,	"-",
128*9674Slinton /* O_NEG */		1,	UNARY|INTOP,	"-",
129*9674Slinton /* O_NEGF */		1,	UNARY|REALOP,	"-",
130*9674Slinton /* O_MUL */		2,	BINARY|INTOP,	"*",
131*9674Slinton /* O_MULF */		2,	BINARY|REALOP,	"*",
132*9674Slinton /* O_DIVF */		2,	BINARY|REALOP,	"/",
133*9674Slinton /* O_DIV */		2,	BINARY|INTOP,	" div ",
134*9674Slinton /* O_MOD */		2,	BINARY|INTOP,	" mod ",
135*9674Slinton /* O_AND */		2,	BINARY|INTOP,	" and ",
136*9674Slinton /* O_OR */		2,	BINARY|INTOP,	" or ",
137*9674Slinton /* O_LT */		2,	BINARY|INTOP,	" < ",
138*9674Slinton /* O_LTF */		2,	BINARY|REALOP,	" < ",
139*9674Slinton /* O_LE */		2,	BINARY|INTOP,	" <= ",
140*9674Slinton /* O_LEF */		2,	BINARY|REALOP,	" <= ",
141*9674Slinton /* O_GT */		2,	BINARY|INTOP,	" > ",
142*9674Slinton /* O_GTF */		2,	BINARY|REALOP,	" > ",
143*9674Slinton /* O_GE */		2,	BINARY|INTOP,	" >= ",
144*9674Slinton /* O_GEF */		2,	BINARY|REALOP,	" >= ",
145*9674Slinton /* O_EQ */		2,	BINARY|INTOP,	" = ",
146*9674Slinton /* O_EQF */		2,	BINARY|REALOP,	" = ",
147*9674Slinton /* O_NE */		2,	BINARY|INTOP,	" <> ",
148*9674Slinton /* O_NEF */		2,	BINARY|REALOP,	" <> ",
149*9674Slinton 
150*9674Slinton /* O_ALIAS */		2,	null,		"alias",
151*9674Slinton /* O_ASSIGN */		2,	BINARY,		" := ",
152*9674Slinton /* O_CALL */		2,	null,		"call",
153*9674Slinton /* O_CATCH */		0,	null,		"catch",
154*9674Slinton /* O_CHFILE */		0,	null,		"file",
155*9674Slinton /* O_CONT */		0,	null,		"cont",
156*9674Slinton /* O_DELETE */		0,	null,		"delete",
157*9674Slinton /* O_DUMP */		0,	null,		"dump",
158*9674Slinton /* O_EDIT */		0,	null,		"edit",
159*9674Slinton /* O_FUNC */		1,	null,		"func",
160*9674Slinton /* O_GRIPE */		0,	null,		"gripe",
161*9674Slinton /* O_HELP */		0,	null,		"help",
162*9674Slinton /* O_IGNORE */		0,	null,		"ignore",
163*9674Slinton /* O_LIST */		2,	null,		"list",
164*9674Slinton /* O_PRINT */		1,	null,		"print",
165*9674Slinton /* O_PSYM */		1,	null,		"psym",
166*9674Slinton /* O_RUN */		0,	null,		"run",
167*9674Slinton /* O_SKIP */		0,	null,		"skip",
168*9674Slinton /* O_SOURCE */		0,	null,		"source",
169*9674Slinton /* O_STATUS */		0,	null,		"status",
170*9674Slinton /* O_STEP */		0,	null,		"step",
171*9674Slinton /* O_STOP */		3,	null,		"stop",
172*9674Slinton /* O_STOPI */		3,	null,		"stopi",
173*9674Slinton /* O_TRACE */		3,	null,		"trace",
174*9674Slinton /* O_TRACEI */		3,	null,		"tracei",
175*9674Slinton /* O_WHATIS */		1,	null,		"whatis",
176*9674Slinton /* O_WHERE */		0,	null,		"where",
177*9674Slinton /* O_WHEREIS */		1,	null,		"whereis",
178*9674Slinton /* O_WHICH */		1,	null,		"which",
179*9674Slinton /* O_EXAMINE */		0,	null,		"examine",
180*9674Slinton 
181*9674Slinton /* O_ADDEVENT */	0,	null,		"when",
182*9674Slinton /* O_ENDX */		0,	null,		nil,
183*9674Slinton /* O_IF */		0,	null,		"if",
184*9674Slinton /* O_ONCE */		0,	null,		"once",
185*9674Slinton /* O_PRINTCALL */	1,	null,		"printcall",
186*9674Slinton /* O_PRINTIFCHANGED */	1,	null,		"printifchanged",
187*9674Slinton /* O_PRINTRTN */	1,	null,		"printrtn",
188*9674Slinton /* O_PRINTSRCPOS */	1,	null,		"printsrcpos",
189*9674Slinton /* O_PROCRTN */		1,	null,		"procrtn",
190*9674Slinton /* O_QLINE */		2,	null,		nil,
191*9674Slinton /* O_STOPIFCHANGED */	1,	null,		"stopifchanged",
192*9674Slinton /* O_STOPX */		0,	null,		"stop",
193*9674Slinton /* O_TRACEON */		1,	null,		"traceon",
194*9674Slinton /* O_TRACEOFF */	1,	null,		"traceoff",
195*9674Slinton };
196