1 2 package SOFA.SOFAnode.Made.CDL; 3 import java.rmi.RemoteException ; 4 5 import SOFA.SOFAnode.Made.TIR.CDLRepository; 6 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 7 import SOFA.SOFAnode.Made.TIR.Repository; 8 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 9 10 class CompExprBinOper extends CompExprOper { 11 public CompExprOper operand1; 12 public CompExprOper operand2; 13 public CompExprBinOper(int type, CompExprOper op1, CompExprOper op2) { 14 super(type); 15 operand1 = op1; 16 operand2 = op2; 17 } 18 19 public int type() { 20 if (operand1.type()==CompExprKind.e_all) 21 return operand2.type(); 22 else 23 return operand1.type(); 24 } 25 26 public boolean isProp() { return (operand1.isProp() || operand2.isProp()); } 27 28 public EnumList nameProp(CompRepository rep) throws CDLExceptRemote, CDLExceptLock { 29 EnumList l1 = operand1.nameProp(rep); 30 EnumList l2 = operand2.nameProp(rep); 31 l2.toFirst(); 32 for (int i=0;i<l2.size();i++) { 33 l1.addName((String ) l2.aktual()); 34 l2.toNext(); 35 } 36 return l1; 37 } 38 39 public String toString() { 40 StringBuffer sb = new StringBuffer ("("); 41 sb.append(operand1.toString()); 42 switch (kind) { 43 case CompExprKind.e_or: 44 sb.append("|"); 45 break; 46 case CompExprKind.e_xor: 47 sb.append("^"); 48 break; 49 case CompExprKind.e_and: 50 sb.append("&"); 51 break; 52 case CompExprKind.e_shr: 53 sb.append(">>"); 54 break; 55 case CompExprKind.e_shl: 56 sb.append("<<"); 57 break; 58 case CompExprKind.e_plus: 59 sb.append("+"); 60 break; 61 case CompExprKind.e_minus: 62 sb.append("-"); 63 break; 64 case CompExprKind.e_mul: 65 sb.append("*"); 66 break; 67 case CompExprKind.e_div: 68 sb.append("/"); 69 break; 70 case CompExprKind.e_mod: 71 sb.append("%"); 72 break; 73 } 74 sb.append(operand2.toString()); 75 sb.append(")"); 76 return sb.toString(); 77 } 78 79 public ExprOperDef toNormal(CDLRepository rep) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock { 80 try { 81 return ((Repository) rep.get_containing_repository()).create_exprbinoperation(kind, operand1.toNormal(rep), operand2.toNormal(rep)); 82 } catch (RemoteException e) { 83 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 84 } catch (TIRExceptCreate ecr) { 85 throw new CDLExceptToNormal("Can't create expression"); 86 } 87 } 88 89 public static boolean isCompatible(int operand, CompExprOper e1, CompExprOper e2) { 90 switch (operand) { 91 case CompExprKind.e_mul: 92 case CompExprKind.e_div: 93 case CompExprKind.e_plus: 94 case CompExprKind.e_minus: 95 switch (e1.type()) { 96 case CompExprKind.e_int: 97 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_int)) 98 return true; 99 break; 100 case CompExprKind.e_float: 101 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_float)) 102 return true; 103 break; 104 case CompExprKind.e_fixed: 105 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_fixed)) 106 return true; 107 break; 108 case CompExprKind.e_all: 109 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_fixed) || 110 (e2.type() == CompExprKind.e_int) || (e2.type() == CompExprKind.e_float)) 111 return true; 112 break; 113 } 114 return false; 115 case CompExprKind.e_and: 116 case CompExprKind.e_xor: 117 case CompExprKind.e_or: 118 case CompExprKind.e_shl: 119 case CompExprKind.e_shr: 120 case CompExprKind.e_mod: 121 switch (e1.type()) { 122 case CompExprKind.e_int: 123 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_int)) 124 return true; 125 break; 126 case CompExprKind.e_all: 127 if ((e2.type() == CompExprKind.e_all) || (e2.type() == CompExprKind.e_int)) 128 return true; 129 break; 130 } 131 return false; 132 default: return false; 133 } 134 } 135 } 136 | Popular Tags |