Exemplo n.º 1
0
        public void WriteTo(TranslationBuffer buffer)
        {
            if (_hasVariables)
            {
                foreach (var parametersByType in _variables)
                {
                    parametersByType.Key.WriteTo(buffer);
                    buffer.WriteSpaceToTranslation();
                    parametersByType.Value.WriteTo(buffer);
                    buffer.WriteToTranslation(';');
                    buffer.WriteNewLineToTranslation();
                }

                switch (_statements[0].NodeType)
                {
                case Conditional when !ConditionalTranslation.IsTernary(_statements[0].Expression):
                case Switch:
                    buffer.WriteNewLineToTranslation();
                    break;
                }
            }

            for (var i = 0; ;)
            {
                _statements[i].WriteTo(buffer);

                if (++i == _statementCount)
                {
                    break;
                }

                buffer.WriteNewLineToTranslation();
            }
        }
        public ITranslation GetTranslationFor(Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            switch (expression.NodeType)
            {
            case Decrement:
            case Increment:
            case IsFalse:
            case IsTrue:
            case OnesComplement:
            case PostDecrementAssign:
            case PostIncrementAssign:
            case PreDecrementAssign:
            case PreIncrementAssign:
            case UnaryPlus:
                return(new UnaryTranslation((UnaryExpression)expression, this));

            case Add:
            case AddChecked:
            case And:
            case AndAlso:
            case Coalesce:
            case Divide:
            case Equal:
            case ExclusiveOr:
            case GreaterThan:
            case GreaterThanOrEqual:
            case LeftShift:
            case LessThan:
            case LessThanOrEqual:
            case Modulo:
            case Multiply:
            case MultiplyChecked:
            case NotEqual:
            case Or:
            case OrElse:
            case Power:
            case RightShift:
            case Subtract:
            case SubtractChecked:
                return(BinaryTranslation.For((BinaryExpression)expression, this));

            case AddAssign:
            case AddAssignChecked:
            case AndAssign:
            case Assign:
            case DivideAssign:
            case ExclusiveOrAssign:
            case LeftShiftAssign:
            case ModuloAssign:
            case MultiplyAssign:
            case MultiplyAssignChecked:
            case OrAssign:
            case PowerAssign:
            case RightShiftAssign:
            case SubtractAssign:
            case SubtractAssignChecked:
                return(new AssignmentTranslation((BinaryExpression)expression, this));

            case ArrayIndex:
                return(new IndexAccessTranslation((BinaryExpression)expression, this));

            case ArrayLength:
                return(new ArrayLengthTranslation((UnaryExpression)expression, this));

            case Block:
                return(new BlockTranslation((BlockExpression)expression, this));

            case Call:
                return(MethodCallTranslation.For((MethodCallExpression)expression, this));

            case Conditional:
                return(ConditionalTranslation.For((ConditionalExpression)expression, this));

            case Constant:
                return(ConstantTranslation.For((ConstantExpression)expression, this));

            case ExpressionType.Convert:
            case ConvertChecked:
            case TypeAs:
            case Unbox:
                return(CastTranslation.For((UnaryExpression)expression, this));

            case DebugInfo:
                return(DebugInfoTranslation.For((DebugInfoExpression)expression, this));

            case Default:
                return(new DefaultValueTranslation(expression, this));

            case Dynamic:
                return(DynamicTranslation.For((DynamicExpression)expression, this));

            case Extension:
                return(new FixedValueTranslation(expression, this));

            case Goto:
                return(GotoTranslation.For((GotoExpression)expression, this));

            case Index:
                return(new IndexAccessTranslation((IndexExpression)expression, this));

            case Invoke:
                return(MethodCallTranslation.For((InvocationExpression)expression, this));

            case Label:
                return(new LabelTranslation((LabelExpression)expression, this));

            case Lambda:
                return(new LambdaTranslation((LambdaExpression)expression, this));

            case ListInit:
                return(ListInitialisationTranslation.For((ListInitExpression)expression, this));

            case Loop:
                return(new LoopTranslation((LoopExpression)expression, this));

            case MemberAccess:
                return(new MemberAccessTranslation((MemberExpression)expression, this));

            case MemberInit:
                return(MemberInitialisationTranslation.For((MemberInitExpression)expression, this));

            case Negate:
            case NegateChecked:
            case Not:
                return(new NegationTranslation((UnaryExpression)expression, this));

            case New:
                return(NewingTranslation.For((NewExpression)expression, this));

            case NewArrayBounds:
                return(new NewArrayTranslation((NewArrayExpression)expression, this));

            case NewArrayInit:
                return(ArrayInitialisationTranslation.For((NewArrayExpression)expression, this));

            case Parameter:
                return(ParameterTranslation.For((ParameterExpression)expression, this));

            case Quote:
                return(QuotedLambdaTranslation.For((UnaryExpression)expression, this));

            case RuntimeVariables:
                return(RuntimeVariablesTranslation.For((RuntimeVariablesExpression)expression, this));

            case Switch:
                return(new SwitchTranslation((SwitchExpression)expression, this));

            case Throw:
                return(new ThrowTranslation((UnaryExpression)expression, this));

            case Try:
                return(new TryCatchTranslation((TryExpression)expression, this));

            case TypeEqual:
                return(TypeEqualTranslation.For((TypeBinaryExpression)expression, this));

            case TypeIs:
                return(CastTranslation.For((TypeBinaryExpression)expression, this));
            }

            return(new FixedValueTranslation(expression, this));
        }
Exemplo n.º 3
0
 private bool WriteBlankLineBefore()
 {
     return((NodeType == Label) ||
            ((NodeType == Conditional) && !ConditionalTranslation.IsTernary(Expression)));
 }