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 abstract class Expr_c extends Term_c implements Expr 13 { 14 protected Type type; 15 16 public Expr_c(Position pos) { 17 super(pos); 18 } 19 20 25 public Type type() { 26 return this.type; 27 } 28 29 30 public Expr type(Type type) { 31 if (type == this.type) return this; 32 Expr_c n = (Expr_c) copy(); 33 n.type = type; 34 return n; 35 } 36 37 public void dump(CodeWriter w) { 38 super.dump(w); 39 40 if (type != null) { 41 w.allowBreak(4, " "); 42 w.begin(0); 43 w.write("(type " + type + ")"); 44 w.end(); 45 } 46 } 47 48 49 public Precedence precedence() { 50 return Precedence.UNKNOWN; 51 } 52 53 public boolean isConstant() { 54 return false; 55 } 56 57 public Object constantValue() { 58 return null; 59 } 60 61 public String stringValue() { 62 return (String ) constantValue(); 63 } 64 65 public boolean booleanValue() { 66 return ((Boolean ) constantValue()).booleanValue(); 67 } 68 69 public byte byteValue() { 70 return ((Byte ) constantValue()).byteValue(); 71 } 72 73 public short shortValue() { 74 return ((Short ) constantValue()).shortValue(); 75 } 76 77 public char charValue() { 78 return ((Character ) constantValue()).charValue(); 79 } 80 81 public int intValue() { 82 return ((Integer ) constantValue()).intValue(); 83 } 84 85 public long longValue() { 86 return ((Long ) constantValue()).longValue(); 87 } 88 89 public float floatValue() { 90 return ((Float ) constantValue()).floatValue(); 91 } 92 93 public double doubleValue() { 94 return ((Double ) constantValue()).doubleValue(); 95 } 96 97 public Node buildTypes(TypeBuilder tb) throws SemanticException { 98 return type(tb.typeSystem().unknownType(position())); 99 } 100 101 113 public void printSubExpr(Expr expr, CodeWriter w, PrettyPrinter pp) { 114 printSubExpr(expr, true, w, pp); 115 } 116 117 132 public void printSubExpr(Expr expr, boolean associative, 133 CodeWriter w, PrettyPrinter pp) { 134 if (! associative && precedence().equals(expr.precedence()) || 135 precedence().isTighter(expr.precedence())) { 136 w.write("("); 137 printBlock(expr, w, pp); 138 w.write( ")"); 139 } 140 else { 141 printBlock(expr, w, pp); 142 } 143 } 144 } 145 | Popular Tags |