Esempio n. 1
0
        /// <summary>
        /// An example of modifying the DFIR. Remove debug points, maybe because they are noise in the Dfir graph for our purposes.
        /// </summary>
        private static void RemoveDebugPoints(DfirRoot sourceDfirRoot, CompileCancellationToken compileCancellationToken)
        {
            if (sourceDfirRoot == null)
            {
                return;
            }

            if (compileCancellationToken.IsCancellationRequested)
            {
                CompileCanceledException.ThrowIt();
            }

            List <DebugPoint> debugPoints = sourceDfirRoot.GetAllNodesIncludingSelf().OfType <DebugPoint>().ToList();

            foreach (DebugPoint debugPoint in debugPoints)
            {
                foreach (Terminal terminal in debugPoint.Terminals)
                {
                    if (!terminal.IsConnected)
                    {
                        continue;
                    }

                    Terminal connectedTerminal = terminal.ConnectedTerminal;
                    var      wire = connectedTerminal.ParentNode as Wire;
                    terminal.Disconnect();
                    wire?.RemoveOutput(connectedTerminal);
                }
                debugPoint.RemoveFromGraph();
            }
        }
Esempio n. 2
0
 public static bool TestTerminalHasOwnedValueConnected(this Terminal terminal)
 {
     if (terminal.DataType.IsImmutableReferenceType() ||
         terminal.DataType.IsMutableReferenceType())
     {
         terminal.ParentNode.SetDfirMessage(Messages.TerminalDoesNotAcceptReference);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        public static bool TestTerminalHasMutableTypeConnected(this Terminal terminal)
        {
            VariableReference variable = terminal.GetFacadeVariable();

            if (!(variable.Mutable || variable.Type.IsMutableReferenceType()))
            {
                terminal.ParentNode.SetDfirMessage(Messages.TerminalDoesNotAcceptImmutableType);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        private void VisitConnectable(Connectable connectable)
        {
            // Update terminals on a TerminateLifetime before reflecting types
            var terminateLifetime = connectable as TerminateLifetime;

            if (terminateLifetime != null)
            {
                VisitTerminateLifetime(terminateLifetime);
            }

            foreach (var nodeTerminal in connectable.Terminals)
            {
                NationalInstruments.Dfir.Terminal dfirTerminal = _map.GetDfirForTerminal(nodeTerminal);
                NIType typeToReflect = dfirTerminal.DataType;
                if (!nodeTerminal.DataType.Equals(typeToReflect))
                {
                    nodeTerminal.DataType = typeToReflect;
                }
            }
        }
Esempio n. 5
0
        private void VisitConnectable(Connectable connectable)
        {
            // Update terminals on a TerminateLifetime before reflecting types
            var terminateLifetime     = connectable as TerminateLifetime;
            var typePassthrough       = connectable as TypePassthrough;
            var structFieldAccessor   = connectable as StructFieldAccessor;
            var variantMatchStructure = connectable as SourceModel.VariantMatchStructure;

            if (terminateLifetime != null)
            {
                VisitTerminateLifetime(terminateLifetime);
            }
            if (typePassthrough != null)
            {
                NIType type = _map.GetDfirForTerminal(typePassthrough.InputTerminals.ElementAt(0)).GetTrueVariable().Type.GetReferentType();
                typePassthrough.Type = type;
            }
            if (structFieldAccessor != null)
            {
                var structFieldAccessorDfir = (StructFieldAccessorNode)_map.GetDfirForModel(structFieldAccessor);
                structFieldAccessor.UpdateDependencies(structFieldAccessorDfir.StructType);
            }
            if (variantMatchStructure != null)
            {
                var    variantMatchStructureSelectorDfir = ((Nodes.VariantMatchStructure)_map.GetDfirForModel(variantMatchStructure)).Selector;
                NIType variantType = variantMatchStructureSelectorDfir.InputTerminals[0].GetTrueVariable().Type;
                variantMatchStructure.UpdateDependencies(variantType);
            }

            foreach (var nodeTerminal in connectable.Terminals)
            {
                NationalInstruments.Dfir.Terminal dfirTerminal = _map.GetDfirForTerminal(nodeTerminal);
                NIType typeToReflect = dfirTerminal.DataType;
                if (!nodeTerminal.DataType.Equals(typeToReflect))
                {
                    nodeTerminal.DataType = typeToReflect;
                }
            }
        }