Binary operator: Left op Right
Inheritance: Expr
Exemple #1
0
 public BinaryExp(Exp left, Exp right, BinaryOp op)
 {
     Debug.Assert(left != null);
     Debug.Assert(right != null);
     
     //m_filerange = FileRange.Merge(left.Location, right.Location);
     
     m_left = left;
     m_right = right;
     m_op = op;
 }
Exemple #2
0
 // Return true if our param types let us match a predefined operator.
 // Else return false (which implies that we must match against an 
 // overloaded operator)
 // @todo - combine w/ CalcCLRTypeHelper()
 static public bool MatchesPredefinedOp(BinaryOp op, Type clrLeft, Type clrRight)
 {
     // For arithmetic ops, only predefined if both args are numbers
     if (op == BinaryOp.cAdd || op == BinaryOp.cMul || op == BinaryOp.cSub || 
         op == BinaryOp.cDiv || op == BinaryOp.cMod ||
         op == BinaryOp.cShiftLeft || op == BinaryOp.cShiftRight)
     {
         return IsNumber(clrLeft) && IsNumber(clrRight);                
     }
     
     if (op == BinaryOp.cEqu || op == BinaryOp.cNeq)
     {
         if (IsNumber(clrLeft) && IsNumber(clrRight)) 
             return true;
         if (IsBool(clrLeft) && IsBool(clrRight))
             return true;
         if (IsEnum(clrLeft) && IsEnum(clrRight))
             return true;                
         return false;                
     }
     
     // Bitwise operators work on either bool or integers
     if (op == BinaryOp.cBitwiseAnd || op == BinaryOp.cBitwiseOr || op == BinaryOp.cBitwiseXor)
     {
         if (IsInteger(clrLeft) && IsInteger(clrRight)) 
             return true;
         if (IsBool(clrLeft) && IsBool(clrRight))
             return true;
         if (IsEnum(clrLeft) && IsEnum(clrRight)) // @todo -only if flags attribute specified
             return true;                
         return false;  
     }
             
     // Relational ops only work on ints
     if (op == BinaryOp.cLT || op == BinaryOp.cGT ||
         op == BinaryOp.cLE || op == BinaryOp.cGE)
     {
         if (IsNumber(clrLeft) && IsNumber(clrRight))
             return true;
         if (IsEnum(clrLeft) && IsEnum(clrRight))
             return true;                
     }
     
     // These ops can't be overloaded, so they had better
     // match a default type
     if (op == BinaryOp.cAnd || op == BinaryOp.cOr)
     {
         return true;        
     }
     
     return false;
 }
Exemple #3
0
 public static string OpName(BinaryOp op)
 {
     return m_ops[(int) op];
 }