19674Slinton /* Copyright (c) 1982 Regents of the University of California */ 29674Slinton 3*12543Scsvaf static char sccsid[] = "@(#)operators.c 1.4 05/18/83"; 49674Slinton 59674Slinton /* 69674Slinton * Tree node classes. 79674Slinton */ 89674Slinton 99674Slinton #include "defs.h" 109674Slinton #include "operators.h" 119674Slinton 129674Slinton #ifndef public 139674Slinton typedef struct { 149674Slinton char numargs; 159674Slinton char opflags; 169674Slinton String opstring; 179674Slinton } Opinfo; 189674Slinton 199674Slinton typedef enum { 209674Slinton O_NOP, 219674Slinton O_NAME, O_SYM, O_LCON, O_FCON, O_SCON, 229674Slinton O_RVAL, O_INDEX, O_INDIR, O_DOT, 239674Slinton O_COMMA, 249674Slinton 259674Slinton O_ITOF, O_ADD, O_ADDF, O_SUB, O_SUBF, O_NEG, O_NEGF, 269674Slinton O_MUL, O_MULF, O_DIVF, O_DIV, O_MOD, 279674Slinton 289674Slinton O_AND, O_OR, 299674Slinton 309674Slinton O_LT, O_LTF, O_LE, O_LEF, O_GT, O_GTF, O_GE, O_GEF, 319674Slinton O_EQ, O_EQF, O_NE, O_NEF, 329674Slinton 339674Slinton O_ALIAS, /* rename a command */ 349674Slinton O_ASSIGN, /* assign a value to a program variable */ 359674Slinton O_CALL, /* call a procedure in the program */ 369674Slinton O_CATCH, /* catch a signal before program does */ 379674Slinton O_CHFILE, /* change (or print) the current source file */ 389674Slinton O_CONT, /* continue execution */ 39*12543Scsvaf O_DEBUG, /* invoke a dbx internal debugging routine */ 409674Slinton O_DELETE, /* remove a trace/stop */ 419674Slinton O_DUMP, /* dump out variables */ 429674Slinton O_EDIT, /* edit a file (or function) */ 439674Slinton O_FUNC, /* set the current function */ 449674Slinton O_GRIPE, /* send mail to debugger support person */ 459674Slinton O_HELP, /* print a synopsis of debugger commands */ 469674Slinton O_IGNORE, /* let program catch signal */ 479674Slinton O_LIST, /* list source lines */ 489674Slinton O_PRINT, /* print the values of a list of expressions */ 499674Slinton O_PSYM, /* print symbol information */ 509674Slinton O_RUN, /* start up program */ 519674Slinton O_SKIP, /* skip the current line */ 529674Slinton O_SOURCE, /* read commands from a file */ 539674Slinton O_STATUS, /* display currently active trace/stop's */ 549674Slinton O_STEP, /* execute a single line */ 559674Slinton O_STOP, /* stop on an event */ 569674Slinton O_STOPI, /* stop on an event at an instruction boundary */ 579674Slinton O_TRACE, /* trace something on an event */ 589674Slinton O_TRACEI, /* trace at the instruction level */ 599674Slinton O_WHATIS, /* print the declaration of a variable */ 609674Slinton O_WHERE, /* print a stack trace */ 619674Slinton O_WHEREIS, /* print all the symbols with the given name */ 629674Slinton O_WHICH, /* print out full qualification of a symbol */ 639674Slinton O_EXAMINE, /* examine program instructions/data */ 649674Slinton 659674Slinton O_ADDEVENT, /* add an event */ 669674Slinton O_ENDX, /* end of program reached */ 679674Slinton O_IF, /* if first arg is true, do commands in second arg */ 689674Slinton O_ONCE, /* add a "one-time" event, delete when first reached */ 699674Slinton O_PRINTCALL, /* print out the current procedure and its arguments */ 709674Slinton O_PRINTIFCHANGED, /* print the value of the argument if it has changed */ 719674Slinton O_PRINTRTN, /* print out the routine and value that just returned */ 729674Slinton O_PRINTSRCPOS, /* print out the current source position */ 739674Slinton O_PROCRTN, /* CALLPROC completed */ 749674Slinton O_QLINE, /* filename, line number */ 759674Slinton O_STOPIFCHANGED, /* stop if the value of the argument has changed */ 769674Slinton O_STOPX, /* stop execution */ 779674Slinton O_TRACEON, /* begin tracing source line, variable, or all lines */ 789674Slinton O_TRACEOFF, /* end tracing source line, variable, or all lines */ 799674Slinton 8011166Slinton O_TYPERENAME, /* state the type of an expression */ 8111166Slinton 829674Slinton O_LASTOP 839674Slinton } Operator; 849674Slinton 859674Slinton /* 869674Slinton * Operator flags and predicates. 879674Slinton */ 889674Slinton 899674Slinton #define null 0 909674Slinton #define LEAF 01 919674Slinton #define UNARY 02 929674Slinton #define BINARY 04 939674Slinton #define BOOL 010 949674Slinton #define REALOP 020 959674Slinton #define INTOP 040 969674Slinton 979674Slinton #define isbitset(a, m) ((a&m) == m) 989674Slinton #define isleaf(o) isbitset(opinfo[ord(o)].opflags, LEAF) 999674Slinton #define isunary(o) isbitset(opinfo[ord(o)].opflags, UNARY) 1009674Slinton #define isbinary(o) isbitset(opinfo[ord(o)].opflags, BINARY) 1019674Slinton #define isreal(o) isbitset(opinfo[ord(o)].opflags, REALOP) 1029674Slinton #define isint(o) isbitset(opinfo[ord(o)].opflags, INTOP) 1039674Slinton #define isboolean(o) isbitset(opinfo[ord(o)].opflags, BOOL) 1049674Slinton 1059674Slinton #define degree(o) (opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY)) 1069674Slinton #define nargs(o) (opinfo[ord(o)].numargs) 1079674Slinton 1089674Slinton #endif 1099674Slinton 1109674Slinton /* 1119674Slinton * Operator information structure. 1129674Slinton */ 1139674Slinton 1149674Slinton public Opinfo opinfo[] ={ 1159674Slinton /* O_NOP */ 0, null, 0, 1169674Slinton /* O_NAME */ -1, LEAF, 0, 1179674Slinton /* O_SYM */ -1, LEAF, 0, 1189674Slinton /* O_LCON */ -1, LEAF, 0, 1199674Slinton /* O_FCON */ -1, LEAF, 0, 1209674Slinton /* O_SCON */ -1, LEAF, 0, 1219674Slinton /* O_RVAL */ 1, UNARY, 0, 1229674Slinton /* O_INDEX */ 2, BINARY, 0, 1239674Slinton /* O_INDIR */ 1, UNARY, "^", 1249674Slinton /* O_DOT */ 2, null, ".", 1259674Slinton /* O_COMMA */ 2, BINARY, ",", 1269674Slinton /* O_ITOF */ 1, UNARY|INTOP, 0, 1279674Slinton /* O_ADD */ 2, BINARY|INTOP, "+", 1289674Slinton /* O_ADDF */ 2, BINARY|REALOP, "+", 1299674Slinton /* O_SUB */ 2, BINARY|INTOP, "-", 1309674Slinton /* O_SUBF */ 2, BINARY|REALOP, "-", 1319674Slinton /* O_NEG */ 1, UNARY|INTOP, "-", 1329674Slinton /* O_NEGF */ 1, UNARY|REALOP, "-", 1339674Slinton /* O_MUL */ 2, BINARY|INTOP, "*", 1349674Slinton /* O_MULF */ 2, BINARY|REALOP, "*", 1359674Slinton /* O_DIVF */ 2, BINARY|REALOP, "/", 1369674Slinton /* O_DIV */ 2, BINARY|INTOP, " div ", 1379674Slinton /* O_MOD */ 2, BINARY|INTOP, " mod ", 1389674Slinton /* O_AND */ 2, BINARY|INTOP, " and ", 1399674Slinton /* O_OR */ 2, BINARY|INTOP, " or ", 1409674Slinton /* O_LT */ 2, BINARY|INTOP, " < ", 1419674Slinton /* O_LTF */ 2, BINARY|REALOP, " < ", 1429674Slinton /* O_LE */ 2, BINARY|INTOP, " <= ", 1439674Slinton /* O_LEF */ 2, BINARY|REALOP, " <= ", 1449674Slinton /* O_GT */ 2, BINARY|INTOP, " > ", 1459674Slinton /* O_GTF */ 2, BINARY|REALOP, " > ", 1469674Slinton /* O_GE */ 2, BINARY|INTOP, " >= ", 1479674Slinton /* O_GEF */ 2, BINARY|REALOP, " >= ", 1489674Slinton /* O_EQ */ 2, BINARY|INTOP, " = ", 1499674Slinton /* O_EQF */ 2, BINARY|REALOP, " = ", 1509674Slinton /* O_NE */ 2, BINARY|INTOP, " <> ", 1519674Slinton /* O_NEF */ 2, BINARY|REALOP, " <> ", 1529674Slinton 1539674Slinton /* O_ALIAS */ 2, null, "alias", 1549674Slinton /* O_ASSIGN */ 2, BINARY, " := ", 1559674Slinton /* O_CALL */ 2, null, "call", 1569674Slinton /* O_CATCH */ 0, null, "catch", 1579674Slinton /* O_CHFILE */ 0, null, "file", 1589674Slinton /* O_CONT */ 0, null, "cont", 159*12543Scsvaf /* O_DEBUG */ 0, null, "debug", 1609674Slinton /* O_DELETE */ 0, null, "delete", 1619674Slinton /* O_DUMP */ 0, null, "dump", 1629674Slinton /* O_EDIT */ 0, null, "edit", 1639674Slinton /* O_FUNC */ 1, null, "func", 1649674Slinton /* O_GRIPE */ 0, null, "gripe", 1659674Slinton /* O_HELP */ 0, null, "help", 1669674Slinton /* O_IGNORE */ 0, null, "ignore", 1679674Slinton /* O_LIST */ 2, null, "list", 1689674Slinton /* O_PRINT */ 1, null, "print", 1699674Slinton /* O_PSYM */ 1, null, "psym", 1709674Slinton /* O_RUN */ 0, null, "run", 1719674Slinton /* O_SKIP */ 0, null, "skip", 1729674Slinton /* O_SOURCE */ 0, null, "source", 1739674Slinton /* O_STATUS */ 0, null, "status", 1749674Slinton /* O_STEP */ 0, null, "step", 1759674Slinton /* O_STOP */ 3, null, "stop", 1769674Slinton /* O_STOPI */ 3, null, "stopi", 1779674Slinton /* O_TRACE */ 3, null, "trace", 1789674Slinton /* O_TRACEI */ 3, null, "tracei", 1799674Slinton /* O_WHATIS */ 1, null, "whatis", 1809674Slinton /* O_WHERE */ 0, null, "where", 1819674Slinton /* O_WHEREIS */ 1, null, "whereis", 1829674Slinton /* O_WHICH */ 1, null, "which", 1839674Slinton /* O_EXAMINE */ 0, null, "examine", 1849674Slinton 1859674Slinton /* O_ADDEVENT */ 0, null, "when", 1869674Slinton /* O_ENDX */ 0, null, nil, 1879674Slinton /* O_IF */ 0, null, "if", 1889674Slinton /* O_ONCE */ 0, null, "once", 1899674Slinton /* O_PRINTCALL */ 1, null, "printcall", 1909674Slinton /* O_PRINTIFCHANGED */ 1, null, "printifchanged", 1919674Slinton /* O_PRINTRTN */ 1, null, "printrtn", 1929674Slinton /* O_PRINTSRCPOS */ 1, null, "printsrcpos", 1939674Slinton /* O_PROCRTN */ 1, null, "procrtn", 1949674Slinton /* O_QLINE */ 2, null, nil, 1959674Slinton /* O_STOPIFCHANGED */ 1, null, "stopifchanged", 1969674Slinton /* O_STOPX */ 0, null, "stop", 1979674Slinton /* O_TRACEON */ 1, null, "traceon", 1989674Slinton /* O_TRACEOFF */ 1, null, "traceoff", 19911166Slinton /* O_TYPERENAME */ 2, UNARY, "traceoff", 2009674Slinton }; 201