1: #
   2: /*
   3:  * pxp - Pascal execution profiler
   4:  *
   5:  * Bill Joy UCB
   6:  * Version 1.2 January 1979
   7:  */
   8: 
   9: #include "0.h"
  10: #include "tree.h"
  11: 
  12: extern  char *opnames[];
  13: 
  14: #define alph(c)     ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  15: /*
  16:  * Rvalue reformats an expression.
  17:  * Par is a flag indicating that the expression
  18:  * should be parenthesized if it is non-atomic.
  19:  */
  20: rvalue(r, par)
  21:     register int *r;
  22:     int par;
  23: {
  24:     register int *al;
  25:     register char *opname;
  26: 
  27:     if (r == NIL) {
  28:         ppid("{expr}");
  29:         return;
  30:     }
  31:     if (r[0] <= T_IN)
  32:         opname = opnames[r[0]];
  33:     switch (r[0]) {
  34:         case T_BINT:
  35:         case T_INT:
  36:         case T_FINT:
  37:             ppnumb(r[2]);
  38:             if (r[0] == T_BINT)
  39:                 ppsep("b");
  40:             return;
  41:         case T_NIL:
  42:             ppkw("nil");
  43:             return;
  44:         case T_FCALL:
  45:             funccod(r);
  46:             return;
  47:         case T_VAR:
  48:             lvalue(r);
  49:             return;
  50:         case T_CSET:
  51:             cset(r);
  52:             return;
  53:         case T_STRNG:
  54:             ppstr(r[2]);
  55:             return;
  56:     }
  57:     if (par)
  58:         ppbra("(");
  59:     switch (r[0]) {
  60:         default:
  61:             panic("rval");
  62:         case T_PLUS:
  63:         case T_MINUS:
  64:             ppop(r[0] == T_PLUS ? "+" : "-");
  65:             al = r[2];
  66:             rvalue(r[2], prec(al) < prec(r) || full);
  67:             break;
  68:         case T_NOT:
  69:             ppkw(opname);
  70:             ppspac();
  71:             rvalue(r[2], 1);
  72:             break;
  73:         case T_EQ:
  74:         case T_NE:
  75:         case T_GE:
  76:         case T_LE:
  77:         case T_GT:
  78:         case T_LT:
  79:             al = r[2];
  80:             rvalue(al, prec(al) <= prec(r) || full);
  81:             goto rest;
  82:         case T_AND:
  83:         case T_OR:
  84:         case T_MULT:
  85:         case T_ADD:
  86:         case T_SUB:
  87:         case T_DIVD:
  88:         case T_MOD:
  89:         case T_DIV:
  90:         case T_IN:
  91:             al = r[2];
  92:             rvalue(al, prec(al) < prec(r) || full);
  93: rest:
  94:             ppspac();
  95:             if (alph(opname[0]))
  96:                 ppkw(opname);
  97:             else
  98:                 ppop(opname);
  99:             ppspac();
 100:             al = r[3];
 101:             rvalue(al, prec(al) <= prec(r) || full);
 102:             break;
 103:     }
 104:     if (par)
 105:         ppket(")");
 106: }
 107: 
 108: /*
 109:  * Prec returns the precedence of an operator,
 110:  * with larger numbers indicating stronger binding.
 111:  * This is used to determine when parenthesization
 112:  * is needed on subexpressions.
 113:  */
 114: prec(r)
 115:     register int *r;
 116: {
 117: 
 118:     if (r == NIL)
 119:         return;
 120:     switch (r[0]) {
 121:         case T_NOT:
 122:             return (4);
 123:         case T_MULT:
 124:         case T_DIVD:
 125:         case T_DIV:
 126:         case T_MOD:
 127:         case T_AND:
 128:             return (3);
 129:         case T_PLUS:
 130:         case T_MINUS:
 131:             return (2);
 132:         case T_ADD:
 133:         case T_SUB:
 134:         case T_OR:
 135:             return (1);
 136:         default:
 137:             return (0);
 138:     }
 139: }

Defined functions

prec defined in line 114; used 8 times

Defined macros

alph defined in line 14; used 1 times
  • in line 95
Last modified: 1983-03-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 707
Valid CSS Valid XHTML 1.0 Strict