Example #1
0
        public void SetCall(IState[] argThenReturnTypes, int[] argThenReturnIds)
        {
            if (argThenReturnTypes.Length != argThenReturnIds.Length)
            {
                throw new ArgumentException("Sizes of type and id array have to be equal");
            }

            for (int i = 0; i < argThenReturnIds.Length - 1; i++)
            {
                var type  = argThenReturnTypes[i];
                var argId = argThenReturnIds[i];
                switch (type)
                {
                case Primitive primitive:
                {
                    var node = GetOrCreateNode(argId);
                    if (!node.TrySetAncestor(primitive))
                    {
                        throw new InvalidOperationException();
                    }
                    break;
                }

                case Array array:
                {
                    //var node = GetOrCreateNode(argId);
                    //var ancestor = CreateVarType(array);
                    //ancestor.BecomeAncestorFor(node);

                    //todo Upcast support
                    GetOrCreateArrayNode(argId, array.ElementNode);
                    break;
                }

                case Fun fun:
                {
                    var node     = GetOrCreateNode(argId);
                    var ancestor = CreateVarType(fun);
                    ancestor.BecomeAncestorFor(node);
                    break;
                }

                case RefTo refTo:
                {
                    var node = GetOrCreateNode(argId);
                    refTo.Node.BecomeAncestorFor(node);
                    break;
                }

                default: throw new InvalidOperationException();
                }
            }

            var returnId   = argThenReturnIds[argThenReturnIds.Length - 1];
            var returnType = argThenReturnTypes[argThenReturnIds.Length - 1];
            var returnNode = GetOrCreateNode(returnId);

            returnNode.State = SolvingFunctions.GetMergedState(returnNode.State, returnType);
        }
Example #2
0
        private SolvingNode GetOrCreateArrayNode(int id, SolvingNode elementType)
        {
            while (_syntaxNodes.Count <= id)
            {
                _syntaxNodes.Add(null);
            }

            var alreadyExists = _syntaxNodes[id];

            if (alreadyExists != null)
            {
                alreadyExists.State = SolvingFunctions.GetMergedState(new Array(elementType), alreadyExists.State);
                return(alreadyExists);
            }

            var res = new SolvingNode(id.ToString(), new Array(elementType), SolvingNodeType.SyntaxNode);

            _syntaxNodes[id] = res;
            return(res);
        }
Example #3
0
        private void SetOrCreateLambda(int lambdaId, SolvingNode[] args, SolvingNode ret)
        {
            var fun = Fun.Of(args, ret);

            while (_syntaxNodes.Count <= lambdaId)
            {
                _syntaxNodes.Add(null);
            }

            var alreadyExists = _syntaxNodes[lambdaId];

            if (alreadyExists != null)
            {
                alreadyExists.State = SolvingFunctions.GetMergedState(fun, alreadyExists.State);
            }
            else
            {
                var res = new SolvingNode(lambdaId.ToString(), fun, SolvingNodeType.SyntaxNode);
                _syntaxNodes[lambdaId] = res;
            }
        }