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; } } }
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}"); }
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); } }