Example #1
0
        private void CheckFunction(ASTNode node)
        {
            string         name  = node.GetName();
            List <ASTNode> args  = node.GetChildren();
            Table          scope = node.GetScope();

            while (scope != null)
            {
                Symbol reference = scope.lookup(name);
                if (reference != null) //The identifier exists in the current scope
                {
                    if (args.Count == reference.GetParameters().Count)
                    {
                        for (int i = 0; i < args.Count; i++)
                        {
                            if (!(args[i].GetType() == reference.GetParameters()[i]))
                            {
                                Swift.error("The type of the parameter you supplied when calling \"" + name + "\" at the line " + args[i].GetContext().GetLine().ToString() + ", column " + args[i].GetContext().GetPos().ToString() + " is not the same type as required by the function", 1);
                            }
                        }
                        break;
                    }
                    else
                    {
                        Swift.error("The number of parameters you supplied when calling \"" + name + "\" at the line " + node.GetContext().GetLine().ToString() + ", column " + node.GetContext().GetPos().ToString() + " does not match the required number of parameters as defined in the function", 1);
                    }
                }
                scope = scope.GetReference();
            }
        }