public override bool Visit(AstArrayInitializerStatement node)
 {
     ErrorIfIsNull(node.Id);
     ErrorIfIsNull(node.Values);
     return true;
 }
 public override bool Visit(AstArrayInitializerStatement node)
 {
     return true;
 }
Beispiel #3
0
        // #ASSIGN_STATEMENT ID ASSIGNMENT #ARRAY_INITIALIZER
        private void ConstructArrayInitializerStatement()
        {
            var vals = new List<AstIntegerValueExpression>();

            var curr = nodes.Peek() as AstIntegerValueExpression;
            while (curr != null)
            {
                nodes.Pop();
                vals.Add(curr);
                curr = nodes.Peek() as AstIntegerValueExpression;
            }

            var id = nodes.Pop() as AstIdExpression;

            var node = new AstArrayInitializerStatement(id, vals);
            PushNode(node);
        }
        public override bool Visit(AstArrayInitializerStatement node)
        {
            var tableSymbol = table.Lookup(node.Id.Id);
            List<int> valueList = node.GetValuesList();
            for (var i = 0; i < valueList.Count(); i++)
            {
                codeStream.WriteLine(CreateUnnamedVariable() + " = getelementptr " + GetArrayId(tableSymbol.Size as int[]) + "* @" +
                tableSymbol.Name + ", i32 0, i32 " + i.ToString());
                codeStream.WriteLine("store i32 " + valueList[i].ToString() + ", i32* " + GetCurrUnnamedVariable());
            }

            return false;
        }
        public override bool Visit(AstArrayInitializerStatement node)
        {
            var s = table.Lookup(node.Id.Id);
            if (s == null)
            {
                DispatchError(node.Id.TextPosition, "Unknown variable " + node.Id.Id);
                return true;
            }

            if (!Symbol.IsArray(s))
            {
                DispatchError(node.Id.TextPosition, "variable " + node.Id.Id + " is not array");
                return true;
            }

            var size = s.Size as int[];

            if (size.Length > 1)
            {
                DispatchError(node.Id.TextPosition, "only linear array can have an initializer");
                return true;
            }
            var valsCount = node.Values.Count;
            if (s.FlatSize > 0 && valsCount > s.FlatSize)
            {
                DispatchError(node.Values[0].TextPosition, "values count must be lesser than array size (" + s.Size + ")");
            }

            return true;
        }
 public abstract bool Visit(AstArrayInitializerStatement node);