Пример #1
0
        private static string ToString(ITransientObject value, IGraph graph, bool firstLevelObjectEmitted,
                                       IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb = new StringBuilder();
            string        transientObjectType = value.Type.PackagePrefixedName;

            sb.Append(transientObjectType);
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("{");
            }
            bool first = true;

            if (procEnv != null)
            {
                sb.Append("&:" + procEnv.GetUniqueId(value));
                first = false;
            }
            if (!firstLevelObjectEmitted)
            {
                foreach (AttributeType attrType in value.Type.AttributeTypes)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(attrType.Name);
                    sb.Append(":");
                    sb.Append(EmitHelper.ToStringAutomatic(value.GetAttribute(attrType.Name), graph, true,
                                                           nameToObject, procEnv));
                }
            }
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("}");
            }
            return(sb.ToString());
        }
Пример #2
0
        public SequenceVariable Copy(Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
        {
            // ensure that every instance of a variable is mapped to the same copy
            if (originalToCopy.ContainsKey(this))
            {
                return(originalToCopy[this]);
            }

            // local variables must be cloned when a defined sequence gets copied
            // global variables stay the same
            if (Type == "")
            {
                originalToCopy.Add(this, this);
                return(this);
            }
            else
            {
                originalToCopy.Add(this, new SequenceVariable(name, prefix, type));
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + name + "; " + name + "==" + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                return(originalToCopy[this]);
            }
        }
Пример #3
0
        public static string ToString(IMatch match, IGraph graph, string indent)
        {
            StringBuilder sb = new StringBuilder(4096);

            sb.Append(indent + "nodes: ");
            foreach (INode node in match.Nodes)
            {
                sb.Append(EmitHelper.ToStringAutomatic(node, graph, false, null, null));
                sb.Append(" ");
            }
            sb.Append("\n");

            sb.Append(indent + "edges: ");
            foreach (IEdge edge in match.Edges)
            {
                sb.Append(EmitHelper.ToStringAutomatic(edge, graph, false, null, null));
                sb.Append(" ");
            }
            sb.Append("\n");

            if (match.NumberOfIndependents > 0)
            {
                sb.Append(indent + "independents: \n");
                foreach (IMatch independent in match.Independents)
                {
                    sb.Append(ToString(independent, graph, indent + "  "));
                }
                sb.Append("\n");
            }

            if (match.NumberOfAlternatives > 0)
            {
                sb.Append(indent + "alternatives: \n");
                foreach (IMatch alternativeCase in match.Alternatives)
                {
                    sb.Append(ToString(alternativeCase, graph, indent + "  "));
                }
                sb.Append("\n");
            }

            if (match.NumberOfIterateds > 0)
            {
                sb.Append(indent + "iterateds: \n");
                foreach (IMatches iterated in match.Iterateds)
                {
                    sb.Append(indent + " iterated: \n");
                    foreach (IMatch iteratedMatch in iterated)
                    {
                        sb.Append(ToString(iteratedMatch, graph, indent + "  "));
                    }
                }
                sb.Append("\n");
            }

            if (match.NumberOfEmbeddedGraphs > 0)
            {
                sb.Append(indent + "subpatterns: \n");
                foreach (IMatch subpattern in match.EmbeddedGraphs)
                {
                    sb.Append(ToString(subpattern, graph, indent + "  "));
                }
                sb.Append("\n");
            }

            return(sb.ToString());
        }