示例#1
0
        public override void CheckSemantic(IASTContext context)
        {
            if (Instance != null)
            {
                Instance.CheckSemantic(context);
                Function = context.GetFunctionDeclaration(Instance.NetType, Name);
            }
            else
            {
                Function = context.GetFunctionDeclaration(Name);
            }

            if (Function == null)
            {
                throw new RecognitionException($"Function {Name} not found in context", Col, Row);
            }

            Type    = Function.ReturnType;
            NetType = Function.ReturnNetType;

            foreach (var parameter in Parameters)
            {
                parameter.CheckSemantic(context);
            }

            if (!Function.CheckParamterTypes(Parameters))
            {
                throw new RecognitionException($"Function {Name} parameters does not match", Col, Row);
            }
        }
示例#2
0
        public override void GenSQL(IASTContext context, StringBuilder sb, int tabOffset)
        {
            sb.Append('\t', tabOffset);

            sb.Append(BinaryExpression.getSQLOperator(op));
            expression.GenSQL(context, sb, 0);
        }
示例#3
0
 public override void CheckSemantic(IASTContext context)
 {
     if (type == null)
     {
         throw new RecognitionException(String.Format("missing type for {0}", value), Col, Row);
     }
 }
示例#4
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            return(declaration.LinqExpression);

            //responseProperty = context.ResponseType.GetProperty(name);
            //if (responseProperty == null)
            //    throw new RecognitionException("Property not found " + name + " in " + context.ResponseType.Name);

            //if (context.ResponseType == context.ModelType)
            //{
            //    modelProperty = responseProperty;
            //    linqExpression = System.Linq.Expressions.Expression.Property(context.Parameter, modelProperty);
            //}
            //else
            //{
            //    NavigationPropertyAttribute navAttr = responseProperty.GetCustomAttribute<NavigationPropertyAttribute>();
            //    if (navAttr != null)
            //    {
            //        modelProperty = context.ModelType.GetProperty(navAttr.NavigationProperty);
            //        linqExpression = System.Linq.Expressions.Expression.Property(context.Parameter, modelProperty);
            //        modelProperty = modelProperty.PropertyType.GetProperty(navAttr.Property);
            //        linqExpression = System.Linq.Expressions.Expression.Property(linqExpression, modelProperty);
            //    }
            //    else
            //    {
            //        modelProperty = context.ModelType.GetProperty(name);
            //        linqExpression = System.Linq.Expressions.Expression.Property(context.Parameter, modelProperty);
            //    }
            //}

            //type = Expression.GetExpressionType(responseProperty.PropertyType);
            //NetType = responseProperty.PropertyType;
        }
示例#5
0
        public override void GenSQL(IASTContext context, StringBuilder sb, int tabOffset)
        {
            sb.Append('\t', tabOffset);

            if (left is BinaryExpression)
            {
                sb.Append('(');
                left.GenSQL(context, sb, 0);
                sb.Append(')');
            }
            else
            {
                left.GenSQL(context, sb, 0);
            }

            sb.Append(' ');

            sb.Append(getSQLOperator(op));

            sb.Append(' ');

            if (right is BinaryExpression)
            {
                sb.Append('(');
                right.GenSQL(context, sb, 0);
                sb.Append(')');
            }
            else
            {
                right.GenSQL(context, sb, 0);
            }
        }
示例#6
0
        public override void GenSQL(IASTContext context, StringBuilder sb, int tabOffset)
        {
            //sb.Append('\t', tabOffset);

            //String column = modelProperty.Name;
            //sb.Append(column);
        }
