Beispiel #1
0
        YExpr ProcessExpr(AssignmentExpressionSyntax assignmentExpression)
        {
            YExpr left  = ProcessExpr(assignmentExpression.Left);
            YExpr right = ProcessExpr(assignmentExpression.Right);

            return(new YAssign(left, right));
        }
Beispiel #2
0
        YStatement ProcessStatement(IfStatementSyntax ifStatement)
        {
            YExpr      condition     = ProcessExpr(ifStatement.Condition);
            YStatement statement     = ProcessStatement(ifStatement.Statement);
            YStatement elseStatement = ProcessStatement(ifStatement.Else.Statement);

            return(new YIf(condition, statement, elseStatement));
        }
Beispiel #3
0
        YExpr ProcessExpr(MemberAccessExpressionSyntax memberAccessExpression)
        {
            YExpr expr = ProcessExpr(memberAccessExpression.Expression);

            return(new YMemberAccessExpr(
                       expr,
                       memberAccessExpression.Name.Identifier.ToString()
                       ));
        }
Beispiel #4
0
        /// <summary>
        /// Unwrap expression to string.
        /// </summary>
        static public void AppendEx(this StringBuilder builder, YExpr expr)
        {
            if (expr is YConstExpr)
            {
                builder.Append("" + expr);
            }
            else if (expr is YThisExpr)
            {
                builder.Append("this");
            }
            else if (expr is YMemberAccessExpr)
            {
                var memberAccess = (YMemberAccessExpr)expr;

                AppendEx(builder, memberAccess.Expression);
                builder.Append("->"); // But what with "this."?
                builder.Append(memberAccess.Name);
            }
            else if (expr is YIdentifierExpr)
            {
                builder.Append(((YIdentifierExpr)expr).Name);
            }
            else if (expr is YBinaryExpr)
            {
                var binary = (YBinaryExpr)expr;

                AppendEx(builder, binary.Left);
                builder.Append(" ");
                AppendEx(builder, binary.Operator);
                builder.Append(" ");
                AppendEx(builder, binary.Right);
            }
            else if (expr is YLiteralExpr)
            {
                var literal = (YLiteralExpr)expr;
                if (literal == YLiteralExpr.Null)
                {
                    builder.Append("nullptr");
                }
                else
                {
                    builder.Append(literal.Value);
                }
            }
            else if (expr is YPrefixUnaryExpr)
            {
                var prefixUnari = (YPrefixUnaryExpr)expr;

                AppendEx(builder, prefixUnari.Operator);
                AppendEx(builder, prefixUnari.Operand);
            }
            else if (expr is YInvocation)
            {
                var invocation = (YInvocation)expr;

                AppendEx(builder, invocation.Expression);

                // no arguments
                builder.Append("()");
            }
            else if (expr is YAssign)
            {
                var assign = (YAssign)expr;

                AppendEx(builder, assign.Left);
                builder.Append("=");
                AppendEx(builder, assign.Right);
            }
        }
Beispiel #5
0
 public YMemberAccessExpr(YExpr expression, string name)
 {
     Expression = expression;
     Name       = name;
 }
Beispiel #6
0
 public YIf(YExpr condition, YStatement statement, YStatement elseStatement)
 {
     Condition     = condition;
     Statement     = statement;
     ElseStatement = elseStatement;
 }
Beispiel #7
0
 public YAssign(YExpr left, YExpr right)
 {
     Left  = left;
     Right = right;
 }
Beispiel #8
0
 public YPrefixUnaryExpr(YOperator @operator, YExpr operand)
 {
     Operator = @operator;
     Operand  = operand;
 }
Beispiel #9
0
 public YInvocation(YExpr expression)
 {
     Expression = expression;
 }
Beispiel #10
0
 public YBinaryExpr(YExpr left, YExpr right, YOperator operation)
 {
     Left     = left;
     Right    = right;
     Operator = operation;
 }
Beispiel #11
0
 public YReturn(YExpr value)
 {
     Value = value;
 }
Beispiel #12
0
 public YExprStatement(YExpr expression)
 {
     Expression = expression;
 }