Example #1
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			ParameterExpression result = new ParameterExpression();
			result.Name = _name;
			result.NameSourceRange = _nameSourceRange;
			result.Parameter = _parameter;
			return result;
		}
Example #2
0
		public override ExpressionNode VisitParameterExpression(ParameterExpression expression)
		{
			_writer.Write("@");
			_writer.WriteIdentifier(expression.Name);
			return expression;
		}
Example #3
0
		private static bool VisitParameterExpression(ParameterExpression node1, ParameterExpression node2)
		{
			return node2 != null &&
			       node1.Name == node2.Name;
		}
Example #4
0
		public virtual ExpressionNode VisitParameterExpression(ParameterExpression expression)
		{
			return expression;
		}
Example #5
0
        private ExpressionNode ParsePrimaryExpression()
        {
            switch (_token.Id)
            {
                case TokenId.NULL:
                    NextToken();
                    return LiteralExpression.FromNull();

                case TokenId.TRUE:
                case TokenId.FALSE:
                    return ParseBooleanLiteral();

                case TokenId.Date:
                    return ParseDateLiteral();

                case TokenId.Number:
                    return ParseNumberLiteral();

                case TokenId.String:
                    return LiteralExpression.FromString(ParseString());

                case TokenId.EXISTS:
                {
                    ExistsSubselect result = new ExistsSubselect();
                    NextToken();
                    Match(TokenId.LeftParentheses);
                    result.Query = ParseQuery();
                    Match(TokenId.RightParentheses);

                    return result;
                }

                case TokenId.ParameterMarker:
                {
                    _rangeRecorder.Begin();
                    NextToken();
                    Identifier name = ParseIdentifier();
                    SourceRange nameSourceRange = _rangeRecorder.End();

                    ParameterExpression result = new ParameterExpression();
                    result.Name = name;
                    result.NameSourceRange = nameSourceRange;
                    return result;
                }

                case TokenId.CAST:
                {
                    NextToken();
                    CastExpression castExpression = new CastExpression();
                    Match(TokenId.LeftParentheses);
                    castExpression.Expression = ParseExpression();
                    Match(TokenId.AS);
                    castExpression.TypeReference = ParseTypeReference();
                    Match(TokenId.RightParentheses);

                    return castExpression;
                }

                case TokenId.CASE:
                {
                    NextToken();

                    CaseExpression caseExpression = new CaseExpression();

                    if (_token.Id != TokenId.WHEN && _token.Id != TokenId.ELSE && _token.Id != TokenId.END)
                        caseExpression.InputExpression = ParseExpression();

                    List<ExpressionNode> whenExpressionList = new List<ExpressionNode>();
                    List<ExpressionNode> expressionList = new List<ExpressionNode>();

                    if (_token.Id != TokenId.WHEN)
                    {
                        Match(TokenId.WHEN);
                    }
                    else
                    {
                        while (_token.Id == TokenId.WHEN)
                        {
                            NextToken();

                            whenExpressionList.Add(ParseExpression());
                            Match(TokenId.THEN);
                            expressionList.Add(ParseExpression());
                        }
                    }

                    caseExpression.WhenExpressions = whenExpressionList.ToArray();
                    caseExpression.ThenExpressions = expressionList.ToArray();

                    if (_token.Id == TokenId.ELSE)
                    {
                        NextToken();
                        caseExpression.ElseExpression = ParseExpression();
                    }

                    Match(TokenId.END);

                    return caseExpression;
                }

                case TokenId.COALESCE:
                {
                    NextToken();
                    CoalesceExpression coalesceExpression = new CoalesceExpression();
                    coalesceExpression.Expressions = ParseExpressionList();
                    return coalesceExpression;
                }

                case TokenId.NULLIF:
                {
                    NextToken();
                    NullIfExpression nullIfExpression = new NullIfExpression();
                    Match(TokenId.LeftParentheses);
                    nullIfExpression.LeftExpression = ParseExpression();
                    Match(TokenId.Comma);
                    nullIfExpression.RightExpression = ParseExpression();
                    Match(TokenId.RightParentheses);
                    return nullIfExpression;
                }

                case TokenId.Identifier:
                {
                    _rangeRecorder.Begin();
                    Identifier name = ParseIdentifier();
                    SourceRange nameSourceRange = _rangeRecorder.End();

                    if (_token.Id != TokenId.LeftParentheses)
                    {
                        NameExpression result = new NameExpression();
                        result.Name = name;
                        result.NameSourceRange = nameSourceRange;
                        return result;
                    }
                    else
                    {
                        bool hasAsteriskModifier;
                        ExpressionNode[] args;

                        if (_lookahead.Id != TokenId.Multiply)
                        {
                            hasAsteriskModifier = false;
                            args = ParseExpressionList();
                        }
                        else
                        {
                            NextToken();
                            NextToken();
                            Match(TokenId.RightParentheses);

                            hasAsteriskModifier = true;
                            args = new ExpressionNode[0];
                        }

                        FunctionInvocationExpression result = new FunctionInvocationExpression();
                        result.Name = name;
                        result.NameSourceRange = nameSourceRange;
                        result.Arguments = args;
                        result.HasAsteriskModifier = hasAsteriskModifier;
                        return result;
                    }
                }

                case TokenId.LeftParentheses:
                {
                    NextToken();

                    ExpressionNode expr;

                    if (_token.Id != TokenId.SELECT)
                    {
                        expr = ParseExpression();
                    }
                    else
                    {
                        SingleRowSubselect singleRowSubselect = new SingleRowSubselect();
                        singleRowSubselect.Query = ParseQuery();
                        expr = singleRowSubselect;
                    }

                    Match(TokenId.RightParentheses);
                    return expr;
                }

                default:
                {
                    _errorReporter.SimpleExpressionExpected(_token.Range, _token.Text);
                    return LiteralExpression.FromNull();
                }
            }
        }