示例#7
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            GenerateLinqExpresions(context, left, right, out LinqExpression expLeft, out LinqExpression expRight);

            if (IsNullable(expLeft.Type) && !IsNullable(expRight.Type))
            {
                expRight = LinqExpression.MakeUnary(System.Linq.Expressions.ExpressionType.Convert, expRight, expLeft.Type);
            }
            else if (IsNullable(expRight.Type) && !IsNullable(expLeft.Type))
            {
                expLeft = LinqExpression.MakeUnary(System.Linq.Expressions.ExpressionType.Convert, expLeft, expRight.Type);
            }

            switch (op)
            {
            case Operator.OP_ADD:
                return(LinqExpression.Add(expLeft, expRight));

            case Operator.OP_SUB:
                return(LinqExpression.Subtract(expLeft, expRight));

            case Operator.OP_DIV:
                return(LinqExpression.Divide(expLeft, expRight));

            case Operator.OP_MUL:
                return(LinqExpression.Multiply(expLeft, expRight));

            case Operator.OP_AND:
                return(LinqExpression.AndAlso(expLeft, expRight));

            case Operator.OP_OR:
                return(LinqExpression.OrElse(expLeft, expRight));

            case Operator.OP_EQUAL:
                return(LinqExpression.Equal(expLeft, expRight));

            case Operator.OP_DISTINT:
                return(LinqExpression.NotEqual(expLeft, expRight));

            case Operator.OP_LIKE:
                return(CreateLike(expLeft, expRight));

            case Operator.OP_LESS:
                return(LinqExpression.LessThan(expLeft, expRight));

            case Operator.OP_GREATHER:
                return(LinqExpression.GreaterThan(expLeft, expRight));

            case Operator.OP_GREATHER_EQ:
                return(LinqExpression.GreaterThanOrEqual(expLeft, expRight));

            case Operator.OP_LESS_EQ:
                return(LinqExpression.LessThanOrEqual(expLeft, expRight));

            default:
                throw new InvalidOperationException("operator not supported");
            }
        }
示例#8
0
        public override void CheckSemantic(IASTContext context)
        {
            type    = ExpressionType.Bool;
            NetType = typeof(bool);

            Left.CheckSemantic(context);

            Right.CheckSemantic(context);
        }
示例#9
0
 public override void CheckSemantic(IASTContext context)
 {
     declaration = context.GetVariableDeclaration(name);
     if (declaration == null)
     {
         throw new RecognitionException($"Variable {name} not found in context");
     }
     Type    = declaration.Type;
     NetType = declaration.NetType;
 }
        public override void CheckSemantic(IASTContext context)
        {
            base.CheckSemantic(context);

            if (type == ExpressionType.Null)
            {
                throw new RecognitionException("Null type not allowed for a relational expression", Col, Row);
            }

            type    = ExpressionType.Bool;
            NetType = typeof(bool);
        }
示例#11
0
 public override void GenOData(IASTContext context, StringBuilder sb, int tabOffset)
 {
     if (type == ExpressionType.String)
     {
         sb.appendEscapedSQLString(value);
     }
     else if (type == ExpressionType.Null)
     {
         sb.Append("null");
     }
     else
     {
         sb.Append(value);
     }
 }
示例#12
0
        public override void CheckSemantic(IASTContext context)
        {
            left.CheckSemantic(context);

            right.CheckSemantic(context);

            type = ExpressionType.match(left.Type, right.Type);

            if (type == null)
            {
                throw new RecognitionException("Type mistmatch ", Col, Row);
            }

            NetType = left.NetType;
        }
示例#13
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            if (Function.IsQueryMethod)
            {
                var genArg = Instance.NetType.GetGenericArguments();
                var method = Function.Method.MakeGenericMethod(genArg[0]);
                if (Parameters.Length > 0)
                {
                    var lambdaExp = Parameters[0].GenerateLinqExpression(new QueryASTContext
                    {
                        ModelType = genArg[0],
                        Parameter = _parameter
                    });
                    var lambda = System.Linq.Expressions.Expression.Lambda(method.GetParameters()[1].ParameterType, lambdaExp, _parameter);

                    return(System.Linq.Expressions.Expression.Call(Function.Method.DeclaringType, Function.Method.Name, new Type[] { genArg[0] },
                                                                   new System.Linq.Expressions.Expression[]
                    {
                        Instance?.GenerateLinqExpression(context),
                        lambda
                    }));
                }
                else
                {
                    return(System.Linq.Expressions.Expression.Call(Function.Method.DeclaringType, Function.Method.Name, new Type[] { genArg[0] },
                                                                   new System.Linq.Expressions.Expression[]
                    {
                        Instance?.GenerateLinqExpression(context)
                    }));
                }
            }
            else
            {
                System.Linq.Expressions.Expression[] argsExp = new System.Linq.Expressions.Expression[Parameters.Length];
                for (int i = 0; i < Parameters.Length; i++)
                {
                    argsExp[i] = Parameters[i].GenerateLinqExpression(context);
                }

                System.Linq.Expressions.Expression instanceExp = Function.Target != null?
                                                                 System.Linq.Expressions.Expression.Constant(Function.Target)
                                                                     : Instance?.GenerateLinqExpression(context);

                var callExp = System.Linq.Expressions.Expression.Call(instanceExp, Function.Method);
                return(System.Linq.Expressions.Expression.Invoke(callExp, argsExp));
            }
        }
