Example #1
0
        public ExplicitBorrowNode(Node parentNode, BorrowMode borrowMode, int inputs, bool alwaysBeginLifetime, bool alwaysCreateReference)
            : base(parentNode)
        {
            BorrowMode            = borrowMode;
            AlwaysBeginLifetime   = alwaysBeginLifetime;
            AlwaysCreateReference = alwaysCreateReference;
            NIType inputType = PFTypes.Void, outputType;

            switch (borrowMode)
            {
            case BorrowMode.Mutable:
                outputType = PFTypes.Void.CreateMutableReference();
                break;

            default:
                outputType = PFTypes.Void.CreateImmutableReference();
                break;
            }
            for (int i = 0; i < inputs; ++i)
            {
                CreateTerminal(Direction.Input, inputType, $"in_{i}");
            }
            for (int i = 0; i < inputs; ++i)
            {
                CreateTerminal(Direction.Output, outputType, $"out_{i}");
            }
        }
        internal static BorrowTunnel CreateBorrowTunnel(Structure structure, BorrowMode borrowMode)
        {
            var borrowTunnel          = new BorrowTunnel(structure, borrowMode);
            var terminateLifetimeDfir = new TerminateLifetimeTunnel(structure);

            borrowTunnel.TerminateLifetimeTunnel      = terminateLifetimeDfir;
            terminateLifetimeDfir.BeginLifetimeTunnel = borrowTunnel;
            return(borrowTunnel);
        }
        internal static ExplicitBorrowNode ConnectExplicitBorrowToInputTerminals(BorrowMode borrowMode, params Terminal[] inputTerminals)
        {
            Diagram            parentDiagram = inputTerminals[0].ParentDiagram;
            ExplicitBorrowNode borrow        = new ExplicitBorrowNode(parentDiagram, borrowMode, inputTerminals.Length, true, true);

            for (int i = 0; i < inputTerminals.Length; ++i)
            {
                Wire.Create(parentDiagram, borrow.OutputTerminals[i], inputTerminals[i]);
            }
            return(borrow);
        }
        public void CreateBorrowAndTerminateLifetimeNodes(LifetimeVariableAssociation lifetimeVariableAssociation)
        {
            if (_borrowRequired)
            {
                Node                 parentNode         = _facades.First().Terminal.ParentNode;
                BorrowMode           borrowMode         = _mutableBorrow ? BorrowMode.Mutable : BorrowMode.Immutable;
                int                  borrowInputCount   = _facades.Count;
                Diagram              inputParentDiagram = _facades.First().Terminal.ParentDiagram;
                var                  explicitBorrow     = new ExplicitBorrowNode(inputParentDiagram, borrowMode, borrowInputCount, true, false);
                AutoBorrowNodeFacade borrowNodeFacade   = AutoBorrowNodeFacade.GetNodeFacade(explicitBorrow);
                foreach (var terminal in explicitBorrow.Terminals)
                {
                    borrowNodeFacade[terminal] = new SimpleTerminalFacade(terminal, default(TypeVariableReference));
                }

                int index = 0;
                foreach (var facade in _facades)
                {
                    Terminal          input = facade.Terminal;
                    VariableReference ownerVariable = input.GetFacadeVariable(), borrowVariable;
                    ((AutoborrowingInputTerminalFacade)facade).AddPostBorrowCoercion(ref input, out borrowVariable);
                    InsertBorrowAheadOfTerminal(input, explicitBorrow, index, ownerVariable, borrowVariable);
                    ++index;
                }

                List <TerminateLifetimeOutputTerminalFacade> terminates = new List <TerminateLifetimeOutputTerminalFacade>();
                foreach (var terminal in parentNode.OutputTerminals)
                {
                    var terminateFacade = _nodeFacade[terminal] as TerminateLifetimeOutputTerminalFacade;
                    if (terminateFacade != null && _facades.Contains(terminateFacade.InputFacade))
                    {
                        terminates.Add(terminateFacade);
                    }
                }

                if (terminates.Count == borrowInputCount)
                {
                    Diagram outputParentDiagram = terminates.First().Terminal.ParentDiagram;
                    var     terminateLifetime   = TerminateLifetimeNodeHelpers.CreateTerminateLifetimeWithFacades(outputParentDiagram, borrowInputCount, borrowInputCount);

                    index = 0;
                    foreach (var terminate in terminates)
                    {
                        InsertTerminateLifetimeBehindTerminal(terminate.Terminal, terminateLifetime, index, lifetimeVariableAssociation);
                        ++index;
                    }
                }
                else if (terminates.Count > 0)
                {
                    throw new InvalidOperationException("Mismatched terminates and borrows; not sure what to do");
                }
            }
        }
Example #5
0
        public static void CheckAllBorrowModesMatch <T>(this IEnumerable <IViewModel> selection, ICommandParameter parameter, BorrowMode match) where T : IBorrowTunnel
        {
            IEnumerable <T> borrowTunnels = selection.GetBorrowTunnels <T>();

            if (!borrowTunnels.Any())
            {
                return;
            }
            BorrowMode firstMode     = borrowTunnels.First().BorrowMode;
            bool       multipleModes = borrowTunnels.Any(bt => bt.BorrowMode != firstMode);

            ((ICheckableCommandParameter)parameter).IsChecked = firstMode == match && !multipleModes;
        }
Example #6
0
 public LoopBorrowTunnel()
 {
     Docking     = BorderNodeDocking.Left;
     _borrowMode = BorrowMode.Immutable;
 }
Example #7
0
 public static void SetBorrowTunnelsMode <T>(this IEnumerable <T> borrowTunnels, BorrowMode borrowMode) where T : Element, IBorrowTunnel
 {
     if (borrowTunnels.Any())
     {
         using (IActiveTransaction transaction = (borrowTunnels.First()).TransactionManager.BeginTransaction("Set BorrowTunnel BorrowMode", TransactionPurpose.User))
         {
             foreach (T borrowTunnel in borrowTunnels)
             {
                 borrowTunnel.BorrowMode = borrowMode;
             }
             transaction.Commit();
         }
     }
 }