protected override EV3Type CalculateType()
        {
            string propertyName      = ParentExpression.FullName().ToUpper();
            EV3SubDefinitionBase sub = Context.FindMethod(propertyName);

            if (sub != null)
            {
                return(sub.ReturnType);
            }

            return(EV3Type.Unknown);
        }
Example #2
0
        public override string Compile(TextWriter writer, IEV3Variable variable)
        {
            EV3SubDefinitionBase sub = Context.FindMethod(Value);

            if (sub != null)
            {
                return(CompileMethodCall(writer, variable, sub));
            }

            AddError($"Unknown method call to {ParentExpression.FullName()}");
            return("");
        }
        public override string Compile(TextWriter writer, IEV3Variable variable)
        {
            EV3SubDefinitionBase sub = Context.FindMethod(Value);

            if (sub != null)
            {
                using (var tempVariables = Context.UseTempVariables())
                {
                    if (variable.Type.IsArray() && !sub.ReturnType.IsArray())
                    {
                        variable = tempVariables.CreateVariable(variable.Type.BaseType());
                    }
                    return(sub.Compile(writer, Context, new string[0], variable.Ev3Name));
                }
            }
            else
            {
                AddError($"Unknown property {ParentExpression.FullName()}");
            }

            return(variable.Ev3Name);
        }
Example #4
0
        private string CompileMethodCall(TextWriter writer, IEV3Variable variable, EV3SubDefinitionBase sub)
        {
            if (sub.ParameterTypes.Count != ParentExpression.Arguments.Count)
            {
                AddError($"Incorrect number of parameters. Expected {sub.ParameterTypes.Count}.");
                return("");
            }

            using (var tempVariables = Context.UseTempVariables())
            {
                string[] arguments = ParentExpression.Arguments
                                     .Select(a => a.Compiler())
                                     .Zip(sub.ParameterTypes, (c, t) => new { Compiler = c, Type = t })
                                     .Select(c => CompileWithConvert(writer, c.Compiler, c.Type, tempVariables)).ToArray();

                if (variable != null && variable.Type.IsArray() && !sub.ReturnType.IsArray())
                {
                    variable = tempVariables.CreateVariable(variable.Type.BaseType());
                }

                return(sub.Compile(writer, Context, arguments, variable?.Ev3Name));
            }
        }