//context should be init block if init exists
        public static ForLoopNode Create(ContextNode context, CodeBlockNode init, ExpressionNode condition, CodeBlockNode increment, CodeBlockNode body, SequencePoint point)
        {
            if (init == null)
            {
                init = CodeBlockNode.Create(context, point);
            }

            if (condition == null)
            {
                condition = LiteralNode.Create(context, true, point);
            }

            if (increment == null)
            {
                increment = CodeBlockNode.Create(context, point);
            }

            if (!(condition.IsGettable && condition.ExpressionReturnType.IsAssignableTo(context.Parser.Bool)))
            {
                ErrorCode.InvalidCondition.ReportAndThrow(point, "Condition must be a gettable boolean expression");
            }

            return(new ForLoopNode(init, condition, increment, body, point));
        }
Example #2
0
        private static IEnumerable <TypeReference> GetImplicitConversions(Parser parser, LiteralNode node)
        {
            var type = node.ExpressionReturnType;

            if (type.IsIntegerType())
            {
                BigInteger converted;
                if (type.IsSignedInteger())
                {
                    converted = new BigInteger((long)node.Value);
                }
                else
                {
                    converted = new BigInteger((ulong)node.Value);
                }
                return(GetImplicitConversions(parser.ProjectParser, converted));
            }
            else
            {
                return(Enumerable.Empty <TypeReference>());
            }
        }
Example #3
0
 private static LiteralNode ConvertLiteral(LiteralNode node, TypeReference type)
 {
     return(new LiteralNode(node.Value.Value, type, node.SequencePoint));
 }
 private static IReadOnlyList <LiteralNode> CreateArrayDims(ContextNode context, SequencePoint point, params int[] dims)
 {
     return(dims.Select(dim => LiteralNode.Create(context, dim, point)).ToArray());
 }