internal CodeGeneratorImpl(QueryImpl query, Type cls) { 
     if (cls == null) { 
         throw new CodeGeneratorException("No class defined");
     }
     this.cls = cls;
     this.query = query;
 }
        internal static QueryImpl GetInstance([CallerMemberName] string callerName = "")
        {
            var instance = new QueryImpl();

            InstanceFactory(ref instance, callerName);
            return(instance);
        }
        public Code Pow(Code opd1, Code opd2)
        {
            Node left  = (Node)opd1;
            Node right = (Node)opd2;

            if (left.type == NodeType.tpReal || right.type == NodeType.tpReal)
            {
                if (left.type == NodeType.tpInt)
                {
                    left = QueryImpl.int2real(left);
                }
                else if (left.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (right.type == NodeType.tpInt)
                {
                    right = QueryImpl.int2real(right);
                }
                else if (right.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new BinOpNode(NodeType.tpReal, NodeTag.opRealPow, left, right));
            }
            else if (left.type == NodeType.tpInt && right.type == NodeType.tpInt)
            {
                return(new BinOpNode(NodeType.tpInt, NodeTag.opIntPow, left, right));
            }
            else
            {
                throw new CodeGeneratorException("Invalid argument types");
            }
        }
Beispiel #4
0
            public override IQuery GetExecutableQuery(ISession session)
            {
                var result = base.GetExecutableQuery(session);

                queryExecutable = (QueryImpl)result;
                return(result);
            }
        public Code Le(Code opd1, Code opd2)
        {
            Node left  = (Node)opd1;
            Node right = (Node)opd2;

            if (left.type == NodeType.tpReal || right.type == NodeType.tpReal)
            {
                if (left.type == NodeType.tpInt)
                {
                    left = QueryImpl.int2real(left);
                }
                else if (left.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (right.type == NodeType.tpInt)
                {
                    right = QueryImpl.int2real(right);
                }
                else if (right.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new BinOpNode(NodeType.tpBool, NodeTag.opRealLe, left, right));
            }
            else if (left.type == NodeType.tpInt && right.type == NodeType.tpInt)
            {
                return(new BinOpNode(NodeType.tpBool, NodeTag.opIntLe, left, right));
            }
            else if (left.type == NodeType.tpStr && right.type == NodeType.tpStr)
            {
                return(new BinOpNode(NodeType.tpBool, NodeTag.opStrLe, left, right));
            }
            else if (left.type == NodeType.tpDate || right.type == NodeType.tpDate)
            {
                if (left.type == NodeType.tpStr)
                {
                    left = QueryImpl.str2date(left);
                }
                else if (left.type != NodeType.tpDate)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (right.type == NodeType.tpStr)
                {
                    right = QueryImpl.str2date(right);
                }
                else if (right.type != NodeType.tpDate)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new BinOpNode(NodeType.tpBool, NodeTag.opDateLe, left, right));
            }
            else
            {
                throw new CodeGeneratorException("Invalid argument types");
            }
        }
 internal CodeGeneratorImpl(QueryImpl query, Type cls)
 {
     if (cls == null)
     {
         throw new CodeGeneratorException("No class defined");
     }
     this.cls   = cls;
     this.query = query;
 }
        public Code Field(Code baseExpr, String name)
        {
            Type      scope = (baseExpr == null) ? cls : ((Node)baseExpr).Type;
            FieldInfo f     = QueryImpl.lookupField(scope, name);

            if (f == null)
            {
                throw new CodeGeneratorException("No such field " + name + " in class " + scope);
            }
            return(new LoadNode((Node)baseExpr, f));
        }
        Node mathFunc(NodeTag cop, Code opd)
        {
            Node expr = (Node)opd;

            if (expr.type == NodeType.tpInt)
            {
                expr = QueryImpl.int2real(expr);
            }
            else if (expr.type != NodeType.tpReal)
            {
                throw new CodeGeneratorException("Invalid argument types");
            }
            return(new UnaryOpNode(NodeType.tpReal, cop, expr));
        }
        public void OrderBy(String name, bool ascent)
        {
            FieldInfo f = QueryImpl.lookupField(cls, name);
            OrderNode node;

            if (f == null)
            {
                MethodInfo m = QueryImpl.lookupMethod(cls, name, QueryImpl.defaultProfile);
                if (m == null)
                {
                    throw new CodeGeneratorException("No such field " + name + " in class " + cls);
                }
                else
                {
                    node = new OrderNode(m);
                }
            }
            else
            {
                node = new OrderNode(f);
            }
            node.ascent = ascent;
            if (query.order == null)
            {
                query.order = node;
            }
            else
            {
                OrderNode last;
                for (last = query.order; last.next != null; last = last.next)
                {
                    ;
                }
                last.next = node;
            }
        }
Beispiel #10
0
        public IEnumerable Select(Type cls, string predicate)
        {
            Query query = new QueryImpl(null);

            return(query.Select(cls, this, predicate));
        }
Beispiel #11
0
        public IEnumerable <T> Select(string predicate)
        {
            Query <T> query = new QueryImpl <T>(null);

            return(query.Select(this, predicate));
        }
        public Code Between(Code opd1, Code opd2, Code opd3)
        {
            Node expr = (Node)opd1;
            Node low  = (Node)opd2;
            Node high = (Node)opd3;

            if (expr.type == NodeType.tpReal || low.type == NodeType.tpReal || high.type == NodeType.tpReal)
            {
                if (expr.type == NodeType.tpInt)
                {
                    expr = QueryImpl.int2real(expr);
                }
                else if (expr.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (low.type == NodeType.tpInt)
                {
                    low = QueryImpl.int2real(low);
                }
                else if (low.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (high.type == NodeType.tpInt)
                {
                    high = QueryImpl.int2real(high);
                }
                else if (high.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new CompareNode(NodeTag.opRealBetween, expr, low, high));
            }
            else if (expr.type == NodeType.tpInt && low.type == NodeType.tpInt && high.type == NodeType.tpInt)
            {
                return(new CompareNode(NodeTag.opIntBetween, expr, low, high));
            }
            else if (expr.type == NodeType.tpStr && low.type == NodeType.tpStr && high.type == NodeType.tpStr)
            {
                return(new CompareNode(NodeTag.opStrBetween, expr, low, high));
            }
            else if (expr.type == NodeType.tpDate)
            {
                if (low.type == NodeType.tpStr)
                {
                    low = QueryImpl.str2date(low);
                }
                else if (low.type != NodeType.tpDate)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                if (high.type == NodeType.tpStr)
                {
                    high = QueryImpl.str2date(high);
                }
                else if (high.type != NodeType.tpDate)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new CompareNode(NodeTag.opDateBetween, expr, low, high));
            }
            else
            {
                throw new CodeGeneratorException("Invalid argument types");
            }
        }
        public override IEnumerable <M> Select(string predicate)
        {
            Query <M> query = new QueryImpl <M>(Storage);

            return(query.Select(link, predicate));
        }
 static partial void InstanceFactory(ref QueryImpl instance, [CallerMemberName] string callerName = "");
        public Code In(Code opd1, Code opd2)
        {
            Node left  = (Node)opd1;
            Node right = (Node)opd2;

            if (right == null)
            {
                return(new ConstantNode(NodeType.tpBool, NodeTag.opFalse));
            }
            switch (right.type)
            {
            case NodeType.tpCollection:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanCollection, left, right));

            case NodeType.tpArrayBool:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayBool, checkType(NodeType.tpBool, left), right));

            case NodeType.tpArrayChar:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayChar, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayInt1:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayInt1, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayInt2:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayInt2, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayInt4:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayInt4, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayInt8:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayInt8, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayUInt1:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayUInt1, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayUInt2:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayUInt2, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayUInt4:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayUInt4, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayUInt8:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayUInt8, checkType(NodeType.tpInt, left), right));

            case NodeType.tpArrayReal4:
                if (left.type == NodeType.tpInt)
                {
                    left = QueryImpl.int2real(left);
                }
                else if (left.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayReal4, left, right));

            case NodeType.tpArrayReal8:
                if (left.type == NodeType.tpInt)
                {
                    left = QueryImpl.int2real(left);
                }
                else if (left.type != NodeType.tpReal)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayReal8, left, right));

            case NodeType.tpArrayObj:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayObj, checkType(NodeType.tpObj, left), right));

            case NodeType.tpArrayStr:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opScanArrayStr, checkType(NodeType.tpStr, left), right));

            case NodeType.tpStr:
                return(new BinOpNode(NodeType.tpBool, NodeTag.opInString, checkType(NodeType.tpStr, left), right));

            case NodeType.tpList:
                return(listToTree(left, (BinOpNode)right));

            default:
                throw new CodeGeneratorException("Invalid argument types");
            }
        }
        private static Node listToTree(Node expr, BinOpNode list)
        {
            BinOpNode tree = null;

            do
            {
                Node    elem = list.right;
                NodeTag cop  = NodeTag.opNop;
                if (elem.type == NodeType.tpUnknown)
                {
                    elem.type = expr.type;
                }
                if (expr.type == NodeType.tpInt)
                {
                    if (elem.type == NodeType.tpReal)
                    {
                        expr = new UnaryOpNode(NodeType.tpReal, NodeTag.opIntToReal, expr);
                        cop  = NodeTag.opRealEq;
                    }
                    else if (elem.type == NodeType.tpInt)
                    {
                        cop = NodeTag.opIntEq;
                    }
                }
                else if (expr.type == NodeType.tpReal)
                {
                    if (elem.type == NodeType.tpReal)
                    {
                        cop = NodeTag.opRealEq;
                    }
                    else if (elem.type == NodeType.tpInt)
                    {
                        cop  = NodeTag.opRealEq;
                        elem = QueryImpl.int2real(elem);
                    }
                }
                else if (expr.type == NodeType.tpDate && elem.type == NodeType.tpDate)
                {
                    cop = NodeTag.opDateEq;
                }
                else if (expr.type == NodeType.tpStr && elem.type == NodeType.tpStr)
                {
                    cop = NodeTag.opStrEq;
                }
                else if (expr.type == NodeType.tpObj && elem.type == NodeType.tpObj)
                {
                    cop = NodeTag.opObjEq;
                }
                else if (expr.type == NodeType.tpBool && elem.type == NodeType.tpBool)
                {
                    cop = NodeTag.opBoolEq;
                }
                if (cop == NodeTag.opNop)
                {
                    throw new CodeGeneratorException("Invalid argument types");
                }
                BinOpNode cmp = new BinOpNode(NodeType.tpBool, cop, expr, elem);
                if (tree == null)
                {
                    tree = cmp;
                }
                else
                {
                    tree = new BinOpNode(NodeType.tpBool, NodeTag.opBoolOr, cmp, tree);
                }
            } while ((list = (BinOpNode)list.left) != null);
            return(tree);
        }
        public override IEnumerable Select(Type cls, string predicate)
        {
            Query query = new QueryImpl(Storage);

            return(query.Select(cls, link, predicate));
        }
