Пример #1
0
        public override AstNode Visit(NewArrayExpression node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Visit each size expresion.
            Expression sizeExpr = node.GetSize();
            IChelaType coercionType = node.GetCoercionType();
            while(sizeExpr != null)
            {
                // Visit the size expression.
                sizeExpr.Accept(this);

                // Coerce the size.
                IChelaType sizeType = sizeExpr.GetNodeType();
                if(sizeType != coercionType)
                    Cast(node, sizeExpr.GetNodeValue(), sizeType, coercionType);

                // Process the next size.
                sizeExpr = (Expression)sizeExpr.GetNext();
            }

            // Create the array
            IChelaType arrayType = node.GetArrayType();
            builder.CreateNewArray(arrayType);

            // Initialize elements.
            Expression init = (Expression)node.GetInitializers();
            if(init != null)
                InitializeArrayElements(init, node.GetDimensions(), 0, arrayType, node.GetInitCoercionType(), init);

            return builder.EndNode();
        }