Example #6
0
		public override ExpressionNode VisitParameterExpression(ParameterExpression expression)
		{
			_ilEmitContext.AddParameter(expression, expression.Parameter, typeof(ParameterBinding));
			return expression;
		}
Example #7
0
        public override ExpressionNode VisitParameterExpression(ParameterExpression expression)
        {
            ParameterBinding parameter = ResolveParameter(expression.NameSourceRange, expression.Name);

            if (parameter == null)
                ErrorReporter.UndeclaredParameter(expression.NameSourceRange, expression.Name);

            expression.Parameter = parameter;

            return expression;
        }
Example #8
0
        public override ExpressionNode VisitNameExpression(NameExpression expression)
        {
            // Resolve column
            // -- or --
            // Resolve constant
            // -- or --
            // Resolve parameter (without @)
            // -- or --
            // Reference to row object

            ColumnRefBinding columnRefBinding = ResolveColumnRef(expression.NameSourceRange, expression.Name);
            ConstantBinding constantBinding = ResolveConstant(expression.NameSourceRange, expression.Name);
            ParameterBinding parameterBinding = ResolveParameter(expression.NameSourceRange, expression.Name);
            TableRefBinding tableRefBinding = ResolveTableRef(expression.NameSourceRange, expression.Name);

            if (columnRefBinding != null)
            {
                if (constantBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { columnRefBinding, constantBinding });

                if (parameterBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { columnRefBinding, parameterBinding });

                if (tableRefBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { columnRefBinding, tableRefBinding });

                return new ColumnExpression(columnRefBinding);
            }

            if (constantBinding != null)
            {
                if (parameterBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { constantBinding, parameterBinding });

                if (tableRefBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { constantBinding, tableRefBinding });

                return new NamedConstantExpression(constantBinding);
            }

            if (parameterBinding != null)
            {
                if (tableRefBinding != null)
                    ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { parameterBinding, tableRefBinding });

                ParameterExpression parameterExpression = new ParameterExpression();
                parameterExpression.Name = expression.Name;
                parameterExpression.NameSourceRange = expression.NameSourceRange;
                parameterExpression.Parameter = parameterBinding;
                return parameterExpression;
            }

            if (tableRefBinding != null)
            {
                if (tableRefBinding.TableBinding is DerivedTableBinding ||
                    tableRefBinding.TableBinding is CommonTableBinding)
                {
                    ErrorReporter.InvalidRowReference(expression.NameSourceRange, tableRefBinding);
                    return expression;
                }
                else
                {
                    ColumnRefBinding cab = tableRefBinding.Scope.DeclareRowColumnRef(tableRefBinding);
                    return new ColumnExpression(cab);
                }
            }

            // Check if there is any function with this name declared. This helps to give a better
            // error message.

            FunctionBinding[] functionBindings = _scope.DataContext.Functions.Find(expression.Name);

            if (functionBindings != null && functionBindings.Length > 0)
            {
                // Report that parentheses are required in function calls.
                ErrorReporter.InvocationRequiresParentheses(expression.NameSourceRange, functionBindings);
            }
            else
            {
                // Report the regular undeclared entity error message.
                ErrorReporter.UndeclaredEntity(expression.NameSourceRange, expression.Name);
            }

            return expression;
        }
Example #9
0
		public override ExpressionNode VisitParameterExpression(ParameterExpression expression)
		{
			ILParameterDeclaration parameterBinding = _ilEmitContext.GetParameters(expression)[0];
			EmitLoadParameter(parameterBinding);
			EmitThisArgumentPointer(typeof(ParameterBinding));
			_ilEmitContext.ILGenerator.EmitCall(OpCodes.Call, _parameterBindingGetValueMethod, null);

			return expression;
		}
Example #10
0
		public override ExpressionNode VisitParameterExpression(ParameterExpression expression)
		{
			_xmlWriter.WriteStartElement("parameterExpression");
			_xmlWriter.WriteAttributeString("parameter", expression.Name.ToSource());
			WriteTypeAttribute(expression.ExpressionType);
			_xmlWriter.WriteEndElement();

			return expression;
		}