1 package polyglot.ext.jl.ast; 2 3 import polyglot.ast.*; 4 import polyglot.types.*; 5 import polyglot.visit.*; 6 import polyglot.util.*; 7 8 12 public class IntLit_c extends NumLit_c implements IntLit 13 { 14 15 protected Kind kind; 16 17 public IntLit_c(Position pos, Kind kind, long value) { 18 super(pos, value); 19 this.kind = kind; 20 } 21 22 26 public boolean boundary() { 27 return (kind == INT && (int) value == Integer.MIN_VALUE) 28 || (kind == LONG && value == Long.MIN_VALUE); 29 } 30 31 32 public long value() { 33 return longValue(); 34 } 35 36 37 public IntLit value(long value) { 38 IntLit_c n = (IntLit_c) copy(); 39 n.value = value; 40 return n; 41 } 42 43 44 public IntLit.Kind kind() { 45 return kind; 46 } 47 48 49 public IntLit kind(IntLit.Kind kind) { 50 IntLit_c n = (IntLit_c) copy(); 51 n.kind = kind; 52 return n; 53 } 54 55 56 public Node typeCheck(TypeChecker tc) throws SemanticException { 57 TypeSystem ts = tc.typeSystem(); 58 59 Kind kind = kind(); 60 61 if (kind == INT) { 62 return type(ts.Int()); 63 } 64 else if (kind == LONG) { 65 return type(ts.Long()); 66 } 67 else { 68 throw new InternalCompilerError("Unrecognized IntLit kind " + kind); 69 } 70 } 71 72 public String positiveToString() { 73 if (kind() == LONG) { 74 if (boundary()) { 75 return "9223372036854775808L"; 77 } 78 else { 79 return Long.toString(value) + "L"; 80 } 81 } 82 else { 83 if (boundary()) { 84 return "2147483648"; 86 } 87 else { 88 return Long.toString(value); 89 } 90 } 91 } 92 93 public String toString() { 94 if (kind() == LONG) { 95 return Long.toString(value) + "L"; 96 } 97 else { 98 return Long.toString(value); 99 } 100 } 101 102 public void prettyPrint(CodeWriter w, PrettyPrinter tr) { 103 w.write(toString()); 104 } 105 106 public Object constantValue() { 107 if (kind() == LONG) { 108 return new Long (value); 109 } 110 else { 111 return new Integer ((int) value); 112 } 113 } 114 115 public Precedence precedence() { 116 if (value < 0L && ! boundary()) { 117 return Precedence.UNARY; 118 } 119 else { 120 return Precedence.LITERAL; 121 } 122 } 123 } 124 | Popular Tags |