Beispiel #1
0
        internal BitwiseExpression this[ExpressionKind type]
        {
            get
            {
                if (!type.IsBitwise())
                {
                    throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(ExpressionKind));
                }

                if (_operations.ContainsKey(type))
                {
                    return(_operations[type]);
                }

                Type concreteType = Type.GetType(GetType().Namespace + "." + Enum.GetName(typeof(ExpressionKind), type) + "Expression");
                if ((concreteType == null) || !concreteType.IsBitwiseExpression())
                {
                    throw new InvalidBitwiseTypeException();
                }

                BitwiseExpression obj = (BitwiseExpression)Activator.CreateInstance(concreteType);
                _operations.Add(type, obj);
                return(obj);
            }
        }
Beispiel #2
0
        internal static string GetBitwiseToken(this ExpressionKind expressionKind)
        {
            if (!expressionKind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(expressionKind), (int)expressionKind, typeof(ExpressionKind));
            }

            switch (expressionKind)
            {
            case ExpressionKind.BitwiseAnd:
                return("&");

            case ExpressionKind.BitwiseLeftShift:
                return("<<");

            case ExpressionKind.BitwiseNot:
                return("~");

            case ExpressionKind.BitwiseOr:
                return("|");

            case ExpressionKind.BitwiseRightShift:
                return(">>");

            case ExpressionKind.BitwiseXor:
                return("^");

            default:
                throw new ArgumentOutOfRangeException(nameof(expressionKind), expressionKind, null);
            }
        }
Beispiel #3
0
        internal static string GetBitwzName(this ExpressionKind expressionKind)
        {
            if (!expressionKind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(expressionKind), (int)expressionKind, typeof(ExpressionKind));
            }

            switch (expressionKind)
            {
            case ExpressionKind.BitwiseAnd:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bAnd));

            case ExpressionKind.BitwiseLeftShift:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bShl));

            case ExpressionKind.BitwiseNot:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bNot));

            case ExpressionKind.BitwiseOr:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bOr));

            case ExpressionKind.BitwiseRightShift:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bShr));

            case ExpressionKind.BitwiseXor:
                return(typeof(BitwzMath).FullName + "." + nameof(BitwzMath.bXor));

            default:
                throw new ArgumentOutOfRangeException(nameof(expressionKind), expressionKind, null);
            }
        }
Beispiel #4
0
        internal static bool IsUnary(this ExpressionKind expressionKind)
        {
            if (!expressionKind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(expressionKind), (int)expressionKind, typeof(ExpressionKind));
            }

            return(expressionKind == ExpressionKind.BitwiseNot);
        }
        internal BitwiseFunctionAttribute(ExpressionKind kind)
        {
            if (!kind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(kind), (int)kind, typeof(ExpressionKind));
            }

            Kind     = kind;
            IsUnary  = kind.IsUnary();
            Operator = kind.GetBitwiseToken();
        }
Beispiel #6
0
        internal static bool HasHigherPrecedenceThan(this ExpressionKind expressionKind, ExpressionKind otherExpressionKind)
        {
            if (!expressionKind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(expressionKind), (int)expressionKind, typeof(ExpressionKind));
            }
            if (!otherExpressionKind.IsBitwise())
            {
                throw new InvalidEnumArgumentException(nameof(otherExpressionKind), (int)otherExpressionKind, typeof(ExpressionKind));
            }

            return((Math.Abs((int)expressionKind - (int)otherExpressionKind) >= 5000) && ((int)expressionKind > (int)otherExpressionKind));
        }