Exemplo n.º 1
0
 public void TestFunctionCall(FunctionCallingAstNode expect,
                              FunctionCallingAstNode actual, string traceMessage)
 {
     Assert.AreEqual(expect.Callee, actual.Callee, traceMessage);
     Assert.IsTrue(
         EqualCheckUtil.EnumerableEqual(expect.Arguments, actual.Arguments),
         traceMessage);
 }
Exemplo n.º 2
0
        public void Visit(FunctionCallingAstNode visitable)
        {
            if (!_context.HasFunction(visitable.Callee))
            {
                throw new UndefinedVariableException($"function {visitable.Callee}");
            }

            var args                = visitable.Arguments;
            var prototypes          = _context.GetFunction(visitable.Callee);
            var sameCountPrototypes = (from proto in prototypes
                                       where proto.Parameters.Length == (args?.Length ?? 0)
                                       select proto).ToArray();

            if (args is null || args.Length == 0)
            {
                if (sameCountPrototypes.Length != 1)
                {
                    throw new VariableRedefineException($"function {visitable.Callee}");
                }

                return;
            }

            for (int i = 0; i < args.Length; i++)
            {
                Visit(args[i]);
                var i1             = i;
                var protoToReserve = (from proto in sameCountPrototypes
                                      where proto.Parameters[i1].Type == _exprType
                                      select proto).ToArray();

                if (protoToReserve.Length == 0)
                {
                    throw new SemanticException(
                              $"no matching function: {visitable.Callee}");
                }

                sameCountPrototypes = protoToReserve;
            }

            if (sameCountPrototypes.Length != 1)
            {
                throw new VariableRedefineException($"function {visitable.Callee}");
            }
        }
 public void Visit(FunctionCallingAstNode visitable)
 {
     throw new System.NotImplementedException();
 }
 public bool Equals(FunctionCallingAstNode other)
 {
     return(Callee == other.Callee &&
            EqUtil.EnumerableEqual(Arguments, other.Arguments));
 }