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