Exemple #1
0
        public override void Visit(RunQueryNode node)
        {
            _symbolTable.SetCurrentNode(node);
            node.Type = _symbolTable.RetrieveSymbol(node.FunctionName).ToString().ToLower();
            bool isCollection = false;

            VisitChildren(node);
            List <FunctionParameterEntry> funcParamList = _symbolTable.GetParameterTypes(node.FunctionName);

            funcParamList.OrderBy(x => x.ID);
            int     i = 0;
            AllType placeholderType = AllType.UNKNOWNTYPE;

            if (node.Parent is ExpressionNode expNode)
            {
                expNode.OverAllType = _symbolTable.RetrieveSymbol(node.FunctionName);
            }

            if (node.Children.Count > 0)
            {
                if (node.Children.Count <= funcParamList.Count)
                {
                    foreach (AbstractNode child in node.Children)
                    {
                        if (child is VariableNode varNode)
                        {
                            placeholderType = _symbolTable.RetrieveSymbol(child.Name, out isCollection) ?? AllType.UNKNOWNTYPE;

                            if (funcParamList.Count > 0)
                            {
                                if (placeholderType != funcParamList[i].Type && funcParamList[i].Collection == isCollection)
                                {
                                    //type error
                                    _symbolTable.RunFunctionTypeError(child.Name, funcParamList[i].Name);
                                }
                            }
                            else
                            {
                                //calling function with no formal parameters
                                _symbolTable.RunFunctionParameterError();
                            }
                        }
                        else if (child is ConstantNode constNode)
                        {
                            if (funcParamList.Count == 0)
                            {
                                _symbolTable.RunFunctionParameterError();
                            }
                            else
                            {
                                if (child.Type_enum != funcParamList[i].Type)
                                {
                                    _symbolTable.RunFunctionTypeError(child.Name, funcParamList[i].Name);
                                    //type error
                                }
                            }
                        }
                        ++i;
                    }
                }
                else
                {
                    _symbolTable.RunFunctionParameterError();
                }
            }
            else if (funcParamList.Count > 0)
            {
                //running function without actual parameters, when function has formal parameters
                _symbolTable.RunFunctionParameterError();
            }
        }