Exemple #1
0
        public static IExpressionNode GetConvertedOrOriginOrThrow(IExpressionNode origin, FunnyType to)
        {
            if (origin.Type == to)
            {
                return(origin);
            }
            var converter = VarTypeConverter.GetConverterOrThrow(origin.Type, to, origin.Interval);

            return(new CastExpressionNode(origin, to, converter, origin.Interval));
        }
        private IExpressionNode CreateFunctionCall(IFunCallSyntaxNode node, IConcreteFunction function)
        {
            var children  = node.Args.SelectToArray(ReadNode);
            var converted = function.CreateWithConvertionOrThrow(children, node.Interval);

            if (converted.Type != node.OutputType)
            {
                var converter = VarTypeConverter.GetConverterOrThrow(converted.Type, node.OutputType, node.Interval);
                return(new CastExpressionNode(converted, node.OutputType, converter, node.Interval));
            }
            else
            {
                return(converted);
            }
        }
Exemple #3
0
        public IExpressionNode CreateWithConvertionOrThrow(IList <IExpressionNode> children, Interval interval)
        {
            var i          = 0;
            var argNode    = children[0];
            var toType     = ArgTypes[i];
            var fromType   = argNode.Type;
            var castedNode = argNode;

            if (fromType != toType)
            {
                var converter = VarTypeConverter.GetConverterOrThrow(fromType, toType, argNode.Interval);
                castedNode = new CastExpressionNode(argNode, toType, converter, argNode.Interval);
            }

            i++;

            return(new FunOfSingleArgExpressionNode(this, castedNode, interval));
        }
        public static IExpressionNode BuildExpression(
            ISyntaxNode node,
            IFunctionDictionary functions,
            FunnyType outputType,
            VariableDictionary variables,
            TypeInferenceResults typeInferenceResults,
            TicTypesConverter typesConverter)
        {
            var result = node.Accept(
                new ExpressionBuilderVisitor(functions, variables, typeInferenceResults, typesConverter));

            if (result.Type == outputType)
            {
                return(result);
            }
            var converter = VarTypeConverter.GetConverterOrThrow(result.Type, outputType, node.Interval);

            return(new CastExpressionNode(result, outputType, converter, node.Interval));
        }
Exemple #5
0
        public IExpressionNode CreateWithConvertionOrThrow(IList <IExpressionNode> children, Interval interval)
        {
            var castedChildren = new IExpressionNode[children.Count];

            var i = 0;

            foreach (var argNode in children)
            {
                var toType     = ArgTypes[i];
                var fromType   = argNode.Type;
                var castedNode = argNode;

                if (fromType != toType)
                {
                    var converter = VarTypeConverter.GetConverterOrThrow(fromType, toType, argNode.Interval);
                    castedNode = new CastExpressionNode(argNode, toType, converter, argNode.Interval);
                }

                castedChildren[i] = castedNode;
                i++;
            }

            return(new FunOfTwoArgsExpressionNode(this, castedChildren[0], castedChildren[1], interval));
        }