1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)operators.c 1.4 5/18/83"; 4 5 static char rcsid[] = "$Header: operators.c,v 1.3 84/03/27 10:22:38 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_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, /* CALLPROC 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 88 O_LASTOP 89 } Operator; 90 91 /* 92 * Operator flags and predicates. 93 */ 94 95 #define null 0 96 #define LEAF 01 97 #define UNARY 02 98 #define BINARY 04 99 #define BOOL 010 100 #define REALOP 020 101 #define INTOP 040 102 103 #define isbitset(a, m) ((a&m) == m) 104 #define isleaf(o) isbitset(opinfo[ord(o)].opflags, LEAF) 105 #define isunary(o) isbitset(opinfo[ord(o)].opflags, UNARY) 106 #define isbinary(o) isbitset(opinfo[ord(o)].opflags, BINARY) 107 #define isreal(o) isbitset(opinfo[ord(o)].opflags, REALOP) 108 #define isint(o) isbitset(opinfo[ord(o)].opflags, INTOP) 109 #define isboolean(o) isbitset(opinfo[ord(o)].opflags, BOOL) 110 111 #define degree(o) (opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY)) 112 #define nargs(o) (opinfo[ord(o)].numargs) 113 114 #endif 115 116 /* 117 * Operator information structure. 118 */ 119 120 public Opinfo opinfo[] ={ 121 /* O_NOP */ 0, null, 0, 122 /* O_NAME */ -1, LEAF, 0, 123 /* O_SYM */ -1, LEAF, 0, 124 /* O_LCON */ -1, LEAF, 0, 125 /* O_FCON */ -1, LEAF, 0, 126 /* O_SCON */ -1, LEAF, 0, 127 /* O_RVAL */ 1, UNARY, 0, 128 /* O_INDEX */ 2, BINARY, 0, 129 /* O_INDIR */ 1, UNARY, "^", 130 /* O_DOT */ 2, null, ".", 131 /* O_COMMA */ 2, BINARY, ",", 132 /* O_ITOF */ 1, UNARY|INTOP, 0, 133 /* O_ADD */ 2, BINARY|INTOP, "+", 134 /* O_ADDF */ 2, BINARY|REALOP, "+", 135 /* O_SUB */ 2, BINARY|INTOP, "-", 136 /* O_SUBF */ 2, BINARY|REALOP, "-", 137 /* O_NEG */ 1, UNARY|INTOP, "-", 138 /* O_NEGF */ 1, UNARY|REALOP, "-", 139 /* O_MUL */ 2, BINARY|INTOP, "*", 140 /* O_MULF */ 2, BINARY|REALOP, "*", 141 /* O_DIVF */ 2, BINARY|REALOP, "/", 142 /* O_DIV */ 2, BINARY|INTOP, " div ", 143 /* O_MOD */ 2, BINARY|INTOP, " mod ", 144 /* O_AND */ 2, BINARY|INTOP, " and ", 145 /* O_OR */ 2, BINARY|INTOP, " or ", 146 /* O_LT */ 2, BINARY|INTOP, " < ", 147 /* O_LTF */ 2, BINARY|REALOP, " < ", 148 /* O_LE */ 2, BINARY|INTOP, " <= ", 149 /* O_LEF */ 2, BINARY|REALOP, " <= ", 150 /* O_GT */ 2, BINARY|INTOP, " > ", 151 /* O_GTF */ 2, BINARY|REALOP, " > ", 152 /* O_GE */ 2, BINARY|INTOP, " >= ", 153 /* O_GEF */ 2, BINARY|REALOP, " >= ", 154 /* O_EQ */ 2, BINARY|INTOP, " = ", 155 /* O_EQF */ 2, BINARY|REALOP, " = ", 156 /* O_NE */ 2, BINARY|INTOP, " <> ", 157 /* O_NEF */ 2, BINARY|REALOP, " <> ", 158 159 /* O_ALIAS */ 2, null, "alias", 160 /* O_ASSIGN */ 2, BINARY, " := ", 161 /* O_CALL */ 2, null, "call", 162 /* O_CATCH */ 0, null, "catch", 163 /* O_CHFILE */ 0, null, "file", 164 /* O_CONT */ 0, null, "cont", 165 /* O_DEBUG */ 0, null, "debug", 166 /* O_DELETE */ 1, null, "delete", 167 /* O_DUMP */ 0, null, "dump", 168 /* O_EDIT */ 0, null, "edit", 169 /* O_FUNC */ 1, null, "func", 170 /* O_GRIPE */ 0, null, "gripe", 171 /* O_HELP */ 0, null, "help", 172 /* O_IGNORE */ 0, null, "ignore", 173 /* O_LIST */ 2, null, "list", 174 /* O_PRINT */ 1, null, "print", 175 /* O_PSYM */ 1, null, "psym", 176 /* O_RUN */ 0, null, "run", 177 /* O_SKIP */ 0, null, "skip", 178 /* O_SOURCE */ 0, null, "source", 179 /* O_STATUS */ 0, null, "status", 180 /* O_STEP */ 0, null, "step", 181 /* O_STOP */ 3, null, "stop", 182 /* O_STOPI */ 3, null, "stopi", 183 /* O_TRACE */ 3, null, "trace", 184 /* O_TRACEI */ 3, null, "tracei", 185 /* O_WHATIS */ 1, null, "whatis", 186 /* O_WHERE */ 0, null, "where", 187 /* O_WHEREIS */ 1, null, "whereis", 188 /* O_WHICH */ 1, null, "which", 189 /* O_EXAMINE */ 0, null, "examine", 190 191 /* O_ADDEVENT */ 0, null, "when", 192 /* O_ENDX */ 0, null, nil, 193 /* O_IF */ 0, null, "if", 194 /* O_ONCE */ 0, null, "once", 195 /* O_PRINTCALL */ 1, null, "printcall", 196 /* O_PRINTIFCHANGED */ 1, null, "printifchanged", 197 /* O_PRINTRTN */ 1, null, "printrtn", 198 /* O_PRINTSRCPOS */ 1, null, "printsrcpos", 199 /* O_PROCRTN */ 1, null, "procrtn", 200 /* O_QLINE */ 2, null, nil, 201 /* O_STOPIFCHANGED */ 1, null, "stopifchanged", 202 /* O_STOPX */ 0, null, "stop", 203 /* O_TRACEON */ 1, null, "traceon", 204 /* O_TRACEOFF */ 1, null, "traceoff", 205 /* O_TYPERENAME */ 2, UNARY, "traceoff", 206 /* O_RERUN */ 0, null, "rerun", 207 /* O_RETURN */ 1, null, "return", 208 /* O_UP */ 1, UNARY, "up", 209 /* O_DOWN */ 1, UNARY, "down", 210 }; 211