1 28 29 package com.caucho.es.parser; 30 31 import com.caucho.es.ESException; 32 33 import java.io.IOException ; 34 35 38 class UnaryExpr extends Expr { 39 Expr term; 40 int op; 41 42 UnaryExpr(Block block, Expr term, int op) 43 { 44 super(block); 45 46 this.term = term; 47 this.op = op; 48 49 if (term != null) 50 term.setUsed(); 51 } 52 53 void exprStatement(Function fun) throws ESException 54 { 55 if (op == 'v') { 56 fun.addExpr(this); 57 isTop = true; 58 } 59 else 60 term.exprStatement(fun); 61 } 62 63 int getType() 64 { 65 switch (op) { 66 case '~': 67 return TYPE_INTEGER; 68 69 case '-': 70 case '+': 71 if (term.getType() == TYPE_INTEGER) 72 return TYPE_INTEGER; 73 else 74 return TYPE_NUMBER; 75 76 case '!': 77 return TYPE_BOOLEAN; 78 79 case 't': 80 case 'v': 81 return TYPE_ES; 82 83 default: 84 return TYPE_ES; 85 } 86 } 87 88 void printBooleanImpl() throws IOException 89 { 90 switch (op) { 91 case '!': 92 cl.print("(!"); 93 term.printBoolean(); 94 cl.print(")"); 95 break; 96 97 default: 98 throw new IOException ("foo"); 99 } 100 } 101 102 void printInt32Impl() throws IOException 103 { 104 switch (op) { 105 case '~': 106 cl.print("(~"); 107 term.printInt32(); 108 cl.print(")"); 109 break; 110 111 case '-': 112 cl.print("(-"); 113 term.printInt32(); 114 cl.print(")"); 115 break; 116 117 case '+': 118 cl.print("("); 119 term.printInt32(); 120 cl.print(")"); 121 break; 122 123 default: 124 throw new IOException ("foo"); 125 } 126 } 127 128 void printNumImpl() throws IOException 129 { 130 switch (op) { 131 case '-': 132 cl.print("(-"); 133 term.printNum(); 134 cl.print(")"); 135 break; 136 137 case '+': 138 cl.print("("); 139 term.printNum(); 140 cl.print(")"); 141 break; 142 143 default: 144 throw new IOException ("foo"); 145 } 146 } 147 148 void printImpl() throws IOException 149 { 150 switch (op) { 151 case 't': 152 term.print(); 153 cl.print(".typeof()"); 154 break; 155 156 case 'v': 157 cl.print("_env.doVoid("); 158 term.print(); 159 cl.print(")"); 160 break; 161 162 default: 163 throw new IOException ("foo"); 164 } 165 } 166 } 167 | Popular Tags |