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