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