예제 #1
0
        public void UpdateOutputTerminals(int outputTerminalCount)
        {
            AutoBorrowNodeFacade nodeFacade = AutoBorrowNodeFacade.GetNodeFacade(this);
            var immutableReferenceType      = NITypes.Void.CreateImmutableReference();
            int currentOutputTerminalCount  = OutputTerminals.Count();

            if (currentOutputTerminalCount < outputTerminalCount)
            {
                for (; currentOutputTerminalCount < outputTerminalCount; ++currentOutputTerminalCount)
                {
                    var terminal = CreateTerminal(Direction.Output, immutableReferenceType, "outer lifetime");
                    nodeFacade[terminal] = new SimpleTerminalFacade(terminal, terminal.GetTypeVariableSet().CreateReferenceToNewTypeVariable());
                }
            }
            else if (currentOutputTerminalCount > outputTerminalCount)
            {
                int i = currentOutputTerminalCount - 1;
                while (i >= 0 && currentOutputTerminalCount > outputTerminalCount)
                {
                    Terminal outputTerminal = OutputTerminals.ElementAt(i);
                    if (!outputTerminal.IsConnected)
                    {
                        RemoveTerminalAtIndex(outputTerminal.Index);
                        --currentOutputTerminalCount;
                    }
                    --i;
                }
            }
        }
예제 #2
0
        protected override void VisitNode(Node node)
        {
            TypeVariableSet      typeVariableSet = node.GetTypeVariableSet();
            AutoBorrowNodeFacade nodeFacade      = AutoBorrowNodeFacade.GetNodeFacade(node);
            var primitive    = node as PrimitiveTypeNode;
            var selfTypeNode = node as SelfTypeNode;

            if (primitive != null)
            {
                nodeFacade[primitive.OutputTerminal] = new SimpleTerminalFacade(
                    primitive.OutputTerminal,
                    typeVariableSet.CreateTypeVariableReferenceFromNIType(primitive.Type));
                return;
            }
            if (selfTypeNode != null)
            {
                foreach (Terminal inputTerminal in selfTypeNode.InputTerminals)
                {
                    TypeVariableReference typeVariable = typeVariableSet.CreateReferenceToNewTypeVariable();
                    nodeFacade[inputTerminal] = new SimpleTerminalFacade(inputTerminal, typeVariable);
                }
                return;
            }
            throw new NotSupportedException($"Unsupported node type: {node.GetType().Name}");
        }
예제 #3
0
        protected override void VisitWire(Wire wire)
        {
            TypeVariableReference wireTypeVariable = wire.GetTypeVariableSet()
                                                     .CreateReferenceToNewTypeVariable(Enumerable.Empty <Constraint>());

            AutoBorrowNodeFacade wireFacade = AutoBorrowNodeFacade.GetNodeFacade(wire);

            foreach (var terminal in wire.Terminals)
            {
                wireFacade[terminal] = new SimpleTerminalFacade(terminal, wireTypeVariable);
            }
        }