1 23 package org.objectweb.medor.expression.type; 24 25 import org.objectweb.jorm.type.api.PType; 26 import org.objectweb.medor.expression.api.TypingException; 27 28 31 public class ExpressionTypeHelper { 32 37 public static final boolean isArithmeticType(PType t) { 38 switch (t.getTypeCode()) { 39 case PType.TYPECODE_BYTE: 40 return true; 41 case PType.TYPECODE_SHORT: 42 return true; 43 case PType.TYPECODE_INT: 44 return true; 45 case PType.TYPECODE_LONG: 46 return true; 47 case PType.TYPECODE_FLOAT: 48 return true; 49 case PType.TYPECODE_DOUBLE: 50 return true; 51 default: 52 return false; 53 } 54 } 55 56 64 public static PType getResultType(PType type1, PType type2) 65 throws TypingException { 66 if (type1.isa(type2)) { 67 return type2; 68 } 69 else if (type2.isa(type1)) { 70 return type1; 71 } 72 else { 73 throw new TypingException("Incompatible types"); 74 } 75 } 76 } 77 | Popular Tags |