1 29 30 package com.caucho.quercus.expr; 31 32 import com.caucho.quercus.Location; 33 import com.caucho.quercus.env.Env; 34 import com.caucho.quercus.env.Value; 35 import com.caucho.quercus.parser.QuercusParser; 36 import com.caucho.quercus.program.Statement; 37 import com.caucho.util.L10N; 38 39 import java.io.IOException ; 40 import java.util.logging.Logger ; 41 42 45 abstract public class Expr { 46 private static final L10N L = new L10N(Expr.class); 47 private static final Logger log = Logger.getLogger(Expr.class.getName()); 48 49 public static final int COMPILE_ARG_MAX = 5; 50 51 private final Location _location; 52 53 public Expr(Location location) 54 { 55 _location = location; 56 } 57 58 public Expr() 59 { 60 _location = Location.UNKNOWN; 61 } 62 63 66 final public Location getLocation() 67 { 68 return _location; 69 } 70 71 74 public String getFileName() 75 { 76 if (_location != Location.UNKNOWN) 77 return _location.getFileName(); 78 else 79 return null; 80 } 81 82 85 public int getLine() 86 { 87 return _location.getLineNumber(); 88 } 89 90 93 public String getFunctionLocation() 94 { 95 return ""; 96 } 97 98 101 public String getLocationLine() 102 { 103 if (_location != Location.UNKNOWN) 104 return _location.getFileName() + ":" + getLine() + ": "; 105 else 106 return ""; 107 } 108 109 112 public boolean isRef() 113 { 114 return false; 115 } 116 117 120 public boolean isConstant() 121 { 122 return isLiteral(); 123 } 124 125 128 public boolean isLiteral() 129 { 130 return false; 131 } 132 133 136 public boolean isTrue() 137 { 138 return false; 139 } 140 141 144 public boolean isFalse() 145 { 146 return false; 147 } 148 149 152 public boolean canRead() 153 { 154 return true; 155 } 156 157 public Expr createAssign(QuercusParser parser, Expr value) 158 throws IOException 159 { 160 String msg = (L.l("{0} is an invalid left-hand side of an assignment.", 161 this)); 162 163 if (parser != null) 164 throw parser.error(msg); 165 else 166 throw new IOException (msg); 167 } 168 169 172 public void assign(QuercusParser parser) 173 throws IOException 174 { 175 String msg = L.l("{0} is an invalid left-hand side of an assignment.", 176 this); 177 178 if (parser != null) 179 throw parser.error(msg); 180 else 181 throw new IOException (msg); 182 } 183 184 public Expr createAssignRef(QuercusParser parser, Expr value) 185 throws IOException 186 { 187 String msg = L.l("{0} is an invalid left-hand side of an assignment.", 189 this); 190 191 if (parser != null) 192 throw parser.error(msg); 193 else 194 throw new IOException (msg); 195 } 196 197 201 public Expr createRef(QuercusParser parser) 202 throws IOException 203 { 204 return this; 205 } 206 207 public Expr createDeref(ExprFactory factory) 208 throws IOException 209 { 210 return this; 211 } 212 213 217 public Expr createCopy(ExprFactory factory) 218 { 219 return this; 220 } 221 222 226 232 233 236 public Expr createFieldGet(ExprFactory factory, String name) 237 { 238 return factory.createFieldGet(this, name); 239 } 240 241 244 public Expr createFieldGet(ExprFactory factory, Expr name) 245 { 246 return factory.createFieldVarGet(this, name); 247 } 248 249 252 public Statement createUnset(ExprFactory factory, Location location) 253 throws IOException 254 { 255 throw new IOException (L.l("{0} is an illegal value to unset", 256 this)); 257 } 258 259 262 public Expr createIsset(ExprFactory factory) 263 throws IOException 264 { 265 throw new IOException (L.l("{0} is an illegal value to isset", 266 this)); 267 } 268 269 272 public boolean isBoolean() 273 { 274 return false; 275 } 276 277 280 public boolean isLong() 281 { 282 return false; 283 } 284 285 288 public boolean isDouble() 289 { 290 return false; 291 } 292 293 296 public boolean isNumber() 297 { 298 return isLong() || isDouble(); 299 } 300 301 304 public boolean isString() 305 { 306 return false; 307 } 308 309 314 public Value evalConstant() 315 throws IOException 316 { 317 throw new IOException (L.l("{0} is not a constant expression", this)); 318 } 319 320 327 abstract public Value eval(Env env); 328 329 337 public Value evalDirty(Env env) 338 { 339 return eval(env); 340 } 341 342 349 public Value evalArray(Env env) 350 { 351 return eval(env); 352 } 353 354 361 public Value evalObject(Env env) 362 { 363 return eval(env); 364 } 365 366 373 public Value evalRef(Env env) 374 { 375 return eval(env); 376 } 377 378 385 public Value evalCopy(Env env) 386 { 387 return eval(env); 388 } 389 390 398 public Value evalArg(Env env) 399 { 400 return eval(env); 401 } 402 403 406 public void evalAssign(Env env, Value value) 407 { 408 throw new RuntimeException (L.l("{0} is an invalid left-hand side of an assignment.", 409 this)); 410 } 411 412 419 public String evalString(Env env) 420 { 421 return eval(env).toString(); 422 } 423 424 431 public char evalChar(Env env) 432 { 433 return eval(env).toChar(); 434 } 435 436 443 public boolean evalBoolean(Env env) 444 { 445 return eval(env).toBoolean(); 446 } 447 448 455 public long evalLong(Env env) 456 { 457 return eval(env).toLong(); 458 } 459 460 467 public double evalDouble(Env env) 468 { 469 return eval(env).toDouble(); 470 } 471 472 475 public void print(Env env) 476 throws IOException 477 { 478 eval(env).print(env); 479 } 480 481 public String toString() 482 { 483 return "Expr[]"; 484 } 485 } 486 487 | Popular Tags |