示例#14
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            System.Linq.Expressions.Expression instanceExp = Function.Target != null?
                                                             System.Linq.Expressions.Expression.Constant(Function.Target)
                                                                 : Instance?.GenerateLinqExpression(context);

            var callExp = System.Linq.Expressions.Expression.Call(instanceExp, Function.Method);

            System.Linq.Expressions.Expression[] argsExp = new System.Linq.Expressions.Expression[Parameters.Length];

            for (int i = 0; i < Parameters.Length; i++)
            {
                argsExp[i] = Parameters[i].GenerateLinqExpression(context);
            }

            return(System.Linq.Expressions.Expression.Invoke(callExp, argsExp));
        }
示例#15
0
        public override void CheckSemantic(IASTContext context)
        {
            Left.CheckSemantic(context);

            if (Left.NetType == null)
            {
                throw new RecognitionException(".Net Type not recognized");
            }

            pi = Left.NetType.GetProperty(Name) ?? Left.NetType.GetProperty(Name.Pascal());
            if (pi == null)
            {
                throw new RecognitionException($"Property {Name} not found in {Left.NetType.Name}");
            }

            NetType = pi.PropertyType;
            type    = GetExpressionType(pi.PropertyType);
        }
示例#16
0
        public override void CheckSemantic(IASTContext context)
        {
            if (Instance != null)
            {
                Instance.CheckSemantic(context);
                Function = context.GetFunctionDeclaration(Instance.NetType, Name);
            }
            else
            {
                Function = context.GetFunctionDeclaration(Name);
            }

            if (Function == null)
            {
                throw new RecognitionException($"Function {Name} not found in context", Col, Row);
            }

            Type    = Function.ReturnType;
            NetType = Function.ReturnNetType;

            if (Function.IsQueryMethod)
            {
                var genArg = Instance.NetType.GetGenericArguments();
                _parameter = System.Linq.Expressions.Expression.Parameter(genArg[0]);

                context = new QueryASTContext
                {
                    ModelType = genArg[0],
                    Parameter = _parameter
                };
            }

            foreach (var parameter in Parameters)
            {
                parameter.CheckSemantic(context);
            }

            if (!Function.IsQueryMethod && !Function.CheckParamterTypes(Parameters))
            {
                throw new RecognitionException($"Function {Name} parameters does not match", Col, Row);
            }
        }
示例#17
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            var leftExp       = Left.GenerateLinqExpression(context);
            var leftModelType = ((PropertyInfo)((System.Linq.Expressions.MemberExpression)leftExp).Member).PropertyType;

            NavigationPropertyAttribute navAttr = pi.GetCustomAttribute <NavigationPropertyAttribute>();

            if (navAttr != null)
            {
                var modelProperty = leftModelType.GetProperty(navAttr.NavigationProperty);
                var linqExp       = System.Linq.Expressions.Expression.Property(leftExp, modelProperty);
                modelProperty = modelProperty.PropertyType.GetProperty(navAttr.Property);
                linqExp       = System.Linq.Expressions.Expression.Property(linqExp, modelProperty);
                return(linqExp);
            }

            var expression = System.Linq.Expressions.Expression.Property(leftExp, pi.Name);

            return(expression);
        }
示例#18
0
        public override void CheckSemantic(IASTContext context)
        {
            Condition.CheckSemantic(context);

            if (Condition.Type != ExpressionType.Bool)
            {
                throw new RecognitionException($"Expression at Line {Row} Col {Col} does not return boolean value");
            }

            OnTrue.CheckSemantic(context);

            OnFalse.CheckSemantic(context);

            type = ExpressionType.match(OnTrue.Type, OnFalse.Type);

            if (type == null)
            {
                throw new RecognitionException("Type mistmatch ", Col, Row);
            }

            NetType = OnTrue.NetType;
        }
