Example #1
0
 public Builder(TypeSystem typeSystem)
 {
     // Don't store the typeSystem in this; we may not access it outside of Flush().
     this.NullableNode  = typeSystem.NullableNode;
     this.NonNullNode   = typeSystem.NonNullNode;
     this.ObliviousNode = typeSystem.ObliviousNode;
     this.VoidType      = typeSystem.VoidType;
 }
Example #2
0
            /// <summary>
            /// Gets a nullability node that is nullable iff either input is nullable.
            /// </summary>
            public NullabilityNode Join(NullabilityNode a, NullabilityNode b, EdgeLabel edgeLabel)
            {
                if (a == b)
                {
                    return(a);
                }
                if (a.NullType == NullType.NonNull)
                {
                    return(b);
                }
                if (b.NullType == NullType.NonNull)
                {
                    return(a);
                }

                if (a.NullType == NullType.Oblivious)
                {
                    return(b);
                }
                if (b.NullType == NullType.Oblivious)
                {
                    return(a);
                }

                if (a.NullType == NullType.Nullable)
                {
                    return(a);
                }
                if (b.NullType == NullType.Nullable)
                {
                    return(b);
                }

                var newNode = CreateHelperNode();

                CreateEdge(a, newNode, edgeLabel);
                CreateEdge(b, newNode, edgeLabel);
                return(newNode);
            }
            /// <summary>
            /// Creates an edge source->target.
            /// </summary>
            public NullabilityEdge?CreateEdge(NullabilityNode source, NullabilityNode target)
            {
                // Ignore a bunch of special cases where the edge won't have any effect on the overall result:
                source = source.ReplacedWith;
                target = target.ReplacedWith;
                if (source == target)
                {
                    return(null);
                }
                if (source.NullType == NullType.NonNull || source.NullType == NullType.Oblivious)
                {
                    return(null);
                }
                if (target.NullType == NullType.Nullable || target.NullType == NullType.Oblivious)
                {
                    return(null);
                }
                var edge = new NullabilityEdge(source, target);

                Debug.WriteLine($"New edge: {source.Name} -> {target.Name}");
                newEdges.Add(edge);
                return(edge);
            }