示例#1
0
        private void AddResult(Result ret, List <Node> lst)
        {
            Node            proto     = (Node)lst[0].Clone();
            List <NodePath> arguments = new List <NodePath>();

            // Find anonymous labels
            foreach (Node node in proto.Descendants)
            {
                if (node.Label[0] == Node.PlaceholderCode)
                {
                    arguments.Add(node.Path);
                }
            }

            // Create embedding
            Embedding embedding = ret.Prototype(proto, arguments);

            foreach (Node node in lst)
            {
                embedding.Embed(node);
            }
        }
示例#2
0
        public Result Collect(Node[] forest)
        {
            Calculate(forest);

            // d_nodes is a list of all root nodes constituting the embeddings
            // d_reverseMapping is a map from the roots to all the original nodes
            // which are contained in that root
            Result result = new Result();

            foreach (Node root in d_nodes)
            {
                List <Node> mapping = d_reverseMapping[root];

                // Replace the subexpression that was mapped on this root with an
                // embedding
                Node            prototype = (Node)root.Clone();
                List <NodePath> arguments = new List <NodePath>();

                // Calculate the placeholder nodes
                foreach (Node node in prototype.Descendants)
                {
                    if (Node.IsPlaceholder(node.Instruction))
                    {
                        arguments.Add(node.Path);
                    }
                }

                Embedding proto = result.Prototype(prototype, arguments);

                // Now we generate all the full expressions for this embedding
                foreach (Node inst in mapping)
                {
                    // Replace inst in top hiearchy with embedding node
                    proto.Embed(((Node)inst.Top.Clone()).FromPath(inst.Path));
                }
            }

            return(result);
        }