示例#19
0
 public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
 {
     if (type == ExpressionType.String)
     {
         return(System.Linq.Expressions.Expression.Constant(value, typeof(string)));
     }
     else if (type == ExpressionType.Null)
     {
         return(System.Linq.Expressions.Expression.Constant(null));
     }
     else if (type == ExpressionType.Bool)
     {
         return(System.Linq.Expressions.Expression.Constant(bool.Parse(value)));
     }
     else if (type == ExpressionType.Integer)
     {
         return(System.Linq.Expressions.Expression.Constant(int.Parse(value)));
     }
     else if (type == ExpressionType.Double)
     {
         return(System.Linq.Expressions.Expression.Constant(double.Parse(value)));
     }
     throw new InvalidOperationException();
 }
示例#20
0
 public override void GenOData(IASTContext context, StringBuilder sb, int tabOffset)
 {
     throw new NotImplementedException();
 }
示例#21
0
 public abstract void GenOData(IASTContext context, StringBuilder sb, int tabOffset);
示例#22
0
 public abstract void CheckSemantic(IASTContext context);
示例#23
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            GenerateLinqExpresions(context, OnTrue, OnFalse, out LinqExpression expLeft, out LinqExpression expRight);

            return(LinqExpression.Condition(Condition.GenerateLinqExpression(context), expLeft, expRight));
        }
示例#24
0
 public ChildASTContext(IASTContext parent)
 {
     this.parent = parent;
 }
示例#25
0
 public override void CheckSemantic(IASTContext context)
 {
     throw new NotImplementedException();
 }
示例#26
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            var linqExp = expression.GenerateLinqExpression(context);

            return(System.Linq.Expressions.Expression.Negate(linqExp));
        }
示例#27
0
 public override void GenOData(IASTContext context, StringBuilder sb, int tabOffset)
 {
     sb.Append(BinaryExpression.getODataOperator(op));
     expression.GenOData(context, sb, 0);
 }
示例#28
0
 public override void CheckSemantic(IASTContext context)
 {
     expression.CheckSemantic(context);
     type = expression.Type;
 }
示例#29
0
 public abstract System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context);
示例#30
0
        public static void GenerateLinqExpresions(IASTContext context, Expression left, Expression right, out LinqExpression expLeft, out LinqExpression expRight)
        {
            expLeft = left.GenerateLinqExpression(context);

            if ((expLeft.Type == typeof(DateTime) || expLeft.Type == typeof(DateTime?)) ||
                (expLeft.Type == typeof(Guid) || expLeft.Type == typeof(Guid?)))
            {
                if (right.Type == ExpressionType.String && right is LiteralExpression)
                {
                    var literal = (LiteralExpression)right;

                    if (expLeft.Type == typeof(Guid) || expLeft.Type == typeof(Guid?))
                    {
                        if (!Guid.TryParse(literal.Value, out var guid))
                        {
                            throw new RecognitionException($"Invalid guid format '{literal.Value}'", literal.Col, literal.Row);
                        }
                        expRight = LinqExpression.Constant(guid);
                    }
                    else
                    {
                        if (DateTime.TryParse(literal.Value, out var date))//!DateTime.TryParseExact(literal.Value, DateFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
                        {
                            throw new RecognitionException($"Invalid date format '{literal.Value}'", literal.Col, literal.Row);
                        }
                        expRight = LinqExpression.Constant(date);
                    }
                }
                else
                {
                    expRight = right.GenerateLinqExpression(context);
                }
            }
            else
            {
                expRight = right.GenerateLinqExpression(context);
                if ((expRight.Type == typeof(DateTime) || expLeft.Type == typeof(DateTime?)) ||
                    (expRight.Type == typeof(Guid) || expLeft.Type == typeof(Guid?)))
                {
                    if (left.Type == ExpressionType.String && left is LiteralExpression)
                    {
                        var literal = (LiteralExpression)left;
                        if (expRight.Type == typeof(Guid) || expLeft.Type == typeof(Guid?))
                        {
                            if (!Guid.TryParse(literal.Value, out var guid))
                            {
                                throw new RecognitionException($"Invalid guid format '{literal.Value}'", literal.Col, literal.Row);
                            }
                            expLeft = LinqExpression.Constant(guid);
                        }
                        else
                        {
                            if (DateTime.TryParse(literal.Value, out var date))//!DateTime.TryParseExact(literal.Value, DateFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
                            {
                                throw new RecognitionException($"Invalid date format '{literal.Value}'", literal.Col, literal.Row);
                            }
                            expLeft = LinqExpression.Constant(date);
                        }
                    }
                }
            }
        }