private IndexAccessTranslation(ITranslation subject, ParameterSetTranslation parameters)
 {
     _subject        = subject;
     _parameters     = parameters;
     TranslationSize = subject.TranslationSize + parameters.TranslationSize + 2;
     FormattingSize  = subject.FormattingSize + parameters.FormattingSize;
 }
        private static IDictionary <ITranslation, ParameterSetTranslation> GetVariableDeclarations(
            BlockExpression block,
            ITranslationContext context)
        {
            if (block.Variables.Count == 0)
            {
                return(EmptyDictionary <ITranslation, ParameterSetTranslation> .Instance);
            }

            var variablesByType = block
                                  .Variables
                                  .Except(context.InlineOutputVariables)
                                  .Except(context.JoinedAssignmentVariables)
                                  .GroupBy(v => v.Type)
                                  .ToArray();

            if (variablesByType.Length == 0)
            {
                return(EmptyDictionary <ITranslation, ParameterSetTranslation> .Instance);
            }

            return(variablesByType.ToDictionary(
                       grp => (ITranslation)context.GetTranslationFor(grp.Key),
                       grp => ParameterSetTranslation.For(grp.ToList(), context)
                       .WithoutParentheses()
                       .WithoutTypeNames(context)));
        }
Ejemplo n.º 3
0
 protected NewingTranslationBase(NewExpression newing, ITranslationContext context)
 {
     Parameters = ParameterSetTranslation.For(
         new CtorInfoWrapper(newing.Constructor),
         newing.Arguments,
         context);
 }
Ejemplo n.º 4
0
 public MethodInvocationTranslatable(IMethod method, ParameterSetTranslation parameters, ITranslationContext context)
 {
     _method     = method;
     _parameters = parameters;
     _explicitGenericArguments = GetRequiredExplicitGenericArguments(context, out var totalLength);
     EstimatedSize             = method.Name.Length + totalLength + parameters.EstimatedSize;
 }
Ejemplo n.º 5
0
 public IndexAccessTranslation(ITranslation subject, ParameterSetTranslation parameters, Type indexValueType)
 {
     NodeType      = ExpressionType.Call;
     Type          = indexValueType;
     _subject      = subject;
     _parameters   = parameters;
     EstimatedSize = GetEstimatedSize();
 }
 public IndexAccessTranslation(
     ITranslation subject,
     ParameterSetTranslation parameters,
     Type indexValueType)
     : this(subject, parameters)
 {
     NodeType = ExpressionType.Call;
     Type     = indexValueType;
 }
 private IndexAccessTranslation(
     Expression subject,
     ICollection <Expression> arguments,
     ITranslationContext context)
     : this(
         context.GetTranslationFor(subject),
         ParameterSetTranslation.For(arguments, context))
 {
 }
Ejemplo n.º 8
0
 private IndexAccessTranslation(
     Expression subject,
     ICollection <Expression> arguments,
     ITranslationContext context)
 {
     _subject      = context.GetTranslationFor(subject);
     _parameters   = new ParameterSetTranslation(arguments, context);
     EstimatedSize = GetEstimatedSize();
 }
Ejemplo n.º 9
0
        public static ITranslation For(MethodCallExpression methodCall, ITranslationContext context)
        {
            var method     = new BclMethodWrapper(methodCall.Method);
            var parameters = new ParameterSetTranslation(method, methodCall.Arguments, context);

            if (context.Settings.ConvertPropertyMethodsToSimpleSyntax && IsDirectPropertyMethodCall(methodCall, out var propertyInfo))
            {
                var objTranslation = context.GetTranslationFor(methodCall.Object);
                var propertyAccess = new MemberAccessTranslation(objTranslation, propertyInfo.Name, propertyInfo.PropertyType);

                var isAssignment = methodCall.Method.ReturnType == typeof(void);
                if (isAssignment)
                {
                    var valueExpr = methodCall.Arguments.First();
                    return(new AssignmentTranslation(Assign, propertyAccess, valueExpr, context));
                }
                else
                {
                    return(propertyAccess);
                }
            }

            if (IsStringConcatCall(methodCall))
            {
                return(new StringConcatenationTranslation(Call, methodCall.Arguments, context));
            }

            if (methodCall.Method.IsImplicitOperator())
            {
                return(new CodeBlockTranslation(parameters[0]).WithNodeType(Call));
            }

            var subject = GetSubjectTranslation(methodCall, context);

            if (IsIndexedPropertyAccess(methodCall))
            {
                return(new IndexAccessTranslation(subject, parameters, methodCall.Type));
            }

            parameters = parameters.WithParentheses();

            if (methodCall.Method.IsExplicitOperator())
            {
                return(CastTranslation.ForExplicitOperator(
                           parameters[0],
                           context.GetTranslationFor(methodCall.Method.ReturnType)));
            }

            var methodCallTranslation = new StandardMethodCallTranslation(Call, subject, method, parameters, context);

            if (context.IsPartOfMethodCallChain(methodCall))
            {
                methodCallTranslation.AsPartOfMethodCallChain();
            }

            return(methodCallTranslation);
        }
        public LambdaTranslation(LambdaExpression lambda, ITranslationContext context)
        {
            Type             = lambda.Type;
            _parameters      = new ParameterSetTranslation(lambda.Parameters, context);
            _bodyTranslation = context.GetCodeBlockTranslationFor(lambda.Body);
            EstimatedSize    = GetEstimatedSize();

            if (_bodyTranslation.IsMultiStatement == false)
            {
                _bodyTranslation.WithoutTermination();
            }
        }
