Ejemplo n.º 1
0
        private static void Add(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
        {
            TokenInfo info = new TokenInfo(tokenId, text, isKeyword, isQueryKeyword, unOp, binOp);

            _infosById.Add(tokenId, info);

            if (text != null)
                _infosByText.Add(text, info);
        }
Ejemplo n.º 2
0
		public UnaryExpression(UnaryOperator op, ExpressionNode operand)
		{
			_op = op;
			_operand = operand;
		}
Ejemplo n.º 3
0
 private TokenInfo(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
 {
     _tokenId = tokenId;
     _text = text;
     _isKeyword = isKeyword;
     _isQueryKeyword = isQueryKeyword;
     _unaryOperator = unOp;
     _binaryOperator = binOp;
 }
Ejemplo n.º 4
0
 private TokenInfo(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
 {
     _tokenId        = tokenId;
     _text           = text;
     _isKeyword      = isKeyword;
     _isQueryKeyword = isQueryKeyword;
     _unaryOperator  = unOp;
     _binaryOperator = binOp;
 }
Ejemplo n.º 5
0
        private static void Add(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
        {
            TokenInfo info = new TokenInfo(tokenId, text, isKeyword, isQueryKeyword, unOp, binOp);

            _infosById.Add(tokenId, info);

            if (text != null)
            {
                _infosByText.Add(text, info);
            }
        }
Ejemplo n.º 6
0
        void IErrorReporter.AmbiguousOperator(UnaryOperator op, Type type, MethodInfo opMethod1, MethodInfo opMethod2)
        {
            string message = String.Format(
                CultureInfo.CurrentCulture,
                Resources.AmbiguousUnaryOp,
                op.TokenText,
                FormattingHelpers.FormatType(type),
                FormattingHelpers.FormatMethodInfo(opMethod1),
                FormattingHelpers.FormatMethodInfo(opMethod2)
            );

            HandleError(ErrorId.AmbiguousUnaryOperator, message);
        }
Ejemplo n.º 7
0
 void IErrorReporter.CannotApplyOperator(UnaryOperator op, Type type)
 {
     string message = String.Format(CultureInfo.CurrentCulture, Resources.CannotApplyUnaryOp, op.TokenText, FormattingHelpers.FormatType(type));
     HandleError(ErrorId.CannotApplyUnaryOperator, message);
 }
Ejemplo n.º 8
0
 public void PushUnary(UnaryOperator unaryOperator)
 {
     ExpressionNode operand = _expressionStack.Pop();
     UnaryExpression unaryExpression = new UnaryExpression(unaryOperator, operand);
     Push(unaryExpression);
 }
Ejemplo n.º 9
0
        public static RuntimeException UnaryOperatorFailed(UnaryOperator unaryOperator, MethodInfo operatorMethod, Type expressionType, object value, Exception exception)
        {
            if (unaryOperator == null)
                throw new ArgumentNullException("unaryOperator");

            if (operatorMethod == null)
                throw new ArgumentNullException("operatorMethod");

            if (expressionType == null)
                throw new ArgumentNullException("expressionType");

            if (exception == null)
                throw new ArgumentNullException("exception");

            string message = String.Format(
                CultureInfo.CurrentCulture,
                Resources.UnaryOperatorFailed,
                unaryOperator.TokenText,
                FormattingHelpers.FormatType(expressionType),
                FormattingHelpers.FormatMethodInfo(operatorMethod),
                exception.Message,
                value,
                Environment.NewLine
            );

            return new RuntimeException(message, exception);
        }
Ejemplo n.º 10
0
        private ExpressionNode ParseSubExpression(ExpressionNode left, int precedence)
        {
            if (left == null)
            {
                // No left operand, so we parse one and take care about leading unary operators

                if (_token.Info.UnaryOperator != null)
                {
                    UnaryOperator op = _token.Info.UnaryOperator;

                    NextToken();

                    ExpressionNode expr = ParseSubExpression(null, op.Precedence);
                    left = new UnaryExpression(op, expr);
                }
                else
                {
                    left = ParseSimpleExpression();
                }
            }

            while (_token.Id != TokenId.Eof)
            {
                // Special handling for NOT BETWEEN, NOT IN, NOT LIKE, NOT SIMILAR TO, and NOT SOUNDSLIKE.

                bool negated = false;

                if (_token.Id == TokenId.NOT)
                {
                    if (_lookahead.Id == TokenId.BETWEEN ||
                        _lookahead.Id == TokenId.IN ||
                        _lookahead.Id == TokenId.LIKE ||
                        _lookahead.Id == TokenId.SIMILAR ||
                        _lookahead.Id == TokenId.SOUNDSLIKE)
                    {
                        NextToken();
                        negated = true;
                    }
                }

                // Special handling for the only ternary operator BETWEEN

                if (_token.Id == TokenId.BETWEEN)
                {
                    NextToken();
                    ExpressionNode lowerBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);
                    Match(TokenId.AND);
                    ExpressionNode upperBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);

                    left = new BetweenExpression(left, lowerBound, upperBound);
                }
                else
                {
                    // If there is no binary operator we are finished

                    if (_token.Info.BinaryOperator == null)
                    {
                        break;
                    }

                    BinaryOperator binaryOp = _token.Info.BinaryOperator;

                    // Precedence is lower, parse it later

                    if (binaryOp.Precedence < precedence)
                    {
                        break;
                    }

                    // Precedence is equal, but operator ist not right associative, parse it later

                    if (binaryOp.Precedence == precedence && !binaryOp.IsRightAssociative)
                    {
                        break;
                    }

                    // Precedence is higher

                    NextToken();

                    // Special handling for SIMILAR TO

                    if (binaryOp == BinaryOperator.SimilarTo)
                    {
                        Match(TokenId.TO);
                    }

                    if (binaryOp == BinaryOperator.In)
                    {
                        // Special handling for IN

                        InExpression inExpression = new InExpression();
                        inExpression.Left             = left;
                        inExpression.RightExpressions = ParseSimpleQueryExpressionList();
                        left = inExpression;
                    }
                    else if (_token.Id == TokenId.ANY || _token.Id == TokenId.SOME || _token.Id == TokenId.ALL)
                    {
                        // Special handling for ANY (SOME) and ALL

                        if (binaryOp != BinaryOperator.Equal &&
                            binaryOp != BinaryOperator.NotEqual &&
                            binaryOp != BinaryOperator.Less &&
                            binaryOp != BinaryOperator.LessOrEqual &&
                            binaryOp != BinaryOperator.Greater &&
                            binaryOp != BinaryOperator.GreaterOrEqual)
                        {
                            _errorReporter.InvalidOperatorForAllAny(_token.Range, binaryOp);
                        }

                        AllAnySubselect allAnySubselect = new AllAnySubselect();
                        allAnySubselect.Left = left;
                        allAnySubselect.Op   = binaryOp;
                        allAnySubselect.Type = (_token.Id == TokenId.ALL) ? AllAnySubselect.AllAnyType.All : AllAnySubselect.AllAnyType.Any;
                        NextToken();
                        Match(TokenId.LeftParentheses);
                        allAnySubselect.Query = ParseQuery();
                        Match(TokenId.RightParentheses);
                        left = allAnySubselect;
                    }
                    else
                    {
                        left = new BinaryExpression(binaryOp, left, ParseSubExpression(null, binaryOp.Precedence));
                    }
                }

                // Special handling for negated expressions (see above)

                if (negated)
                {
                    left = new UnaryExpression(UnaryOperator.LogicalNot, left);
                }
            }

            return(left);
        }
Ejemplo n.º 11
0
		public MethodInfo BindOperator(UnaryOperator op, Type operandType)
		{
			if (operandType == typeof(DBNull))
				return _unaryOperatorPlaceholder;

			try
			{
				List<MethodInfo> methodList = new List<MethodInfo>();

				// Get user defined operator
				methodList.AddRange(OperatorMethodCache.GetOperatorMethods(operandType, op));
				
				// Get the operator method from the buitlin ones
				methodList.AddRange(OperatorMethodCache.GetOperatorMethods(typeof(BuiltInOperators), op));

				MethodInfo[] methods = methodList.ToArray();

				return BindMethodInfo(methods, new Type[] {operandType});
			}
			catch (InvocationIsAmbiguousException ex)
			{
				_errorReporter.AmbiguousOperator(op, operandType, ex.Method1, ex.Method2);

				// Avoid cascading errors
				return ex.Method1;
			}
		}
Ejemplo n.º 12
0
 public UnaryExpression(UnaryOperator op, ExpressionNode operand)
 {
     _op      = op;
     _operand = operand;
 }