Пример #1
0
 public ArrayCreationExpression(DataType element_type, int rank, InitializerList initializer_list, SourceReference source_reference)
 {
     this.element_type     = element_type;
     this.rank             = rank;
     this.initializer_list = initializer_list;
     this.source_reference = source_reference;
 }
Пример #2
0
        private int create_sizes_from_initializer_list(CodeContext context, InitializerList il, int rank, List <Literal> sl)
        {
            if (sl.Count == (this.rank - rank))
            {
                // only add size if this is the first initializer list of the current dimension
                var init = new IntegerLiteral(il.size.ToString(), il.source_reference);
                init.check(context);
                sl.Add(init);
            }

            int subsize = -1;

            foreach (Expression e in il.get_initializers())
            {
                if (e is InitializerList)
                {
                    if (rank == 1)
                    {
                        il.error = true;
                        e.error  = true;
                        Report.error(e.source_reference, "Expected array element, got array initializer list");
                        return(-1);
                    }
                    int size = create_sizes_from_initializer_list(context, (InitializerList)e, rank - 1, sl);
                    if (size == -1)
                    {
                        return(-1);
                    }
                    if (subsize >= 0 && subsize != size)
                    {
                        il.error = true;
                        Report.error(il.source_reference, "Expected initializer list of size %d, got size %d".printf(subsize, size));
                        return(-1);
                    }
                    else
                    {
                        subsize = size;
                    }
                }
                else
                {
                    if (rank != 1)
                    {
                        il.error = true;
                        e.error  = true;
                        Report.error(e.source_reference, "Expected array initializer list, got array element");
                        return(-1);
                    }
                }
            }
            return(il.size);
        }