private static void AppendObjects(IReferenceGraph graph, StringBuilder dot, Dictionary <MemoryPlace, string> nodes)
        {
            if (!graph.Objects.Any())
            {
                return;
            }

            dot.AppendLine("    node [shape=ellipse,style=diagonals];");

            var nextObject = 1;

            foreach (var contextObject in graph.Objects.Where(o => o.IsContext))
            {
                AppendObject(dot, contextObject, "ctx", nodes, nextObject);
                nextObject += 1;
            }
            ;

            dot.AppendLine("    node [shape=ellipse,style=solid];");

            nextObject = 1;
            foreach (var obj in graph.Objects.Where(o => !o.IsContext))
            {
                AppendObject(dot, obj, "obj", nodes, nextObject);
                nextObject += 1;
            }
        }
Example #2
0
 internal CallerVariable(IReferenceGraph graph, BindingSymbol symbol)
     : base(graph)
 {
     _ = symbol.DataType.UnderlyingReferenceType()
         ?? throw new ArgumentException("Must be a reference type", nameof(symbol));
     Symbol = symbol;
 }
 private protected HeapPlace(
     IReferenceGraph graph,
     IAbstractSyntax originSyntax,
     IReference?originOfMutability)
     : base(graph)
 {
     OriginSyntax       = originSyntax;
     OriginOfMutability = originOfMutability;
 }
        internal static string ToDotFormat(this IReferenceGraph graph)
        {
            var dot   = new StringBuilder();
            var nodes = new Dictionary <MemoryPlace, string>();

            dot.AppendLine("digraph reachability {");
            dot.AppendLine("    rankdir=LR;");
            AppendStack(graph, dot, nodes);
            AppendObjects(graph, dot, nodes);
            AppendReferences(graph, dot, nodes);
            dot.AppendLine("}");
            return(dot.ToString());
        }
        private static void AppendReferences(IReferenceGraph graph, StringBuilder dot, Dictionary <MemoryPlace, string> nodes)
        {
            var places = graph.CallerVariables
                         .Concat <MemoryPlace>(graph.Variables)
                         .Concat(graph.TempValues)
                         .Concat(graph.Objects)
                         .ToList();

            var referenceNames = new Dictionary <IReference, string>();

            AppendBorrows(dot, places, referenceNames);
            AppendReferences(dot, nodes, places, referenceNames);
        }
Example #6
0
        internal static Reference ToNewObject(
            IReferenceGraph graph,
            Ownership ownership,
            Access declaredAccess,
            IAbstractSyntax syntax,
            bool isContext,
            bool isOriginOfMutability)
        {
            var reference          = new Reference(ownership, declaredAccess);
            var originOfMutability = isOriginOfMutability ? reference : null;

            reference.Referent = new Object(graph, isContext, syntax, originOfMutability);
            return(reference);
        }
        private static void AppendStack(IReferenceGraph graph, StringBuilder dot, Dictionary <MemoryPlace, string> nodes)
        {
            var hasCallerVariables = graph.CallerVariables.Any();
            var hasVariables       = graph.Variables.Any();
            var hasTempValues      = graph.TempValues.Any();

            if (!hasCallerVariables && !hasVariables && !hasTempValues)
            {
                return;
            }

            dot.AppendLine("    node [shape=plaintext];");
            dot.AppendLine("    stack [label=<");
            dot.AppendLine("        <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">");
            var nextNode = 1;

            foreach (var callerVariable in graph.CallerVariables)
            {
                AppendStackItem(dot, callerVariable, "cv", nodes, ref nextNode);
            }

            if (hasCallerVariables && hasVariables)
            {
                AppendStackSeparator(dot);
            }

            nextNode = 1;
            foreach (var variable in graph.Variables)
            {
                AppendStackItem(dot, variable, "v", nodes, ref nextNode);
            }

            if ((hasCallerVariables || hasVariables) && hasTempValues)
            {
                AppendStackSeparator(dot);
            }

            nextNode = 1;
            foreach (var tempValue in graph.TempValues)
            {
                AppendStackItem(dot, tempValue, "t", nodes, ref nextNode);
            }

            dot.AppendLine("        </TABLE>>];"); // end stack
        }
 internal Object(IReferenceGraph graph, bool isContext, IAbstractSyntax syntax, Reference?originOfMutability)
     : base(graph, syntax, originOfMutability)
 {
     IsContext = isContext;
 }
Example #9
0
 internal TempValue(IReferenceGraph graph, IExpression expression, ReferenceType referenceType)
     : base(graph)
 {
     this.expression = expression;
     ReferenceType   = referenceType;
 }
 private protected StackPlace(IReferenceGraph graph)
     : base(graph)
 {
 }
 private protected MemoryPlace(IReferenceGraph graph)
 {
     Graph      = graph;
     References = references.AsReadOnly();
 }
Example #12
0
 /// <summary>
 /// Release this reference so that it no longer holds the referenced object
 /// </summary>
 void IReference.Release(IReferenceGraph graph)
 {
     Phase = Phase.Released;
     graph.Dirty();
 }