Ejemplo n.º 11
0
 public StandardMethodCallTranslation(
     ExpressionType nodeType,
     ITranslation subjectTranslation,
     IMethod method,
     ParameterSetTranslation parameters,
     ITranslationContext context)
 {
     NodeType                      = nodeType;
     _subjectTranslation           = subjectTranslation;
     _methodInvocationTranslatable = new MethodInvocationTranslatable(method, parameters, context);
     EstimatedSize                 = GetEstimatedSize();
 }
Ejemplo n.º 12
0
        public static ITranslation For(MethodCallExpression methodCall, ITranslationContext context)
        {
            if (methodCall.Method.IsPropertyGetterOrSetterCall(out var property))
            {
                var getterTranslation = new PropertyGetterTranslation(methodCall, property, context);

                if (methodCall.Method.ReturnType != typeof(void))
                {
                    return(getterTranslation);
                }

                return(new PropertySetterTranslation(methodCall, getterTranslation, context));
            }

            if (IsStringConcatCall(methodCall))
            {
                return(new StringConcatenationTranslation(Call, methodCall.Arguments, context));
            }

            var method     = new BclMethodWrapper(methodCall.Method);
            var parameters = new ParameterSetTranslation(method, methodCall.Arguments, context);

            if (methodCall.Method.IsImplicitOperator())
            {
                return(new CodeBlockTranslation(parameters[0]).WithNodeType(Call));
            }

            var subject = GetSubjectTranslation(methodCall, context);

            if (IsIndexedPropertyAccess(methodCall))
            {
                return(new IndexAccessTranslation(subject, parameters, methodCall.Type));
            }

            parameters = parameters.WithParentheses();

            if (methodCall.Method.IsExplicitOperator())
            {
                return(CastTranslation.ForExplicitOperator(
                           parameters[0],
                           context.GetTranslationFor(methodCall.Method.ReturnType)));
            }

            var methodCallTranslation = new StandardMethodCallTranslation(Call, subject, method, parameters, context);

            if (context.IsPartOfMethodCallChain(methodCall))
            {
                methodCallTranslation.AsPartOfMethodCallChain();
            }

            return(methodCallTranslation);
        }
Ejemplo n.º 13
0
            public MethodInvocationTranslation(IMethod method, ParameterSetTranslation parameters, ITranslationContext context)
            {
                _method     = method;
                _parameters = parameters;
                _explicitGenericArguments     = GetRequiredExplicitGenericArguments(context, out var translationsSize);
                _explicitGenericArgumentCount = _explicitGenericArguments.Length;

                TranslationSize = method.Name.Length + translationsSize + parameters.TranslationSize;

                FormattingSize =
                    _explicitGenericArgumentCount * context.GetTypeNameFormattingSize() +
                    parameters.FormattingSize;
            }
Ejemplo n.º 14
0
 public static ITranslation ForDynamicMethodCall(
     ITranslation subjectTranslation,
     IMethod method,
     ICollection <Expression> arguments,
     ITranslationContext context)
 {
     return(new StandardMethodCallTranslation(
                Dynamic,
                subjectTranslation,
                method,
                ParameterSetTranslation.For(arguments, context).WithParentheses(),
                context));
 }
Ejemplo n.º 15
0
        public static ITranslation For(InvocationExpression invocation, ITranslationContext context)
        {
            var invocationMethod = invocation.Expression.Type.GetPublicInstanceMethod("Invoke");

            var method     = new BclMethodWrapper(invocationMethod);
            var parameters = new ParameterSetTranslation(method, invocation.Arguments, context).WithParentheses();
            var subject    = context.GetTranslationFor(invocation.Expression);

            if (subject.NodeType == Lambda)
            {
                subject = subject.WithParentheses();
            }

            return(new StandardMethodCallTranslation(Invoke, subject, method, parameters, context));
        }
        public LambdaTranslation(LambdaExpression lambda, ITranslationContext context)
        {
            Type             = lambda.Type;
            _parameters      = ParameterSetTranslation.For(lambda.Parameters, context);
            _bodyTranslation = context.GetCodeBlockTranslationFor(lambda.Body);

            TranslationSize =
                _parameters.TranslationSize +
                _fatArrow.Length +
                _bodyTranslation.TranslationSize;

            FormattingSize = _parameters.FormattingSize + _bodyTranslation.FormattingSize;

            if (_bodyTranslation.IsMultiStatement == false)
            {
                _bodyTranslation.WithoutTermination();
            }
        }
Ejemplo n.º 17
0
            public StandardMethodCallTranslation(
                ExpressionType nodeType,
                ITranslation subjectTranslation,
                IMethod method,
                ParameterSetTranslation parameters,
                ITranslationContext context)
            {
                _context                     = context;
                NodeType                     = nodeType;
                _subjectTranslation          = subjectTranslation;
                _methodInvocationTranslation = new MethodInvocationTranslation(method, parameters, context);

                TranslationSize =
                    _subjectTranslation.TranslationSize +
                    ".".Length +
                    _methodInvocationTranslation.TranslationSize;

                FormattingSize =
                    _subjectTranslation.FormattingSize +
                    _methodInvocationTranslation.FormattingSize;
            }
Ejemplo n.º 18
0
 public static ITranslation For(RuntimeVariablesExpression runtimeVariables, ITranslationContext context)
 {
     return(ParameterSetTranslation
            .For(runtimeVariables.Variables, context)
            .WithTypes(ExpressionType.RuntimeVariables, runtimeVariables.Type));
 }
Ejemplo n.º 19
0
 protected NewingTranslationBase(NewExpression newing, ITranslationContext context)
 {
     Parameters = new ParameterSetTranslation(newing.Arguments, context);
 }