示例#1
0
        private static string ToString(IObject value, IGraph graph, bool firstLevelObjectEmitted,
                                       IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb         = new StringBuilder();
            string        objectType = value.Type.PackagePrefixedName;

            sb.Append(objectType);
            sb.Append("{");
            sb.Append("%:" + value.GetObjectName());
            if (nameToObject != null)
            {
                if (!nameToObject.ContainsKey(value.GetObjectName()))
                {
                    nameToObject.Add(value.GetObjectName(), value);
                }
            }
            if (!firstLevelObjectEmitted)
            {
                foreach (AttributeType attrType in value.Type.AttributeTypes)
                {
                    sb.Append(",");
                    sb.Append(attrType.Name);
                    sb.Append(":");
                    sb.Append(EmitHelper.ToStringAutomatic(value.GetAttribute(attrType.Name), graph, true,
                                                           nameToObject, procEnv));
                }
            }
            sb.Append("}");
            return(sb.ToString());
        }
示例#2
0
        private static string ToString(IMatch match, IGraph graph, bool firstLevelObjectEmitted, IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb        = new StringBuilder();
            string        matchName = match.Pattern != null ? match.Pattern.PackagePrefixedName : match.MatchClass.PackagePrefixedName;

            sb.Append("match<" + matchName + ">{");
            bool first = true;

            IPatternNode[] nodes = match.Pattern != null ? match.Pattern.Nodes : match.MatchClass.Nodes;
            foreach (IPatternNode patternNode in nodes)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternNode.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getNode(patternNode.UnprefixedName), graph, firstLevelObjectEmitted,
                                                       nameToObject, procEnv));
            }
            IPatternEdge[] edges = match.Pattern != null ? match.Pattern.Edges : match.MatchClass.Edges;
            foreach (IPatternEdge patternEdge in edges)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternEdge.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getEdge(patternEdge.UnprefixedName), graph, firstLevelObjectEmitted,
                                                       nameToObject, procEnv));
            }
            IPatternVariable[] variables = match.Pattern != null ? match.Pattern.Variables : match.MatchClass.Variables;
            foreach (IPatternVariable patternVar in variables)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternVar.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getVariable(patternVar.UnprefixedName), graph, firstLevelObjectEmitted,
                                                       nameToObject, procEnv));
            }
            sb.Append("}");
            return(sb.ToString());
        }
示例#3
0
        private static string ToString(IMatch value, IGraph graph)
        {
            IMatch        match     = (IMatch)value;
            StringBuilder sb        = new StringBuilder();
            string        matchName = match.Pattern != null ? match.Pattern.PackagePrefixedName : match.MatchClass.PackagePrefixedName;

            sb.Append("match<" + matchName + ">{");
            bool first = true;

            IPatternNode[] nodes = match.Pattern != null ? match.Pattern.Nodes : match.MatchClass.Nodes;
            foreach (IPatternNode patternNode in nodes)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternNode.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getNode(patternNode.UnprefixedName), graph));
            }
            IPatternEdge[] edges = match.Pattern != null ? match.Pattern.Edges : match.MatchClass.Edges;
            foreach (IPatternEdge patternEdge in edges)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternEdge.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getEdge(patternEdge.UnprefixedName), graph));
            }
            IPatternVariable[] variables = match.Pattern != null ? match.Pattern.Variables : match.MatchClass.Variables;
            foreach (IPatternVariable patternVar in variables)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }
                sb.Append(patternVar.UnprefixedName);
                sb.Append(":");
                sb.Append(EmitHelper.ToStringAutomatic(match.getVariable(patternVar.UnprefixedName), graph));
            }
            sb.Append("}");
            return(sb.ToString());
        }
示例#4
0
        // gets the variable value, decides whether to query the graph-global or the sequence-lokal variables
        public object GetVariableValue(IGraphProcessingEnvironment procEnv)
        {
            if (Type == "")
            {
                return(procEnv.GetVariableValue(name));
            }
            else
            {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + "==" + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                return(value);
            }
        }
示例#5
0
        // sets the variable value, decides whether to update the graph-global or the sequence-lokal variables
        public void SetVariableValue(object value, IGraphProcessingEnvironment procEnv)
        {
            if (Type == "")
            {
                procEnv.SetVariableValue(name, value);
            }
            else
            {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                this.value = value;
            }
        }
示例#6
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());
        }
示例#7
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]);
            }
        }
示例#8
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());
        }