xref: /csrg-svn/old/dbx/operators.c (revision 42683)
121616Sdist /*
238105Sbostic  * Copyright (c) 1983 The Regents of the University of California.
338105Sbostic  * All rights reserved.
438105Sbostic  *
5*42683Sbostic  * %sccs.include.redist.c%
621616Sdist  */
79674Slinton 
821616Sdist #ifndef lint
9*42683Sbostic static char sccsid[] = "@(#)operators.c	5.3 (Berkeley) 06/01/90";
1038105Sbostic #endif /* not lint */
119674Slinton 
129674Slinton /*
139674Slinton  * Tree node classes.
149674Slinton  */
159674Slinton 
169674Slinton #include "defs.h"
179674Slinton #include "operators.h"
189674Slinton 
199674Slinton #ifndef public
209674Slinton typedef struct {
219674Slinton     char numargs;
229674Slinton     char opflags;
239674Slinton     String opstring;
249674Slinton } Opinfo;
259674Slinton 
269674Slinton typedef enum {
279674Slinton     O_NOP,
2818226Slinton     O_NAME, O_SYM, O_LCON, O_CCON, O_FCON, O_SCON,
299674Slinton     O_RVAL, O_INDEX, O_INDIR, O_DOT,
309674Slinton     O_COMMA,
319674Slinton 
329674Slinton     O_ITOF, O_ADD, O_ADDF, O_SUB, O_SUBF, O_NEG, O_NEGF,
339674Slinton     O_MUL, O_MULF, O_DIVF, O_DIV, O_MOD,
349674Slinton 
359674Slinton     O_AND, O_OR,
369674Slinton 
379674Slinton     O_LT, O_LTF, O_LE, O_LEF, O_GT, O_GTF, O_GE, O_GEF,
389674Slinton     O_EQ, O_EQF, O_NE, O_NEF,
399674Slinton 
409674Slinton     O_ALIAS,		/* rename a command */
419674Slinton     O_ASSIGN,		/* assign a value to a program variable */
429674Slinton     O_CALL,		/* call a procedure in the program */
439674Slinton     O_CATCH,		/* catch a signal before program does */
449674Slinton     O_CHFILE,		/* change (or print) the current source file */
459674Slinton     O_CONT,		/* continue execution */
4612543Scsvaf     O_DEBUG,		/* invoke a dbx internal debugging routine */
479674Slinton     O_DELETE,		/* remove a trace/stop */
489674Slinton     O_DUMP,		/* dump out variables */
499674Slinton     O_EDIT,		/* edit a file (or function) */
509674Slinton     O_FUNC,		/* set the current function */
519674Slinton     O_GRIPE,		/* send mail to debugger support person */
529674Slinton     O_HELP,		/* print a synopsis of debugger commands */
539674Slinton     O_IGNORE,		/* let program catch signal */
549674Slinton     O_LIST,		/* list source lines */
559674Slinton     O_PRINT,		/* print the values of a list of expressions */
569674Slinton     O_PSYM,		/* print symbol information */
579674Slinton     O_RUN,		/* start up program */
589674Slinton     O_SKIP,		/* skip the current line */
599674Slinton     O_SOURCE,		/* read commands from a file */
609674Slinton     O_STATUS,		/* display currently active trace/stop's */
619674Slinton     O_STEP,		/* execute a single line */
629674Slinton     O_STOP,		/* stop on an event */
639674Slinton     O_STOPI,		/* stop on an event at an instruction boundary */
649674Slinton     O_TRACE,		/* trace something on an event */
659674Slinton     O_TRACEI,		/* trace at the instruction level */
669674Slinton     O_WHATIS,		/* print the declaration of a variable */
679674Slinton     O_WHERE,		/* print a stack trace */
689674Slinton     O_WHEREIS,		/* print all the symbols with the given name */
699674Slinton     O_WHICH,		/* print out full qualification of a symbol */
709674Slinton     O_EXAMINE,		/* examine program instructions/data */
719674Slinton 
729674Slinton     O_ADDEVENT,		/* add an event */
739674Slinton     O_ENDX,		/* end of program reached */
749674Slinton     O_IF,		/* if first arg is true, do commands in second arg */
759674Slinton     O_ONCE,		/* add a "one-time" event, delete when first reached */
769674Slinton     O_PRINTCALL,	/* print out the current procedure and its arguments */
779674Slinton     O_PRINTIFCHANGED,	/* print the value of the argument if it has changed */
789674Slinton     O_PRINTRTN,		/* print out the routine and value that just returned */
799674Slinton     O_PRINTSRCPOS,	/* print out the current source position */
8018226Slinton     O_PROCRTN,		/* call completed */
819674Slinton     O_QLINE,		/* filename, line number */
829674Slinton     O_STOPIFCHANGED,	/* stop if the value of the argument has changed */
839674Slinton     O_STOPX,		/* stop execution */
849674Slinton     O_TRACEON,		/* begin tracing source line, variable, or all lines */
859674Slinton     O_TRACEOFF,		/* end tracing source line, variable, or all lines */
869674Slinton 
8711166Slinton     O_TYPERENAME,	/* state the type of an expression */
8816614Ssam     O_RERUN,		/* re-run program with the same arguments as before */
8916614Ssam     O_RETURN,		/* continue execution until procedure returns */
9016614Ssam     O_UP,		/* move current function up the call stack */
9116614Ssam     O_DOWN,		/* move current function down the call stack */
9218226Slinton     O_CALLPROC,		/* call command */
9318226Slinton     O_SEARCH,		/* regular expression pattern search through source */
9418226Slinton     O_SET,		/* set a debugger variable */
9518226Slinton     O_UNSET,		/* unset a debugger variable */
9618226Slinton     O_UNALIAS,		/* remove an alias */
9711166Slinton 
989674Slinton     O_LASTOP
999674Slinton } Operator;
1009674Slinton 
1019674Slinton /*
1029674Slinton  * Operator flags and predicates.
1039674Slinton  */
1049674Slinton 
1059674Slinton #define null 0
1069674Slinton #define LEAF 01
1079674Slinton #define UNARY 02
1089674Slinton #define BINARY 04
1099674Slinton #define BOOL 010
1109674Slinton #define REALOP 020
1119674Slinton #define INTOP 040
1129674Slinton 
1139674Slinton #define isbitset(a, m)	((a&m) == m)
1149674Slinton #define isleaf(o)	isbitset(opinfo[ord(o)].opflags, LEAF)
1159674Slinton #define isunary(o)	isbitset(opinfo[ord(o)].opflags, UNARY)
1169674Slinton #define isbinary(o)	isbitset(opinfo[ord(o)].opflags, BINARY)
1179674Slinton #define isreal(o)	isbitset(opinfo[ord(o)].opflags, REALOP)
1189674Slinton #define isint(o)	isbitset(opinfo[ord(o)].opflags, INTOP)
1199674Slinton #define isboolean(o)	isbitset(opinfo[ord(o)].opflags, BOOL)
1209674Slinton 
1219674Slinton #define degree(o)	(opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY))
1229674Slinton #define nargs(o)	(opinfo[ord(o)].numargs)
1239674Slinton 
1249674Slinton #endif
1259674Slinton 
1269674Slinton /*
1279674Slinton  * Operator information structure.
1289674Slinton  */
1299674Slinton 
1309674Slinton public Opinfo opinfo[] ={
1319674Slinton /* O_NOP */		0,	null,		0,
1329674Slinton /* O_NAME */		-1,	LEAF,		0,
1339674Slinton /* O_SYM */		-1,	LEAF,		0,
1349674Slinton /* O_LCON */		-1,	LEAF,		0,
13518226Slinton /* O_CCON */		-1,	LEAF,		0,
1369674Slinton /* O_FCON */		-1,	LEAF,		0,
1379674Slinton /* O_SCON */		-1,	LEAF,		0,
1389674Slinton /* O_RVAL */		1,	UNARY,		0,
13918226Slinton /* O_INDEX */		2,	null,		0,
1409674Slinton /* O_INDIR */		1,	UNARY,		"^",
1419674Slinton /* O_DOT */		2,	null,		".",
14218226Slinton /* O_COMMA */		2,	null,		",",
1439674Slinton /* O_ITOF */		1,	UNARY|INTOP,	0,
1449674Slinton /* O_ADD */		2,	BINARY|INTOP,	"+",
1459674Slinton /* O_ADDF */		2,	BINARY|REALOP,	"+",
1469674Slinton /* O_SUB */		2,	BINARY|INTOP,	"-",
1479674Slinton /* O_SUBF */		2,	BINARY|REALOP,	"-",
1489674Slinton /* O_NEG */		1,	UNARY|INTOP,	"-",
1499674Slinton /* O_NEGF */		1,	UNARY|REALOP,	"-",
1509674Slinton /* O_MUL */		2,	BINARY|INTOP,	"*",
1519674Slinton /* O_MULF */		2,	BINARY|REALOP,	"*",
1529674Slinton /* O_DIVF */		2,	BINARY|REALOP,	"/",
1539674Slinton /* O_DIV */		2,	BINARY|INTOP,	" div ",
1549674Slinton /* O_MOD */		2,	BINARY|INTOP,	" mod ",
1559674Slinton /* O_AND */		2,	BINARY|INTOP,	" and ",
1569674Slinton /* O_OR */		2,	BINARY|INTOP,	" or ",
1579674Slinton /* O_LT */		2,	BINARY|INTOP,	" < ",
1589674Slinton /* O_LTF */		2,	BINARY|REALOP,	" < ",
1599674Slinton /* O_LE */		2,	BINARY|INTOP,	" <= ",
1609674Slinton /* O_LEF */		2,	BINARY|REALOP,	" <= ",
1619674Slinton /* O_GT */		2,	BINARY|INTOP,	" > ",
1629674Slinton /* O_GTF */		2,	BINARY|REALOP,	" > ",
1639674Slinton /* O_GE */		2,	BINARY|INTOP,	" >= ",
1649674Slinton /* O_GEF */		2,	BINARY|REALOP,	" >= ",
1659674Slinton /* O_EQ */		2,	BINARY|INTOP,	" = ",
1669674Slinton /* O_EQF */		2,	BINARY|REALOP,	" = ",
1679674Slinton /* O_NE */		2,	BINARY|INTOP,	" <> ",
1689674Slinton /* O_NEF */		2,	BINARY|REALOP,	" <> ",
1699674Slinton 
1709674Slinton /* O_ALIAS */		2,	null,		"alias",
17118226Slinton /* O_ASSIGN */		2,	null,		" := ",
1729674Slinton /* O_CALL */		2,	null,		"call",
17318226Slinton /* O_CATCH */		0,	null,		"catch",
1749674Slinton /* O_CHFILE */		0,	null,		"file",
1759674Slinton /* O_CONT */		0,	null,		"cont",
17612543Scsvaf /* O_DEBUG */		0,	null,		"debug",
17716614Ssam /* O_DELETE */		1,	null,		"delete",
17818226Slinton /* O_DUMP */		1,	null,		"dump",
1799674Slinton /* O_EDIT */		0,	null,		"edit",
1809674Slinton /* O_FUNC */		1,	null,		"func",
1819674Slinton /* O_GRIPE */		0,	null,		"gripe",
1829674Slinton /* O_HELP */		0,	null,		"help",
18318226Slinton /* O_IGNORE */		0,	null,		"ignore",
1849674Slinton /* O_LIST */		2,	null,		"list",
1859674Slinton /* O_PRINT */		1,	null,		"print",
1869674Slinton /* O_PSYM */		1,	null,		"psym",
1879674Slinton /* O_RUN */		0,	null,		"run",
1889674Slinton /* O_SKIP */		0,	null,		"skip",
1899674Slinton /* O_SOURCE */		0,	null,		"source",
1909674Slinton /* O_STATUS */		0,	null,		"status",
1919674Slinton /* O_STEP */		0,	null,		"step",
1929674Slinton /* O_STOP */		3,	null,		"stop",
1939674Slinton /* O_STOPI */		3,	null,		"stopi",
1949674Slinton /* O_TRACE */		3,	null,		"trace",
1959674Slinton /* O_TRACEI */		3,	null,		"tracei",
1969674Slinton /* O_WHATIS */		1,	null,		"whatis",
1979674Slinton /* O_WHERE */		0,	null,		"where",
1989674Slinton /* O_WHEREIS */		1,	null,		"whereis",
1999674Slinton /* O_WHICH */		1,	null,		"which",
2009674Slinton /* O_EXAMINE */		0,	null,		"examine",
2019674Slinton 
2029674Slinton /* O_ADDEVENT */	0,	null,		"when",
2039674Slinton /* O_ENDX */		0,	null,		nil,
2049674Slinton /* O_IF */		0,	null,		"if",
2059674Slinton /* O_ONCE */		0,	null,		"once",
2069674Slinton /* O_PRINTCALL */	1,	null,		"printcall",
2079674Slinton /* O_PRINTIFCHANGED */	1,	null,		"printifchanged",
2089674Slinton /* O_PRINTRTN */	1,	null,		"printrtn",
2099674Slinton /* O_PRINTSRCPOS */	1,	null,		"printsrcpos",
2109674Slinton /* O_PROCRTN */		1,	null,		"procrtn",
2119674Slinton /* O_QLINE */		2,	null,		nil,
2129674Slinton /* O_STOPIFCHANGED */	1,	null,		"stopifchanged",
2139674Slinton /* O_STOPX */		0,	null,		"stop",
2149674Slinton /* O_TRACEON */		1,	null,		"traceon",
2159674Slinton /* O_TRACEOFF */	1,	null,		"traceoff",
21618226Slinton /* O_TYPERENAME */	2,	UNARY,		"type rename",
21716614Ssam /* O_RERUN */		0,	null,		"rerun",
21816614Ssam /* O_RETURN */		1,	null,		"return",
21916614Ssam /* O_UP */		1,	UNARY,		"up",
22016614Ssam /* O_DOWN */		1,	UNARY,		"down",
22118226Slinton /* O_CALLPROC */	2,	null,		"call",
22218226Slinton /* O_SEARCH */		2,	null,		"search",
22318226Slinton /* O_SET */		2,	null,		"set",
22418226Slinton /* O_UNSET */		1,	null,		"unset",
22518226Slinton /* O_UNALIAS */		1,	null,		"unalias",
2269674Slinton };
227