Beispiel #18
0
        public IEnumerable Select(string predicate)
        {
            Query query = new QueryImpl(Storage);

            return(query.Select(cls, this, predicate));
        }
        public Code Invoke(Code baseExpr, String name, params Code[] arguments)
        {
            Type[] profile = new Type[arguments.Length];
            Node[] args    = new Node[arguments.Length];
            for (int i = 0; i < profile.Length; i++)
            {
                Node arg = (Node)arguments[i];
                args[i] = arg;
                Type argType;
                switch (arg.type)
                {
                case NodeType.tpInt:
                    argType = typeof(long);
                    break;

                case NodeType.tpReal:
                    argType = typeof(double);
                    break;

                case NodeType.tpStr:
                    argType = typeof(String);
                    break;

                case NodeType.tpDate:
                    argType = typeof(DateTime);
                    break;

                case NodeType.tpBool:
                    argType = typeof(bool);
                    break;

                case NodeType.tpObj:
                    argType = arg.Type;
                    break;

                case NodeType.tpArrayBool:
                    argType = typeof(bool[]);
                    break;

                case NodeType.tpArrayChar:
                    argType = typeof(char[]);
                    break;

                case NodeType.tpArrayInt1:
                    argType = typeof(sbyte[]);
                    break;

                case NodeType.tpArrayInt2:
                    argType = typeof(short[]);
                    break;

                case NodeType.tpArrayInt4:
                    argType = typeof(int[]);
                    break;

                case NodeType.tpArrayInt8:
                    argType = typeof(long[]);
                    break;

                case NodeType.tpArrayUInt1:
                    argType = typeof(byte[]);
                    break;

                case NodeType.tpArrayUInt2:
                    argType = typeof(ushort[]);
                    break;

                case NodeType.tpArrayUInt4:
                    argType = typeof(uint[]);
                    break;

                case NodeType.tpArrayUInt8:
                    argType = typeof(ulong[]);
                    break;

                case NodeType.tpArrayReal4:
                    argType = typeof(float[]);
                    break;

                case NodeType.tpArrayReal8:
                    argType = typeof(double[]);
                    break;

                case NodeType.tpArrayStr:
                    argType = typeof(String[]);
                    break;

                case NodeType.tpArrayObj:
                    argType = typeof(Object[]);
                    break;

                default:
                    throw new CodeGeneratorException("Invalid method argument type");
                }
                profile[i] = argType;
            }
            Type       scope = (baseExpr == null) ? cls : ((Node)baseExpr).Type;
            MethodInfo mth   = QueryImpl.lookupMethod(scope, name, profile);

            if (mth == null)
            {
                throw new CodeGeneratorException("MethodInfo " + name + " not found in class " + scope);
            }
            return(new InvokeNode((Node)baseExpr, mth, args));
        }
        public virtual IEnumerable <T> Select(string predicate)
        {
            Query <T> query = new QueryImpl <T>(Storage);

            return(query.Select(this, predicate));
        }