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 PostfixExpr extends Expr { 39 final static int PREINC = 'i'; 40 final static int PREDEC = 'd'; 41 final static int POSTINC = 'I'; 42 final static int POSTDEC = 'D'; 43 44 private int code; 45 private FieldExpr field; 46 private IdExpr id; 47 48 private AssignExpr cheat; 49 50 PostfixExpr(Block block, int code, FieldExpr field) 51 { 52 super(block); 53 54 this.code = code; 55 this.field = field; 56 57 if (field != null) 58 field.setUsed(); 59 } 60 61 PostfixExpr(Block block, int code, IdExpr id) 62 { 63 super(block); 64 65 this.code = code; 66 this.id = id; 67 68 if (id != null) 69 id.setUsed(); 70 } 71 72 int getType() 73 { 74 if (id == null || ! id.isLocal()) 75 return TYPE_NUMBER; 76 else if (id.getType() == TYPE_INTEGER) 77 return TYPE_INTEGER; 78 else if (id.getType() == TYPE_NUMBER) 79 return TYPE_NUMBER; 80 else 81 return TYPE_ES; 82 } 83 84 void exprStatement(Function fun) throws ESException 85 { 86 setTop(); 87 fun.addExpr(this); 88 } 89 90 void printInt32Impl() throws IOException 91 { 92 switch (code) { 93 case PREINC: 94 if (! noValue) 95 cl.print("("); 96 cl.print(id.getId()); 97 cl.print(" = "); 98 id.printInt32(); 99 cl.print(" + 1"); 100 if (! noValue) 101 cl.print(")"); 102 return; 103 case PREDEC: 104 if (! noValue) 105 cl.print("("); 106 cl.print(id.getId()); 107 cl.print(" = "); 108 id.printInt32(); 109 cl.print(" - 1"); 110 if (! noValue) 111 cl.print(")"); 112 return; 113 case POSTINC: 114 if (! noValue) { 115 cl.print("_env._first("); 116 id.printInt32(); 117 cl.print(", "); 118 } 119 cl.print(id.getId()); 120 cl.print(" = "); 121 id.printInt32(); 122 cl.print(" + 1"); 123 if (! noValue) 124 cl.print(")"); 125 return; 126 case POSTDEC: 127 if (! noValue) { 128 cl.print("_env._first("); 129 id.printInt32(); 130 cl.print(", "); 131 } 132 cl.print(id.getId()); 133 cl.print(" = "); 134 id.printInt32(); 135 cl.print(" - 1"); 136 if (! noValue) 137 cl.print(")"); 138 return; 139 } 140 } 141 142 void printNumImpl() throws IOException 143 { 144 if (id != null && id.isLocal()) { 145 switch (code) { 146 case PREINC: 147 if (! noValue) 148 cl.print("("); 149 cl.print(id.getId()); 150 cl.print(" = "); 151 id.printNum(); 152 cl.print(" + 1"); 153 if (! noValue) 154 cl.print(")"); 155 return; 156 case PREDEC: 157 if (! noValue) 158 cl.print("("); 159 cl.print(id.getId()); 160 cl.print(" = "); 161 id.printNum(); 162 cl.print(" - 1"); 163 if (! noValue) 164 cl.print(")"); 165 return; 166 case POSTINC: 167 if (! noValue) { 168 cl.print("_env._first("); 169 id.printNum(); 170 cl.print(", "); 171 } 172 cl.print(id.getId()); 173 cl.print(" = "); 174 id.printNum(); 175 cl.print(" + 1"); 176 if (! noValue) 177 cl.print(")"); 178 return; 179 case POSTDEC: 180 if (! noValue) { 181 cl.print("_env._first("); 182 id.printNum(); 183 cl.print(", "); 184 } 185 cl.print(id.getId()); 186 cl.print(" = "); 187 id.printNum(); 188 cl.print(" - 1"); 189 if (! noValue) 190 cl.print(")"); 191 return; 192 } 193 } 194 195 switch (code) { 196 case PREINC: 197 case PREDEC: 198 cl.print("_env._pre("); 199 break; 200 201 case POSTINC: 202 case POSTDEC: 203 cl.print("_env._post("); 204 break; 205 } 206 207 if (field != null) { 208 field.getExpr().print(); 209 cl.print(", "); 210 field.getField().printStr(); 211 } else if (function.isGlobalScope()) { 212 cl.print("_env.global, "); 213 printLiteral(id.getId()); 214 } else { 215 printLiteral(id.getId()); 216 } 217 218 if (code == PREINC || code == POSTINC) 219 cl.print(", 1)"); 220 else 221 cl.print(", -1)"); 222 } 223 224 void printImpl() throws IOException 225 { 226 switch (code) { 227 case PREINC: 228 if (! noValue) 229 cl.print("("); 230 cl.print(id.getId()); 231 cl.print(" = ESNumber.create("); 232 id.printNum(); 233 cl.print(" + 1)"); 234 if (! noValue) 235 cl.print(")"); 236 return; 237 case PREDEC: 238 if (! noValue) 239 cl.print(")"); 240 cl.print(id.getId()); 241 cl.print(" = ESNumber.create("); 242 id.printNum(); 243 cl.print(" - 1)"); 244 if (! noValue) 245 cl.print(")"); 246 return; 247 case POSTINC: 248 if (! noValue) { 249 cl.print("_env._first("); 250 id.print(); 251 cl.print(", "); 252 } 253 cl.print(id.getId()); 254 cl.print(" = ESNumber.create("); 255 id.printNum(); 256 cl.print(" + 1)"); 257 if (! noValue) 258 cl.print(")"); 259 return; 260 case POSTDEC: 261 if (! noValue) { 262 cl.print("_env._first("); 263 id.print(); 264 cl.print(", "); 265 } 266 cl.print(id.getId()); 267 cl.print(" = ESNumber.create("); 268 id.printNum(); 269 cl.print(" - 1)"); 270 if (! noValue) 271 cl.print(")"); 272 return; 273 } 274 return; 275 } 276 } 277 | Popular Tags |