예제 #1
0
        ///
        /// <summary>
        ///		Parses bitwise expressions
        /// </summary>
        ///
        /// <param name="leftOp">Left operand</param>
        /// <param name="rightOp">Right operand</param>
        /// <param name="type">Bitwise expression type</param>
        ///
        /// <returns>The result of applying the given bitwise operand</returns>
        ///
        public static CseObject Parse(CseObject leftOp, CseObject rightOp, BitwiseType type)
        {
            CseObject obj = null;

            if (type == BitwiseType.NOT)
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral
                };
            }
            else
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral
                };
            }

            try {
                switch (type)
                {
                case BitwiseType.AND:
                    obj.Value = leftOp.Value & rightOp.Value;
                    break;

                case BitwiseType.OR:
                    obj.Value = leftOp.Value | rightOp.Value;
                    break;

                case BitwiseType.NOT:
                    obj.Value = ~leftOp.Value;
                    break;

                case BitwiseType.SHL:
                    obj.Value = leftOp.Value << rightOp.Value;
                    break;

                case BitwiseType.SHR:
                    obj.Value = leftOp.Value >> rightOp.Value;
                    break;

                default:
                    throw new System.NotImplementedException("Not implemented.");
                }
            }
            catch {
                // TODO: Fill this out!
            }

            return(obj);
        }
예제 #2
0
        public static string GetOperatorCode(string left, string right, BitwiseType operatorType)
        {
            switch (operatorType)
            {
            case BitwiseType.And:
                return(left + " & " + right);

            case BitwiseType.Or:
                return(left + " | " + right);

            case BitwiseType.ExclusiveOr:
                return(left + " ^ " + right);

            default:
                throw new System.InvalidCastException();
            }
        }
예제 #3
0
		///
		/// <summary>
		///		Parses bitwise expressions
		/// </summary>
		/// 
		/// <param name="leftOp">Left operand</param>
		/// <param name="rightOp">Right operand</param>
		/// <param name="type">Bitwise expression type</param>
		/// 
		/// <returns>The result of applying the given bitwise operand</returns>
		/// 
		public static CseObject Parse(CseObject leftOp, CseObject rightOp, BitwiseType type) {
			CseObject obj = null;

			if (type == BitwiseType.NOT) {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral };
			}
			else {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral };
			}

			try {
				switch (type) {
					case BitwiseType.AND:
						obj.Value = leftOp.Value & rightOp.Value;
						break;
					case BitwiseType.OR:
						obj.Value = leftOp.Value | rightOp.Value;
						break;
					case BitwiseType.NOT:
						obj.Value = ~leftOp.Value;
						break;
					case BitwiseType.SHL:
						obj.Value = leftOp.Value << rightOp.Value;
						break;
					case BitwiseType.SHR:
						obj.Value = leftOp.Value >> rightOp.Value;
						break;
					default:
						throw new System.NotImplementedException("Not implemented.");
				}
			}
			catch {
				// TODO: Fill this out!
			}

			return obj;
		}