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