Пример #1
0
            protected override Expression VisitMethodCall(MethodCallExpression node)
            {
                // static bool System.Text.RegularExpressions.Regex.IsMatch(string e.f, string pattern)
                // ==>
                // public unsafe ColumnBatch<long> IsMatch(string regex, ColumnBatch<long> inBV, bool inPlace = true)

                string methodCall;

                if (VectorizableVisitor.IsStaticRegexMatch(node, this.batchType))
                {
                    var args = string.Join(",", node.Arguments.Skip(1).Select(a => a.ExpressionToCSharp()));
                    methodCall = string.Format(
                        "{0}{1}_col.IsMatch({2}, {3}, {4});",
                        Transformer.ColumnFieldPrefix,
                        (node.Arguments.ElementAt(0) as MemberExpression).Member.Name,
                        args, this.incomingBV, this.inPlace ? "true" : "false");
                }
                else
                {
                    // assume that the method call is an instance method and that the receiver is
                    // the field being represented as a MultiString.
                    var memberExpression = node.Object as MemberExpression;
                    var member           = memberExpression.Member;
                    var args             = string.Join(",", node.Arguments.Select(a => a.ExpressionToCSharp()));
                    methodCall = string.Format(
                        "{0}{1}_col.{2}({3}, {4}, {5});",
                        Transformer.ColumnFieldPrefix,
                        member.Name,
                        node.Method.Name,
                        args, this.incomingBV, this.inPlace ? "true" : "false");
                }
                var s = string.Empty;

                if (this.inPlace)
                {
                    this.resultBV = this.incomingBV;
                }
                else
                {
                    this.resultBV = string.Format("bv{0}", counter++);
                    s             = "var " + this.resultBV + " = ";
                }
                s += methodCall;
                this.vectorStatements.Add(s);
                return(node);
            }
Пример #2
0
        private static bool IsVectorizable(Type batchType, Expression e)
        {
            // For now, the only vectorizable things are boolean combinatios of
            // method calls to certain String methods where none of the arguments
            // to the call contain any calls to any String methods.
            // E.g., s.Contains(t) is allowed, s.Contains(t.Substring(...)) is not.
            // s.Equals(t) || s.Contains(u) is allowed
            if (!(e is BinaryExpression || e is UnaryExpression || e is MethodCallExpression || e is MemberExpression))
            {
                return(false);
            }

            var vectorVisitor = new VectorizableVisitor(batchType);

            vectorVisitor.Visit(e);
            return(vectorVisitor.IsVectorizable);
        }