| 2392 | } |
| 2393 | |
| 2394 | static class NumberExpr extends LiteralExpr implements MaybePrimitiveExpr{ |
| 2395 | final Number n; |
| 2396 | public final int id; |
| 2397 | |
| 2398 | public NumberExpr(Number n){ |
| 2399 | this.n = n; |
| 2400 | this.id = registerConstant(n); |
| 2401 | } |
| 2402 | |
| 2403 | Object val(){ |
| 2404 | return n; |
| 2405 | } |
| 2406 | |
| 2407 | public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ |
| 2408 | if(context != C.STATEMENT) |
| 2409 | { |
| 2410 | objx.emitConstant(gen, id); |
| 2411 | // emitUnboxed(context,objx,gen); |
| 2412 | // HostExpr.emitBoxReturn(objx,gen,getJavaClass()); |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | public boolean hasJavaClass() { |
| 2417 | return true; |
| 2418 | } |
| 2419 | |
| 2420 | public Class getJavaClass(){ |
| 2421 | if(n instanceof Integer) |
| 2422 | return long.class; |
| 2423 | else if(n instanceof Double) |
| 2424 | return double.class; |
| 2425 | else if(n instanceof Long) |
| 2426 | return long.class; |
| 2427 | else |
| 2428 | throw new IllegalStateException("Unsupported Number type: " + n.getClass().getName()); |
| 2429 | } |
| 2430 | |
| 2431 | public boolean canEmitPrimitive(){ |
| 2432 | return true; |
| 2433 | } |
| 2434 | |
| 2435 | public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ |
| 2436 | if(n instanceof Integer) |
| 2437 | gen.push(n.longValue()); |
| 2438 | else if(n instanceof Double) |
| 2439 | gen.push(n.doubleValue()); |
| 2440 | else if(n instanceof Long) |
| 2441 | gen.push(n.longValue()); |
| 2442 | } |
| 2443 | |
| 2444 | static public Expr parse(Number form){ |
| 2445 | if(form instanceof Integer |
| 2446 | || form instanceof Double |
| 2447 | || form instanceof Long) |
| 2448 | return new NumberExpr(form); |
| 2449 | else |
| 2450 | return new ConstantExpr(form); |
| 2451 | } |
nothing calls this directly
no outgoing calls
no test coverage detected