Пример #1
0
        public string Visit(MemberAccessChainExpression node)
        {
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            return(left + "." + right);

            //var chain = new List<string>();
            //var codeWriter = new XzaarCodeWriter();

            //var left = node.Left;
            //var isLeft = true;
            //while (left != null)
            //{
            //    var arrayIndexer = "";
            //    var wasChain = false;
            //    var chainExpr = left as MemberAccessChainExpression;
            //    if (chainExpr != null)
            //    {
            //        left = chainExpr.Right;
            //        wasChain = true;
            //    }

            //    var mb = left as MemberExpression;
            //    if (mb != null && mb.Expression != null)
            //    {

            //        if (mb.ArrayIndex != null)
            //        {
            //            arrayIndexer = "[" + Visit(mb.ArrayIndex) + "]";
            //        }

            //        var added = false;
            //        var f = mb.Expression as FieldExpression;
            //        var p = mb.Expression as ParameterDefinitionExpression;
            //        var c = mb.Expression as ConstantExpression;
            //        if (p != null)
            //        {
            //            if (isLeft) chain.Insert(0, p.Name + arrayIndexer);
            //            else chain.Add(p.Name + arrayIndexer);
            //            added = true;
            //        }
            //        if (f != null)
            //        {
            //            if (isLeft) chain.Insert(0, f.Name + arrayIndexer);
            //            else chain.Add(f.Name + arrayIndexer);
            //            added = true;
            //        }
            //        if (c != null)
            //        {
            //            if (isLeft) chain.Insert(0, Visit(c) + arrayIndexer);
            //            else chain.Add(Visit(c) + arrayIndexer);
            //            added = true;
            //        }
            //        if (added)
            //        {
            //            if (wasChain && chainExpr.Left != null)
            //            {
            //                left = chainExpr.Left;
            //            }
            //            else
            //            {
            //                if (!isLeft) break;
            //                left = node.Right;
            //                isLeft = false;
            //            }
            //            continue;
            //        }
            //    }

            //    var constantValue = left as ConstantExpression;
            //    if (constantValue != null)
            //    {
            //        if (constantValue.ArrayIndex != null)
            //            arrayIndexer = "[" + Visit(constantValue.ArrayIndex) + "]";

            //        if (isLeft) chain.Insert(0, Visit(constantValue) + arrayIndexer);
            //        else chain.Add(Visit(constantValue) + arrayIndexer);
            //        if (wasChain && chainExpr.Left != null) left = chainExpr.Left;
            //        else
            //        {
            //            if (!isLeft) break;
            //            left = node.Right;
            //            isLeft = false;
            //        }
            //        continue;
            //    }

            //    var fnc = left as FunctionCallExpression;
            //    if (fnc == null)
            //        break;
            //    insideExpressionCount++;
            //    var ii = ignoreInstance;
            //    ignoreInstance = true;
            //    var fValue = Visit(fnc);
            //    ignoreInstance = ii;
            //    insideExpressionCount--;
            //    if (isLeft) chain.Insert(0, fValue);
            //    else chain.Add(fValue);

            //    if (node.Right == fnc)
            //        break;

            //    // fnc.

            //    // chain.Insert(0, );
            //}
            //var indent = isInsideExpression ? 0 : currentIndent;
            //codeWriter.Write(string.Join(".", chain.ToArray()), indent);
            //if (!isInsideExpression && !noNewLine) codeWriter.NewLine();
            //return codeWriter.ToString();
        }
Пример #2
0
 public object Visit(MemberAccessChainExpression chain)
 {
     return(null);
 }
Пример #3
0
        public string Visit(MemberAccessChainExpression node)
        {
            var codeWriter = new XzaarCodeWriter();
            var chain      = new List <string>();
            var left       = node.Left;
            var isLeft     = true;

            while (left != null)
            {
                var leftValue = "";
                var wasChain  = false;
                var chainExpr = left as MemberAccessChainExpression;
                if (chainExpr != null)
                {
                    left     = chainExpr.Right;
                    wasChain = true;
                }

                var mb = left as MemberExpression;
                if (mb != null && mb.Expression != null)
                {
                    string arrayIndexer = "";
                    if (mb.ArrayIndex != null)
                    {
                        arrayIndexer = "[" + Visit(mb.ArrayIndex) + "]";
                    }

                    var added = false;
                    var f     = mb.Expression as FieldExpression;
                    var p     = mb.Expression as ParameterExpression;
                    if (p != null)
                    {
                        if (isLeft)
                        {
                            chain.Insert(0, p.Name + arrayIndexer);
                        }
                        else
                        {
                            chain.Add(p.Name + arrayIndexer);
                        }
                        added = true;
                    }
                    if (f != null)
                    {
                        if (isLeft)
                        {
                            chain.Insert(0, f.Name + arrayIndexer);
                        }
                        else
                        {
                            chain.Add(f.Name + arrayIndexer);
                        }
                        added = true;
                    }

                    if (added)
                    {
                        if (wasChain && chainExpr.Left != null)
                        {
                            left = chainExpr.Left;
                        }
                        else
                        {
                            if (!isLeft)
                            {
                                break;
                            }
                            left   = node.Right;
                            isLeft = false;
                        }
                        continue;
                    }
                }

                var fnc = left as FunctionCallExpression;
                if (fnc == null)
                {
                    break;
                }
                var fValue = Visit(fnc);
                if (isLeft)
                {
                    chain.Insert(0, fValue);
                }
                else
                {
                    chain.Add(fValue);
                }

                // fnc.

                // chain.Insert(0, );
            }
            var indent = isInsideExpression ? 0 : currentIndent;

            codeWriter.Write(string.Join(".", chain.ToArray()), indent);
            if (!isInsideExpression && !noNewLine)
            {
                codeWriter.NewLine();
            }
            return(codeWriter.ToString());
        }
 public object Visit(MemberAccessChainExpression access)
 {
     throw new System.NotImplementedException();
 }