1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 29 import org.aspectj.compiler.base.bcg.FieldBuilder; 30 import org.aspectj.compiler.base.bcg.CodeBuilder; 31 import org.aspectj.compiler.base.bcg.Label; 32 33 37 public class IntLiteralExpr extends NumericLiteralExpr { 38 39 public long getLongValue() { return (long)intValue; } 40 public float getFloatValue() { return (float)intValue; } 41 public double getDoubleValue() { return (double)intValue; } 42 public String getStringValue() { 43 if (getType() instanceof CharType) 44 return "" + (char) intValue; 45 else 46 return "" + intValue; 47 } 48 49 public IntLiteralExpr(SourceLocation source, int _intValue) { 50 this(source, source.getCompiler().getTypeManager().intType, "" + _intValue, _intValue); 51 } 52 53 public IntLiteralExpr(SourceLocation source, Type type, int _intValue) { 54 this(source, type, createUsefulString(type, _intValue), _intValue); 55 } 56 57 private static String createUsefulString(Type type, int i) { 58 if (type instanceof IntType) return "" + i; 59 return "((" + type.getString() + ")" + i + ")"; 60 } 61 62 public boolean isAssignableTo(Type type) { 63 if (type instanceof ByteType) { 64 return (Byte.MIN_VALUE <= intValue) && (intValue <= Byte.MAX_VALUE); 65 } else if (type instanceof ShortType) { 66 return (Short.MIN_VALUE <= intValue) && (intValue <= Short.MAX_VALUE); 67 } else if (type instanceof CharType) { 68 return (Character.MIN_VALUE <= intValue) && (intValue <= Character.MAX_VALUE); 69 } else if (type instanceof NumericType) { 70 return true; 71 } else { 72 return false; 73 } 74 } 75 76 protected void cgValue(CodeBuilder cb) { 79 cb.emitIntConstant(intValue); 80 } 81 public void addConstant(FieldBuilder fb) { 82 fb.setConstantValue(intValue); 83 } 84 public boolean isConstantZero() { return intValue == 0; } 85 86 protected int intValue; 88 public int getIntValue() { return intValue; } 89 public void setIntValue(int _intValue) { intValue = _intValue; } 90 91 public IntLiteralExpr(SourceLocation location, Type _type, String _value, int _intValue) { 92 super(location, _type, _value); 93 setIntValue(_intValue); 94 } 95 protected IntLiteralExpr(SourceLocation source) { 96 super(source); 97 } 98 99 public ASTObject copyWalk(CopyWalker walker) { 100 IntLiteralExpr ret = new IntLiteralExpr(getSourceLocation()); 101 ret.preCopy(walker, this); 102 ret.type = type; 103 ret.value = value; 104 ret.intValue = intValue; 105 return ret; 106 } 107 108 109 public String getDefaultDisplayName() { 110 return "IntLiteralExpr(type: "+type+", "+"value: "+value+", "+"intValue: "+intValue+")"; 111 } 112 113 } 115 | Popular Tags |