private static UnifiedExpression CreateAttrasgn(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "attrasgn");
            var left  = CreateExpresion(node.FirstElement());
            var name  = node.NthElement(1);
            var args  = CreateArglist(node.LastElement());
            var right = args[args.Count - 1].Value;

            args.RemoveAt(args.Count - 1);
            right.RemoveSelf();
            UnifiedExpression expression;

            if (name.Value == "[]=")
            {
                expression = UnifiedIndexer.Create(left, args);
            }
            else
            {
                var propName = name.Value;
                propName   = propName.Substring(0, propName.Length - 1);
                expression = UnifiedProperty.Create(
                    ".", left, UnifiedVariableIdentifier.Create(propName));
            }
            return(UnifiedBinaryExpression.Create(
                       expression,
                       UnifiedBinaryOperator.Create(
                           "=", UnifiedBinaryOperatorKind.Assign),
                       right));
        }
Esempio n. 2
0
        public UnifiedElement VisitIndexerExpression(
            IndexerExpression indexer, object data)
        {
            var target = indexer.Target.TryAcceptForExpression(this);
            var args   = indexer.Arguments.AcceptVisitorAsArgs(this, data);

            return(UnifiedIndexer.Create(target, args));
        }
        private static UnifiedExpression CreateOpAsgn1(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "op_asgn1");
            var expression = UnifiedIndexer.Create(
                CreateExpresion(node.FirstElement()),
                CreateArglist(node.NthElement(1)));

            return(UnifiedBinaryExpression.Create(
                       expression,
                       Sign2BinaryOperator[node.NthElement(2).Value + "="].DeepCopy
                           (),
                       CreateExpresion(node.LastElement())));
        }
 public override bool Visit(UnifiedIndexer element, VisitorArgument arg)
 {
     element.Target.TryAccept(this, arg);
     element.Arguments.TryAccept(this, arg.Set(Bracket));
     return false;
 }
        public static UnifiedExpression CreatePostfixExpression(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "postfix_expression");

            /*
             * postfix_expression
             * :   primary_expression
             *      (   '[' expression ']'
             |   '(' ')'
             |   '(' argument_expression_list ')'
             |   '.' IDENTIFIER
             |   '->' IDENTIFIER
             |   '++'
             |   '--'
             |      )*
             */

            var result =
                CreatePrimaryExpression(node.Element("primary_expression"));
            var elements = node.Elements().Skip(1);             //先頭以外のすべての要素を取得
            var length   = elements.Count();

            for (var i = 0; i < length; i++)
            {
                switch (elements.ElementAt(i++).Value)
                {
                case "[":
                    result = UnifiedIndexer.Create(
                        result,
                        UnifiedSet <UnifiedArgument> .Create(
                            UnifiedArgument.Create(
                                CreateExpression(
                                    elements.ElementAt(i++)).
                                ElementAt(0))));
                    i++;                     // ']'読み飛ばし
                    break;

                case "(":
                    if (elements.ElementAt(i).Name == "argument_expression_list")
                    {
                        result = UnifiedCall.Create(
                            result,
                            CreateArgumentExpressionList(
                                elements.ElementAt(i++)));
                    }
                    else
                    {
                        result = UnifiedCall.Create(
                            result, UnifiedSet <UnifiedArgument> .Create());
                    }
                    i++;                     // ')'読み飛ばし
                    break;

                case ".":
                    result = UnifiedProperty.Create(
                        ".", result,
                        UnifiedIdentifier.CreateVariable(
                            elements.ElementAt(i++).Value));
                    break;

                case "->":
                    result = UnifiedProperty.Create(
                        "->", result,
                        UnifiedIdentifier.CreateVariable(
                            elements.ElementAt(i++).Value));
                    // TODO ポインタ型に展開してから処理するのか?
                    break;

                case "++":
                    result = UnifiedUnaryExpression.Create(
                        result,
                        UnifiedUnaryOperator.Create(
                            "++",
                            UnifiedUnaryOperatorKind.PostIncrementAssign));
                    break;

                case "--":
                    result = UnifiedUnaryExpression.Create(
                        result,
                        UnifiedUnaryOperator.Create(
                            "--",
                            UnifiedUnaryOperatorKind.PostDecrementAssign));
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            return(result);
        }
 private static UnifiedExpression CreateMathFunctionStylePhrase(MathFunctionStylePhrase phrase)
 {
     return(UnifiedIndexer.Create(CreatePhrase(phrase.ParameterPhrase)));
 }
 public override bool Visit(UnifiedIndexer element, VisitorArgument arg)
 {
     element.Target.TryAccept(this, arg);
     element.Arguments.TryAccept(this, arg.Set(Bracket));
     return(false);
 }