xref: /csrg-svn/old/dbx/operators.c (revision 38105)
121616Sdist /*
2*38105Sbostic  * Copyright (c) 1983 The Regents of the University of California.
3*38105Sbostic  * All rights reserved.
4*38105Sbostic  *
5*38105Sbostic  * Redistribution and use in source and binary forms are permitted
6*38105Sbostic  * provided that the above copyright notice and this paragraph are
7*38105Sbostic  * duplicated in all such forms and that any documentation,
8*38105Sbostic  * advertising materials, and other materials related to such
9*38105Sbostic  * distribution and use acknowledge that the software was developed
10*38105Sbostic  * by the University of California, Berkeley.  The name of the
11*38105Sbostic  * University may not be used to endorse or promote products derived
12*38105Sbostic  * from this software without specific prior written permission.
13*38105Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*38105Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*38105Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1621616Sdist  */
179674Slinton 
1821616Sdist #ifndef lint
19*38105Sbostic static char sccsid[] = "@(#)operators.c	5.2 (Berkeley) 05/23/89";
20*38105Sbostic #endif /* not lint */
219674Slinton 
229674Slinton /*
239674Slinton  * Tree node classes.
249674Slinton  */
259674Slinton 
269674Slinton #include "defs.h"
279674Slinton #include "operators.h"
289674Slinton 
299674Slinton #ifndef public
309674Slinton typedef struct {
319674Slinton     char numargs;
329674Slinton     char opflags;
339674Slinton     String opstring;
349674Slinton } Opinfo;
359674Slinton 
369674Slinton typedef enum {
379674Slinton     O_NOP,
3818226Slinton     O_NAME, O_SYM, O_LCON, O_CCON, O_FCON, O_SCON,
399674Slinton     O_RVAL, O_INDEX, O_INDIR, O_DOT,
409674Slinton     O_COMMA,
419674Slinton 
429674Slinton     O_ITOF, O_ADD, O_ADDF, O_SUB, O_SUBF, O_NEG, O_NEGF,
439674Slinton     O_MUL, O_MULF, O_DIVF, O_DIV, O_MOD,
449674Slinton 
459674Slinton     O_AND, O_OR,
469674Slinton 
479674Slinton     O_LT, O_LTF, O_LE, O_LEF, O_GT, O_GTF, O_GE, O_GEF,
489674Slinton     O_EQ, O_EQF, O_NE, O_NEF,
499674Slinton 
509674Slinton     O_ALIAS,		/* rename a command */
519674Slinton     O_ASSIGN,		/* assign a value to a program variable */
529674Slinton     O_CALL,		/* call a procedure in the program */
539674Slinton     O_CATCH,		/* catch a signal before program does */
549674Slinton     O_CHFILE,		/* change (or print) the current source file */
559674Slinton     O_CONT,		/* continue execution */
5612543Scsvaf     O_DEBUG,		/* invoke a dbx internal debugging routine */
579674Slinton     O_DELETE,		/* remove a trace/stop */
589674Slinton     O_DUMP,		/* dump out variables */
599674Slinton     O_EDIT,		/* edit a file (or function) */
609674Slinton     O_FUNC,		/* set the current function */
619674Slinton     O_GRIPE,		/* send mail to debugger support person */
629674Slinton     O_HELP,		/* print a synopsis of debugger commands */
639674Slinton     O_IGNORE,		/* let program catch signal */
649674Slinton     O_LIST,		/* list source lines */
659674Slinton     O_PRINT,		/* print the values of a list of expressions */
669674Slinton     O_PSYM,		/* print symbol information */
679674Slinton     O_RUN,		/* start up program */
689674Slinton     O_SKIP,		/* skip the current line */
699674Slinton     O_SOURCE,		/* read commands from a file */
709674Slinton     O_STATUS,		/* display currently active trace/stop's */
719674Slinton     O_STEP,		/* execute a single line */
729674Slinton     O_STOP,		/* stop on an event */
739674Slinton     O_STOPI,		/* stop on an event at an instruction boundary */
749674Slinton     O_TRACE,		/* trace something on an event */
759674Slinton     O_TRACEI,		/* trace at the instruction level */
769674Slinton     O_WHATIS,		/* print the declaration of a variable */
779674Slinton     O_WHERE,		/* print a stack trace */
789674Slinton     O_WHEREIS,		/* print all the symbols with the given name */
799674Slinton     O_WHICH,		/* print out full qualification of a symbol */
809674Slinton     O_EXAMINE,		/* examine program instructions/data */
819674Slinton 
829674Slinton     O_ADDEVENT,		/* add an event */
839674Slinton     O_ENDX,		/* end of program reached */
849674Slinton     O_IF,		/* if first arg is true, do commands in second arg */
859674Slinton     O_ONCE,		/* add a "one-time" event, delete when first reached */
869674Slinton     O_PRINTCALL,	/* print out the current procedure and its arguments */
879674Slinton     O_PRINTIFCHANGED,	/* print the value of the argument if it has changed */
889674Slinton     O_PRINTRTN,		/* print out the routine and value that just returned */
899674Slinton     O_PRINTSRCPOS,	/* print out the current source position */
9018226Slinton     O_PROCRTN,		/* call completed */
919674Slinton     O_QLINE,		/* filename, line number */
929674Slinton     O_STOPIFCHANGED,	/* stop if the value of the argument has changed */
939674Slinton     O_STOPX,		/* stop execution */
949674Slinton     O_TRACEON,		/* begin tracing source line, variable, or all lines */
959674Slinton     O_TRACEOFF,		/* end tracing source line, variable, or all lines */
969674Slinton 
9711166Slinton     O_TYPERENAME,	/* state the type of an expression */
9816614Ssam     O_RERUN,		/* re-run program with the same arguments as before */
9916614Ssam     O_RETURN,		/* continue execution until procedure returns */
10016614Ssam     O_UP,		/* move current function up the call stack */
10116614Ssam     O_DOWN,		/* move current function down the call stack */
10218226Slinton     O_CALLPROC,		/* call command */
10318226Slinton     O_SEARCH,		/* regular expression pattern search through source */
10418226Slinton     O_SET,		/* set a debugger variable */
10518226Slinton     O_UNSET,		/* unset a debugger variable */
10618226Slinton     O_UNALIAS,		/* remove an alias */
10711166Slinton 
1089674Slinton     O_LASTOP
1099674Slinton } Operator;
1109674Slinton 
1119674Slinton /*
1129674Slinton  * Operator flags and predicates.
1139674Slinton  */
1149674Slinton 
1159674Slinton #define null 0
1169674Slinton #define LEAF 01
1179674Slinton #define UNARY 02
1189674Slinton #define BINARY 04
1199674Slinton #define BOOL 010
1209674Slinton #define REALOP 020
1219674Slinton #define INTOP 040
1229674Slinton 
1239674Slinton #define isbitset(a, m)	((a&m) == m)
1249674Slinton #define isleaf(o)	isbitset(opinfo[ord(o)].opflags, LEAF)
1259674Slinton #define isunary(o)	isbitset(opinfo[ord(o)].opflags, UNARY)
1269674Slinton #define isbinary(o)	isbitset(opinfo[ord(o)].opflags, BINARY)
1279674Slinton #define isreal(o)	isbitset(opinfo[ord(o)].opflags, REALOP)
1289674Slinton #define isint(o)	isbitset(opinfo[ord(o)].opflags, INTOP)
1299674Slinton #define isboolean(o)	isbitset(opinfo[ord(o)].opflags, BOOL)
1309674Slinton 
1319674Slinton #define degree(o)	(opinfo[ord(o)].opflags&(LEAF|UNARY|BINARY))
1329674Slinton #define nargs(o)	(opinfo[ord(o)].numargs)
1339674Slinton 
1349674Slinton #endif
1359674Slinton 
1369674Slinton /*
1379674Slinton  * Operator information structure.
1389674Slinton  */
1399674Slinton 
1409674Slinton public Opinfo opinfo[] ={
1419674Slinton /* O_NOP */		0,	null,		0,
1429674Slinton /* O_NAME */		-1,	LEAF,		0,
1439674Slinton /* O_SYM */		-1,	LEAF,		0,
1449674Slinton /* O_LCON */		-1,	LEAF,		0,
14518226Slinton /* O_CCON */		-1,	LEAF,		0,
1469674Slinton /* O_FCON */		-1,	LEAF,		0,
1479674Slinton /* O_SCON */		-1,	LEAF,		0,
1489674Slinton /* O_RVAL */		1,	UNARY,		0,
14918226Slinton /* O_INDEX */		2,	null,		0,
1509674Slinton /* O_INDIR */		1,	UNARY,		"^",
1519674Slinton /* O_DOT */		2,	null,		".",
15218226Slinton /* O_COMMA */		2,	null,		",",
1539674Slinton /* O_ITOF */		1,	UNARY|INTOP,	0,
1549674Slinton /* O_ADD */		2,	BINARY|INTOP,	"+",
1559674Slinton /* O_ADDF */		2,	BINARY|REALOP,	"+",
1569674Slinton /* O_SUB */		2,	BINARY|INTOP,	"-",
1579674Slinton /* O_SUBF */		2,	BINARY|REALOP,	"-",
1589674Slinton /* O_NEG */		1,	UNARY|INTOP,	"-",
1599674Slinton /* O_NEGF */		1,	UNARY|REALOP,	"-",
1609674Slinton /* O_MUL */		2,	BINARY|INTOP,	"*",
1619674Slinton /* O_MULF */		2,	BINARY|REALOP,	"*",
1629674Slinton /* O_DIVF */		2,	BINARY|REALOP,	"/",
1639674Slinton /* O_DIV */		2,	BINARY|INTOP,	" div ",
1649674Slinton /* O_MOD */		2,	BINARY|INTOP,	" mod ",
1659674Slinton /* O_AND */		2,	BINARY|INTOP,	" and ",
1669674Slinton /* O_OR */		2,	BINARY|INTOP,	" or ",
1679674Slinton /* O_LT */		2,	BINARY|INTOP,	" < ",
1689674Slinton /* O_LTF */		2,	BINARY|REALOP,	" < ",
1699674Slinton /* O_LE */		2,	BINARY|INTOP,	" <= ",
1709674Slinton /* O_LEF */		2,	BINARY|REALOP,	" <= ",
1719674Slinton /* O_GT */		2,	BINARY|INTOP,	" > ",
1729674Slinton /* O_GTF */		2,	BINARY|REALOP,	" > ",
1739674Slinton /* O_GE */		2,	BINARY|INTOP,	" >= ",
1749674Slinton /* O_GEF */		2,	BINARY|REALOP,	" >= ",
1759674Slinton /* O_EQ */		2,	BINARY|INTOP,	" = ",
1769674Slinton /* O_EQF */		2,	BINARY|REALOP,	" = ",
1779674Slinton /* O_NE */		2,	BINARY|INTOP,	" <> ",
1789674Slinton /* O_NEF */		2,	BINARY|REALOP,	" <> ",
1799674Slinton 
1809674Slinton /* O_ALIAS */		2,	null,		"alias",
18118226Slinton /* O_ASSIGN */		2,	null,		" := ",
1829674Slinton /* O_CALL */		2,	null,		"call",
18318226Slinton /* O_CATCH */		0,	null,		"catch",
1849674Slinton /* O_CHFILE */		0,	null,		"file",
1859674Slinton /* O_CONT */		0,	null,		"cont",
18612543Scsvaf /* O_DEBUG */		0,	null,		"debug",
18716614Ssam /* O_DELETE */		1,	null,		"delete",
18818226Slinton /* O_DUMP */		1,	null,		"dump",
1899674Slinton /* O_EDIT */		0,	null,		"edit",
1909674Slinton /* O_FUNC */		1,	null,		"func",
1919674Slinton /* O_GRIPE */		0,	null,		"gripe",
1929674Slinton /* O_HELP */		0,	null,		"help",
19318226Slinton /* O_IGNORE */		0,	null,		"ignore",
1949674Slinton /* O_LIST */		2,	null,		"list",
1959674Slinton /* O_PRINT */		1,	null,		"print",
1969674Slinton /* O_PSYM */		1,	null,		"psym",
1979674Slinton /* O_RUN */		0,	null,		"run",
1989674Slinton /* O_SKIP */		0,	null,		"skip",
1999674Slinton /* O_SOURCE */		0,	null,		"source",
2009674Slinton /* O_STATUS */		0,	null,		"status",
2019674Slinton /* O_STEP */		0,	null,		"step",
2029674Slinton /* O_STOP */		3,	null,		"stop",
2039674Slinton /* O_STOPI */		3,	null,		"stopi",
2049674Slinton /* O_TRACE */		3,	null,		"trace",
2059674Slinton /* O_TRACEI */		3,	null,		"tracei",
2069674Slinton /* O_WHATIS */		1,	null,		"whatis",
2079674Slinton /* O_WHERE */		0,	null,		"where",
2089674Slinton /* O_WHEREIS */		1,	null,		"whereis",
2099674Slinton /* O_WHICH */		1,	null,		"which",
2109674Slinton /* O_EXAMINE */		0,	null,		"examine",
2119674Slinton 
2129674Slinton /* O_ADDEVENT */	0,	null,		"when",
2139674Slinton /* O_ENDX */		0,	null,		nil,
2149674Slinton /* O_IF */		0,	null,		"if",
2159674Slinton /* O_ONCE */		0,	null,		"once",
2169674Slinton /* O_PRINTCALL */	1,	null,		"printcall",
2179674Slinton /* O_PRINTIFCHANGED */	1,	null,		"printifchanged",
2189674Slinton /* O_PRINTRTN */	1,	null,		"printrtn",
2199674Slinton /* O_PRINTSRCPOS */	1,	null,		"printsrcpos",
2209674Slinton /* O_PROCRTN */		1,	null,		"procrtn",
2219674Slinton /* O_QLINE */		2,	null,		nil,
2229674Slinton /* O_STOPIFCHANGED */	1,	null,		"stopifchanged",
2239674Slinton /* O_STOPX */		0,	null,		"stop",
2249674Slinton /* O_TRACEON */		1,	null,		"traceon",
2259674Slinton /* O_TRACEOFF */	1,	null,		"traceoff",
22618226Slinton /* O_TYPERENAME */	2,	UNARY,		"type rename",
22716614Ssam /* O_RERUN */		0,	null,		"rerun",
22816614Ssam /* O_RETURN */		1,	null,		"return",
22916614Ssam /* O_UP */		1,	UNARY,		"up",
23016614Ssam /* O_DOWN */		1,	UNARY,		"down",
23118226Slinton /* O_CALLPROC */	2,	null,		"call",
23218226Slinton /* O_SEARCH */		2,	null,		"search",
23318226Slinton /* O_SET */		2,	null,		"set",
23418226Slinton /* O_UNSET */		1,	null,		"unset",
23518226Slinton /* O_UNALIAS */		1,	null,		"unalias",
2369674Slinton };
237