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