Exemplo n.º 1
0
        protected override List <AphidExpression> MutateCore(AphidExpression expression, out bool hasChanged)
        {
            hasChanged = false;

            var parent = expression as IParentNode;

            if (IsStatement &&
                expression.Type == AphidExpressionType.BinaryOperatorExpression &&
                expression.ToBinaryOperator().LeftOperand.Type == AphidExpressionType.IdentifierExpression &&
                expression.ToBinaryOperator().RightOperand.Type == AphidExpressionType.FunctionExpression)
            {
                _rootFunctions.Add(expression.ToBinaryOperator().RightOperand.ToFunction());

                return(null);
            }
            else if (expression.Type == AphidExpressionType.FunctionExpression &&
                     !_rootFunctions.Contains(expression.ToFunction()))
            {
                var parents = AphidTreeHelper.FirstOrDefaultPath(_ast, x => x == expression);

                if (parents.Length >= 3 &&
                    parents.Skip(1).First().Type == AphidExpressionType.BinaryOperatorExpression &&
                    parents.Skip(2).First().Type == AphidExpressionType.ObjectExpression)
                {
                    return(null);
                }

                var eligible = GetEligibleMethodContainer(parents, out var after);

                if (eligible != null)
                {
                    var id = QueueInsertion(expression.ToFunction(), eligible, after);
                    hasChanged = true;

                    return(new List <AphidExpression> {
                        id
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public static IdentifierExpression GetDeclaredIdentifier(AphidExpression expression)
        {
            switch (expression.Type)
            {
            case AphidExpressionType.ForEachExpression:
                var element = expression.ToForEach().Element;

                if (element.Type == AphidExpressionType.IdentifierExpression)
                {
                    return(element.ToIdentifier());
                }

                break;

            case AphidExpressionType.BinaryOperatorExpression:
                var binOpExp = expression.ToBinaryOperator();

                if (binOpExp.Operator == AphidTokenType.AssignmentOperator &&
                    binOpExp.LeftOperand.Type == AphidExpressionType.IdentifierExpression)
                {
                    return(binOpExp.LeftOperand.ToIdentifier());
                }

                break;
            }

            return(null);
        }
Exemplo n.º 3
0
        protected override void Visit(AphidExpression expression)
        {
            switch (expression.Type)
            {
            case AphidExpressionType.ForEachExpression:
                var element = expression.ToForEach().Element;

                if (element.Type == AphidExpressionType.IdentifierExpression)
                {
                    _locals.Add(element.ToIdentifier());
                }

                break;

            case AphidExpressionType.BinaryOperatorExpression:
                var binOpExp = expression.ToBinaryOperator();

                if (binOpExp.Operator == AphidTokenType.AssignmentOperator &&
                    binOpExp.LeftOperand.Type == AphidExpressionType.IdentifierExpression)
                {
                    _locals.Add(binOpExp.LeftOperand.ToIdentifier());
                }

                break;

            case AphidExpressionType.FunctionExpression:
                IgnoreChildren();
                break;
            }
        }
Exemplo n.º 4
0
 protected override void BeginVisitNode(AphidExpression expression)
 {
     if (IsMember(expression))
     {
         _object = Ancestors.Peek().ToObject();
         _member = expression.ToBinaryOperator();
         _currentPath.Push(_member.LeftOperand);
     }
     else if (IsArray(expression))
     {
         _array = expression.ToArray();
     }
 }
Exemplo n.º 5
0
        protected override List<AphidExpression> MutateCore(AphidExpression expression, out bool hasChanged)
        {
            BinaryOperatorExpression binOpExp;

            if (expression.Type != AphidNodeType.BinaryOperatorExpression ||
                (binOpExp = expression.ToBinaryOperator()).Operator != AphidTokenType.PlusEqualOperator)
            {
                hasChanged = false;

                return null;
            }

            hasChanged = true;

            return new List<AphidExpression>
            {
                new CallExpression(
                    new BinaryOperatorExpression(
                        binOpExp.LeftOperand,
                        AphidTokenType.MemberOperator,
                        new IdentifierExpression("Add")),
                    binOpExp.RightOperand)
            };
        }
Exemplo n.º 6
0
        protected override List <AphidExpression> MutateCore(AphidExpression expression, out bool hasChanged)
        {
            BinaryOperatorExpression binOpExp;

            if (expression.Type != AphidExpressionType.BinaryOperatorExpression ||
                (binOpExp = expression.ToBinaryOperator()).Operator != AphidTokenType.PlusEqualOperator)
            {
                hasChanged = false;

                return(null);
            }

            hasChanged = true;

            return(new List <AphidExpression>
            {
                new CallExpression(
                    new BinaryOperatorExpression(
                        binOpExp.LeftOperand,
                        AphidTokenType.MemberOperator,
                        new IdentifierExpression("Add")),
                    binOpExp.RightOperand)
            });
        }