protected virtual void VisitVarArrayDeclaration(VarArrayDeclarationNode node)
 {
     Visit(node.TypeNameNode);
     Visit(node.NameNode);
     Visit(node.ArraySizeNode);
     if (node.ElementNodes != null)
     {
         Visit(node.ElementNodes);
     }
 }
Exemplo n.º 2
0
 protected virtual T VisitVarArrayDeclaration(VarArrayDeclarationNode node)
 {
     Visit(node.TypeNameNode);
     Visit(node.NameNode);
     Visit(node.ArraySizeNode);
     if (node.ElementNodes != null)
     {
         Visit(node.ElementNodes);
     }
     return(DefaultResult);
 }
Exemplo n.º 3
0
        private VarDeclarationsTemporaryNode GetVarDeclarationsTemporaryNode(DaedalusParser.VarDeclContext varDeclContext)
        {
            NameNode typeNameNode = new NameNode(GetLocation(varDeclContext.dataType()), varDeclContext.dataType().GetText());

            List <DeclarationNode> varDeclarationNodes = new List <DeclarationNode>();

            foreach (IParseTree childContext in varDeclContext.children)
            {
                if (childContext is DaedalusParser.VarValueDeclContext varValueDeclContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = varValueDeclContext.nameNode();
                    NameNode nameNode = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());

                    ExpressionNode rightSideNode = null;
                    if (varValueDeclContext.varValueAssignment() != null)
                    {
                        rightSideNode = (ExpressionNode)Visit(varValueDeclContext.varValueAssignment().expression());                          // TODO check if null
                    }

                    varDeclarationNodes.Add(new VarDeclarationNode(GetLocation(varValueDeclContext), typeNameNode, nameNode, rightSideNode));
                }
                else if (childContext is DaedalusParser.VarArrayDeclContext varArrayDeclContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = varArrayDeclContext.nameNode();
                    NameNode       nameNode      = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode arraySizeNode = (ExpressionNode)VisitArraySize(varArrayDeclContext.arraySize());


                    List <ExpressionNode> elementNodes = null;
                    if (varArrayDeclContext.varArrayAssignment() != null)
                    {
                        elementNodes = new List <ExpressionNode>();
                        foreach (DaedalusParser.ExpressionContext expressionContext in varArrayDeclContext.varArrayAssignment().expression())
                        {
                            elementNodes.Add((ExpressionNode)Visit(expressionContext));
                        }
                    }

                    VarArrayDeclarationNode varArrayDeclarationNode =
                        new VarArrayDeclarationNode(GetLocation(nameNodeContext), typeNameNode, nameNode, arraySizeNode, elementNodes);                         // TODO check if null
                    _arrayDeclarationNodes.Add(varArrayDeclarationNode);
                    varDeclarationNodes.Add(varArrayDeclarationNode);
                }
            }
            return(new VarDeclarationsTemporaryNode(GetLocation(varDeclContext), varDeclarationNodes));
        }
Exemplo n.º 4
0
        protected override NodeValue VisitVarArrayDeclaration(VarArrayDeclarationNode node)
        {
            if (node.ArraySizeValue is UndefinedValue)
            {
                return(new UndefinedValue());
            }

            if (node.Annotations.Count > 0)
            {
                return(new UndefinedValue());
            }
            node.ArraySizeValue = Visit(node.ArraySizeNode);

            switch (node.ArraySizeValue)
            {
            case UndefinedValue _:
                break;

            case IntValue intValue:
                if (intValue.Value == 0)
                {
                    node.ArraySizeNode.Annotations.Add(new ArraySizeEqualsZeroError(node.NameNode.Value));
                }
                else if (intValue.Value > 4095)
                {
                    node.ArraySizeNode.Annotations.Add(new TooBigArraySizeError());
                }
                else if (node.ElementNodes != null && intValue.Value < node.ElementNodes.Count)     // i.e. if you have array of size 2, you should be able to assign only 1 element
                {
                    node.ArraySizeNode.Annotations.Add(new InconsistentArraySizeError(node.NameNode.Value, (int)intValue.Value, node.ElementNodes.Count));
                }

                ((IArraySymbol)node.Symbol).Size = Convert.ToInt32(intValue.Value);

                break;

            default:
                node.ArraySizeNode.Annotations.Add(new ArraySizeNotConstIntegerError());
                break;
            }
            return(null);
        }
Exemplo n.º 5
0
 protected override void VisitVarArrayDeclaration(VarArrayDeclarationNode varArrayDeclarationNode)
 {
     BuildVar(varArrayDeclarationNode, true);
 }