Ejemplo n.º 1
0
 void AssertAllUnmappedAfterMatch(IMatches matches, bool special)
 {
     foreach (INode node in graph.GetCompatibleNodes(graph.Model.NodeModel.RootType))
     {
         LGSPNode lnode = (LGSPNode)node;
         if (lnode.mappedTo != 0)
         {
             throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not unmapped by action \""
                                 + matches.Producer.Name + "\"!");
         }
         if (lnode.negMappedTo != 0)
         {
             throw new Exception("Node \"" + graph.GetElementName(lnode) + "\" not neg-unmapped by action \""
                                 + matches.Producer.Name + "\"!");
         }
     }
     foreach (IEdge edge in graph.GetCompatibleEdges(graph.Model.EdgeModel.RootType))
     {
         LGSPEdge ledge = (LGSPEdge)edge;
         if (ledge.mappedTo != 0)
         {
             throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not unmapped by action \""
                                 + matches.Producer.Name + "\"!");
         }
         if (ledge.negMappedTo != 0)
         {
             throw new Exception("Edge \"" + graph.GetElementName(ledge) + "\" not neg-unmapped by action \""
                                 + matches.Producer.Name + "\"!");
         }
     }
 }
        private void ChangingElementAttribute(LGSPGraphProcessingEnvironment procEnv)
        {
            AttributeChangeType changeType;

            switch (_undoOperation)
            {
            case UndoOperation.Assign: changeType = AttributeChangeType.Assign; break;

            case UndoOperation.PutElement: changeType = AttributeChangeType.PutElement; break;

            case UndoOperation.RemoveElement: changeType = AttributeChangeType.RemoveElement; break;

            case UndoOperation.AssignElement: changeType = AttributeChangeType.AssignElement; break;

            default: throw new Exception("Internal error during transaction handling");
            }

            LGSPNode node = _elem as LGSPNode;

            if (node != null)
            {
                procEnv.graph.ChangingNodeAttribute(node, _attrType, changeType, _value, _keyOfValue);
            }
            else
            {
                LGSPEdge edge = (LGSPEdge)_elem;
                procEnv.graph.ChangingEdgeAttribute(edge, _attrType, changeType, _value, _keyOfValue);
            }
        }
Ejemplo n.º 3
0
        void DoIt()
        {
            graph = new LGSPGraph(new ProgramGraphsOriginalGraphModel());
            actions = new ProgramGraphsOriginalActions(graph);
            procEnv = new LGSPGraphProcessingEnvironment(graph, actions);

            // use new exact 2.5 interface
            IClass cls = null; 
            IMethodBody mb = null;
            bool success = actions.createProgramGraphPullUp.Apply(procEnv, ref cls, ref mb);
            IMatchesExact<Rule_pullUpMethod.IMatch_pullUpMethod> matchesExact =
                actions.pullUpMethod.Match(procEnv, 0, cls, mb);
            Console.WriteLine(matchesExact.Count + " matches found.");
            Console.WriteLine(matchesExact.FirstExact.node_m5.ToString());

            graph.Clear();
            
            // and again with old inexact interface
            IMatches matchesInexact;
            object[] returns;

            Action_createProgramGraphPullUp createProgramGraph = Action_createProgramGraphPullUp.Instance;
            matchesInexact = createProgramGraph.Match(procEnv, 0);
            returns = createProgramGraph.Modify(procEnv, matchesInexact.First);
            IGraphElement[] param = new LGSPNode[2];
            param[0] = (Class)returns[0];
            param[1] = (MethodBody)returns[1];
            matchesInexact = actions.GetAction("pullUpMethod").Match(procEnv, 0, param);
            Console.WriteLine(matchesInexact.Count + " matches found.");
            Console.WriteLine(matchesInexact.First.getNodeAt((int)Rule_pullUpMethod.pullUpMethod_NodeNums.m5).ToString());
        }
        void ClearGraphListener()
        {
            foreach (INode node in graph.Nodes)
            {
                LGSPNode lgspNode = (LGSPNode)node;
                if ((lgspNode.lgspFlags & (uint)LGSPElemFlags.HAS_VARIABLES) != 0)
                {
                    foreach (Variable var in ElementMap[lgspNode])
                    {
                        VariableMap.Remove(var.Name);
                    }
                    ElementMap.Remove(lgspNode);
                    lgspNode.lgspFlags &= ~(uint)LGSPElemFlags.HAS_VARIABLES;
                }
            }

            foreach (IEdge edge in graph.Edges)
            {
                LGSPEdge lgspEdge = (LGSPEdge)edge;
                if ((lgspEdge.lgspFlags & (uint)LGSPElemFlags.HAS_VARIABLES) != 0)
                {
                    foreach (Variable var in ElementMap[lgspEdge])
                    {
                        VariableMap.Remove(var.Name);
                    }
                    ElementMap.Remove(lgspEdge);
                    lgspEdge.lgspFlags &= ~(uint)LGSPElemFlags.HAS_VARIABLES;
                }
            }
        }
Ejemplo n.º 5
0
        public virtual void RemovingNode(INode node)
        {
            LGSPNode nodeUnique = (LGSPNode)node;

            Insert(nodeUnique.uniqueId);
            //nodeUnique.uniqueId = -1; an index needs to access the old id
        }
Ejemplo n.º 6
0
        public void Modify(GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv, GRGEN_LIBGR.IMatch _curMatch)
        {
            GRGEN_LGSP.LGSPGraph graph    = actionEnv.graph;
            Match_testRule       curMatch = (Match_testRule)_curMatch;

            GRGEN_LGSP.LGSPNode node_a = curMatch._node_a;
            GRGEN_LGSP.LGSPNode node_f = curMatch._node_f;
            GRGEN_LGSP.LGSPNode node_m = curMatch._node_m;
            graph.SettingAddedNodeNames(testRule_addedNodeNames);
            GRGEN_LGSP.LGSPNode        node_are  = graph.Retype(node_a, GRGEN_MODEL.NodeType_D2211_2222_31.typeVar);
            GRGEN_MODEL.ID2211_2222_31 inode_are = (GRGEN_MODEL.ID2211_2222_31)node_are;
            GRGEN_LGSP.LGSPNode        node_fre  = graph.Retype(node_f, GRGEN_MODEL.NodeType_D231_4121.typeVar);
            GRGEN_MODEL.ID231_4121     inode_fre = (GRGEN_MODEL.ID231_4121)node_fre;
            GRGEN_LGSP.LGSPNode        node_mre  = graph.Retype(node_m, GRGEN_MODEL.NodeType_D11_2221.typeVar);
            GRGEN_MODEL.ID11_2221      inode_mre = (GRGEN_MODEL.ID11_2221)node_mre;
            graph.SettingAddedEdgeNames(testRule_addedEdgeNames);
            {             // eval_0
                int tempvar_0 = (int )1234;
                graph.ChangingNodeAttribute(node_are, GRGEN_MODEL.NodeType_D2211_2222_31.AttributeType_d2211_2222_31, GRGEN_LIBGR.AttributeChangeType.Assign, tempvar_0, null);
                inode_are.@d2211_2222_31 = tempvar_0;
                graph.ChangedNodeAttribute(node_are, GRGEN_MODEL.NodeType_D2211_2222_31.AttributeType_d2211_2222_31);
                int tempvar_1 = (int )5678;
                graph.ChangingNodeAttribute(node_fre, GRGEN_MODEL.NodeType_D231_4121.AttributeType_d231_4121, GRGEN_LIBGR.AttributeChangeType.Assign, tempvar_1, null);
                inode_fre.@d231_4121 = tempvar_1;
                graph.ChangedNodeAttribute(node_fre, GRGEN_MODEL.NodeType_D231_4121.AttributeType_d231_4121);
                int tempvar_2 = (int )9012;
                graph.ChangingNodeAttribute(node_mre, GRGEN_MODEL.NodeType_D11_2221.AttributeType_d11_2221, GRGEN_LIBGR.AttributeChangeType.Assign, tempvar_2, null);
                inode_mre.@d11_2221 = tempvar_2;
                graph.ChangedNodeAttribute(node_mre, GRGEN_MODEL.NodeType_D11_2221.AttributeType_d11_2221);
            }
            return;
        }
Ejemplo n.º 7
0
        public virtual void RetypingNode(INode oldNode, INode newNode)
        {
            LGSPNode oldNodeUnique = (LGSPNode)oldNode;
            LGSPNode newNodeUnique = (LGSPNode)newNode;

            newNodeUnique.uniqueId = oldNodeUnique.uniqueId;
            //oldNodeUnique.uniqueId = -1; an index needs to access the old id
        }
Ejemplo n.º 8
0
        public override void RemovingNode(INode node)
        {
            LGSPNode nodeUnique = (LGSPNode)node;

            Insert(nodeUnique.uniqueId);
            //nodeUnique.uniqueId = -1; an index needs to access the old id
            index[nodeUnique.uniqueId] = null;
        }
Ejemplo n.º 9
0
 public void CopyMatchContent(Match_testRule that)
 {
     _node_a      = that._node_a;
     _node_f      = that._node_f;
     _node_m      = that._node_m;
     _edge__edge0 = that._edge__edge0;
     _edge__edge1 = that._edge__edge1;
 }
Ejemplo n.º 10
0
        public override void RetypingNode(INode oldNode, INode newNode)
        {
            LGSPNode oldNodeUnique = (LGSPNode)oldNode;
            LGSPNode newNodeUnique = (LGSPNode)newNode;

            newNodeUnique.uniqueId = oldNodeUnique.uniqueId;
            //oldNodeUnique.uniqueId = -1; an index needs to access the old id
            index[newNodeUnique.uniqueId] = newNode;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds a new edge to the graph and assigns it to the given variable.
        /// </summary>
        /// <param name="edgeType">The edge type for the new edge.</param>
        /// <param name="source">The source of the edge.</param>
        /// <param name="target">The target of the edge.</param>
        /// <param name="varName">The name of the variable.</param>
        /// <returns>The newly created edge.</returns>
        public LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target, String varName)
        {
            LGSPEdge edge = (LGSPEdge)edgeType.CreateEdge(source, target);

            graph.AddEdgeWithoutEvents(edge, edgeType.TypeID);
            SetVariableValue(varName, edge);
            graph.EdgeAdded(edge);
            return(edge);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a new LGSPNode to the graph and assigns it to the given variable.
        /// </summary>
        /// <param name="nodeType">The node type for the new node.</param>
        /// <param name="varName">The name of the variable.</param>
        /// <returns>The newly created node.</returns>
        public LGSPNode AddLGSPNode(NodeType nodeType, String varName)
        {
            LGSPNode node = (LGSPNode)nodeType.CreateNode();

            graph.AddNodeWithoutEvents(node, nodeType.TypeID);
            SetVariableValue(varName, node);
            graph.NodeAdded(node);
            return(node);
        }
        void RemovingNodeListener(INode node)
        {
            LGSPNode lgspNode = (LGSPNode)node;

            if ((lgspNode.lgspFlags & (uint)LGSPElemFlags.HAS_VARIABLES) != 0)
            {
                foreach (Variable var in ElementMap[lgspNode])
                {
                    VariableMap.Remove(var.Name);
                }
                ElementMap.Remove(lgspNode);
                lgspNode.lgspFlags &= ~(uint)LGSPElemFlags.HAS_VARIABLES;
            }
        }
        public readonly IGraph _graph; // for ToString only

        public LGSPUndoElemRedirecting(LGSPEdge edge, LGSPNode source, LGSPNode target, LGSPGraphProcessingEnvironment procEnv)
        {
            _edge   = edge;
            _source = source;
            _target = target;
            if (procEnv.graph is LGSPNamedGraph)
            {
                _name = ((LGSPNamedGraph)procEnv.graph).GetElementName(_edge);
            }
            else
            {
                _name = "?";
            }
            _graph = procEnv.graph;
        }
        public void DoUndo(IGraphProcessingEnvironment procEnv)
        {
            String name;

            if (procEnv.Graph is LGSPNamedGraph && ((LGSPNamedGraph)procEnv.Graph).ElemToName.TryGetValue(_newElem, out name))
            {
                LGSPNamedGraph lgspGraph = (LGSPNamedGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.ElemToName[oldNode] = name;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                    lgspGraph.ElemToName.Remove(newNode);
                    lgspGraph.NameToElem[name] = oldNode;
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.ElemToName[oldEdge] = name;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                    lgspGraph.ElemToName.Remove(newEdge);
                    lgspGraph.NameToElem[name] = oldEdge;
                }
            }
            else
            {
                LGSPGraph lgspGraph = (LGSPGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                }
            }
        }
        void RetypingNodeListener(INode oldNode, INode newNode)
        {
            LGSPNode oldLgspNode = (LGSPNode)oldNode;
            LGSPNode newLgspNode = (LGSPNode)newNode;

            if ((oldLgspNode.lgspFlags & (uint)LGSPElemFlags.HAS_VARIABLES) != 0)
            {
                LinkedList <Variable> varList = ElementMap[oldLgspNode];
                foreach (Variable var in varList)
                {
                    var.Value = newLgspNode;
                }
                ElementMap.Remove(oldLgspNode);
                ElementMap[newLgspNode] = varList;
                newLgspNode.lgspFlags  |= (uint)LGSPElemFlags.HAS_VARIABLES;
            }
        }
Ejemplo n.º 17
0
 public static GRGEN_MODEL.@UEdge CreateEdge(GRGEN_LGSP.LGSPNamedGraph graph, GRGEN_LGSP.LGSPNode source, GRGEN_LGSP.LGSPNode target, string edgeName)
 {
     GRGEN_MODEL.@UEdge edge;
     if (poolLevel == 0)
     {
         edge = new GRGEN_MODEL.@UEdge(source, target);
     }
     else
     {
         edge            = pool[--poolLevel];
         edge.lgspFlags &= ~(uint)GRGEN_LGSP.LGSPElemFlags.HAS_VARIABLES;
         edge.lgspSource = source;
         edge.lgspTarget = target;
         // implicit initialization, container creation of UEdge
     }
     graph.AddEdge(edge, edgeName);
     return(edge);
 }
Ejemplo n.º 18
0
        public void AddNode(LGSPNode node, String elemName)
        {
            if (elemName != null && NameToElem.ContainsKey(elemName))
            {
                throw new ArgumentException("The name \"" + elemName + "\" is already used!");
            }

            if (elemName == null)
            {
                elemName = GetNextName();
            }

            AddNodeWithoutEvents(node, node.lgspType.TypeID);

            NameToElem[elemName] = node;
            ElemToName[node]     = elemName;

            NodeAdded(node);
        }
Ejemplo n.º 19
0
        public virtual void NodeAdded(INode node)
        {
            LGSPNode nodeUnique = (LGSPNode)node;

            if (heap.Count == 1) // empty (one dummy needed for simpler arithmetic)
            {
                nodeUnique.uniqueId = nextNewId;
                ++nextNewId;

                if (graph.flagsPerThreadPerElement != null) // if not null there's some parallel matcher existing
                {
                    EnlargeFlagsOfParallelizedMatcherAsNeeded();
                }
            }
            else
            {
                nodeUnique.uniqueId = FetchAndRemoveMinimum();
            }
        }
Ejemplo n.º 20
0
        public override LGSPNode Retype(LGSPNode node, NodeType newNodeType)
        {
            String name;

            if (ElemToName.TryGetValue(node, out name)) // give new node the name of the old node in case it was named
            {
                LGSPNode newNode = (LGSPNode)newNodeType.CreateNodeWithCopyCommons(node);
                ElemToName[newNode] = name;
                RetypingNode(node, newNode);
                ReplaceNode(node, newNode);
                ElemToName.Remove(node);
                NameToElem[name] = newNode;
                return(newNode);
            }
            else
            {
                return(base.Retype(node, newNodeType));
            }
        }
Ejemplo n.º 21
0
        public static bool IsMatched(LGSPNode node, IMatch lastMatchAtPreviousNestingLevel)
        {
            Debug.Assert(lastMatchAtPreviousNestingLevel != null);

            // move through matches stack backwards to starting rule,
            // check if node is already matched somewhere on the derivation path
            IMatch match = lastMatchAtPreviousNestingLevel;

            while (match != null)
            {
                for (int i = 0; i < match.NumberOfNodes; ++i)
                {
                    if (match.getNodeAt(i) == node)
                    {
                        return(true);
                    }
                }
                match = match.MatchOfEnclosingPattern;
            }
            return(false);
        }
        /// <summary>
        /// Detaches the specified variable from the according graph element.
        /// If it was the last variable pointing to the element, the variable list for the element is removed.
        /// This function may only called on variables pointing to graph elements.
        /// </summary>
        /// <param name="var">Variable to detach.</param>
        private void DetachVariableFromElement(Variable var)
        {
            IGraphElement         elem       = (IGraphElement)var.Value;
            LinkedList <Variable> oldVarList = ElementMap[elem];

            oldVarList.Remove(var);
            if (oldVarList.Count == 0)
            {
                ElementMap.Remove(elem);

                LGSPNode oldNode = elem as LGSPNode;
                if (oldNode != null)
                {
                    oldNode.lgspFlags &= ~(uint)LGSPElemFlags.HAS_VARIABLES;
                }
                else
                {
                    LGSPEdge oldEdge = (LGSPEdge)elem;
                    oldEdge.lgspFlags &= ~(uint)LGSPElemFlags.HAS_VARIABLES;
                }
            }
        }
Ejemplo n.º 23
0
        public LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target, String elemName)
        {
            if (elemName != null && NameToElem.ContainsKey(elemName))
            {
                throw new ArgumentException("The name \"" + elemName + "\" is already used!");
            }

            if (elemName == null)
            {
                elemName = GetNextName();
            }

            LGSPEdge edge = (LGSPEdge)edgeType.CreateEdge(source, target);

            AddEdgeWithoutEvents(edge, edgeType.TypeID);

            NameToElem[elemName] = edge;
            ElemToName[edge]     = elemName;

            EdgeAdded(edge);

            return(edge);
        }
Ejemplo n.º 24
0
        public LGSPNode AddLGSPNode(NodeType nodeType, String elemName)
        {
            if (elemName != null && NameToElem.ContainsKey(elemName))
            {
                throw new ArgumentException("The name \"" + elemName + "\" is already used!");
            }

            if (elemName == null)
            {
                elemName = GetNextName();
            }

            //            LGSPNode node = new LGSPNode(nodeType);
            LGSPNode node = (LGSPNode)nodeType.CreateNode();

            AddNodeWithoutEvents(node, nodeType.TypeID);

            NameToElem[elemName] = node;
            ElemToName[node]     = elemName;

            NodeAdded(node);

            return(node);
        }
Ejemplo n.º 25
0
 void CheckNodeInGraph(LGSPNode node)
 {
     LGSPNode head = nodesByTypeHeads[node.lgspType.TypeID];
     LGSPNode cur = head.lgspTypeNext;
     while(cur != head)
     {
         if(cur == node)
             return;
         cur = cur.lgspTypeNext;
     }
     throw new Exception("Internal error: Node not in graph");
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Checks whether the type ringlist starting at the given head node is broken.
        /// Use for debugging purposes.
        /// </summary>
        /// <param name="node">The node head to be checked.</param>
        public void CheckTypeRinglistBroken(LGSPNode head)
        {
            LGSPNode headNext = head.lgspTypeNext;
            if(headNext == null) throw new Exception("Internal error: Ringlist broken");
            LGSPNode cur = headNext;
            LGSPNode next;
            while(cur != head)
            {
                if(cur != cur.lgspTypeNext.lgspTypePrev) throw new Exception("Internal error: Ringlist out of order");
                next = cur.lgspTypeNext;
                if(next == null) throw new Exception("Internal error: Ringlist broken");
                if(next == headNext) throw new Exception("Internal error: Ringlist loops bypassing head");
                cur = next;
            }

            LGSPNode headPrev = head.lgspTypePrev;
            if(headPrev == null) throw new Exception("Internal error: Ringlist broken");
            cur = headPrev;
            LGSPNode prev;
            while(cur != head)
            {
                if(cur != cur.lgspTypePrev.lgspTypeNext) throw new Exception("Internal error: Ringlist out of order");
                prev = cur.lgspTypePrev;
                if(prev == null) throw new Exception("Internal error: Ringlist broken");
                if(prev == headPrev) throw new Exception("Internal error: Ringlist loops bypassing head");
                cur = prev;
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Changes the source of the edge from the old source to the given new source,
 /// and changes the target node of the edge from the old target to the given new target.
 /// </summary>
 /// <param name="edge">The edge to redirect.</param>
 /// <param name="newSource">The new source node of the edge.</param>
 /// <param name="newTarget">The new target node of the edge.</param>
 /// <param name="oldSourceName">The name of the old source node (used for debug display of the new edge).</param>
 /// <param name="oldTargetName">The name of the old target node (used for debug display of the new edge).</param>
 public void RedirectSourceAndTarget(LGSPEdge edge, LGSPNode newSource, LGSPNode newTarget, string oldSourceName, string oldTargetName)
 {
     RedirectingEdge(edge);
     RemovingEdge(edge);
     edge.lgspSource.RemoveOutgoing(edge);
     newSource.AddOutgoing(edge);
     edge.lgspSource = newSource;
     edge.lgspTarget.RemoveIncoming(edge);
     newTarget.AddIncoming(edge);
     edge.lgspTarget = newTarget;
     nameOfSingleElementAdded[0] = "redirected from " + oldSourceName + " --> " + oldTargetName;
     SettingAddedEdgeNames(nameOfSingleElementAdded);
     EdgeAdded(edge);
     ++changesCounter;
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Merges the source node into the target node,
        /// i.e. all edges incident to the source node are redirected to the target node, then the source node is deleted.
        /// </summary>
        /// <param name="target">The node which remains after the merge.</param>
        /// <param name="source">The node to be merged.</param>
        /// <param name="sourceName">The name of the node to be merged (used for debug display of redirected edges).</param>
        public void Merge(LGSPNode target, LGSPNode source, string sourceName)
        {
            if (source == target)
                return;

            while(source.lgspOuthead!=null)
            {
                if(source.lgspOuthead.Target==source)
                    RedirectSourceAndTarget(source.lgspOuthead, target, target, sourceName, sourceName);
                else
                    RedirectSource(source.lgspOuthead, target, sourceName);
            }
            while (source.lgspInhead != null)
            {
                RedirectTarget(source.lgspInhead, target, sourceName);
            }

            Remove(source);
        }
Ejemplo n.º 29
0
        void DoIt()
        {
            // create the LibGr Search Plan backend we want to use
            LGSPBackend backend = new LGSPBackend();

            // the graph model we'll use
            JavaProgramGraphsGraphModel model = new JavaProgramGraphsGraphModel();

            // the actions object for the rules we'll to use
            IActions ba;

            // import the instance graph we created with gxl2grs, using the the .gm we created by hand
            // (can't use import gxl for the program graph, because the given .gxl is severly rotten)
            // we throw away the named graph cause we don't need names here and they require about the same amount of memory as the graph itself; 
            INamedGraph importedNamedGraph = (INamedGraph)Porter.Import("InstanceGraph.grs", backend, model, out ba);
            LGSPGraph graph = new LGSPGraph((LGSPNamedGraph)importedNamedGraph, "unnamed");
            importedNamedGraph = null;
            
            // get the actions object for the rules we want to use
            JavaProgramGraphsActions actions = ba!=null ? (JavaProgramGraphsActions)ba : new JavaProgramGraphsActions(graph);

            // the graph processing environment we'll use
            LGSPGraphProcessingEnvironment procEnv = new LGSPGraphProcessingEnvironment(graph, actions);

            // the instance graph script uses variables to build up the graph,
            // we query some of them here, to get the elements to refactor
            // (instead of variables one could use the element names)
            Class src = (Class)procEnv.GetNodeVarValue("I176"); // class Node
            Class tgt = (Class)procEnv.GetNodeVarValue("I194"); // class Packet - use if parameter is used in moving method
            //Class tgt = (Class)graph.GetNodeVarValue("I617"); // class String - use if instance variable is used in moving method
            MethodBody mb = (MethodBody)procEnv.GetNodeVarValue("I409"); // method body of send

            // get operation for method body by: 
            // get action, match action pattern with given parameters, apply rewrite filling given out parameters
            IMatchesExact<Rule_getOperation.IMatch_getOperation> matches = actions.getOperation.Match(procEnv, 1, mb);
            IOperation op;
            actions.getOperation.Modify(procEnv, matches.FirstExact, out op);

            // iterated application of action marking the body of the expression
            // (shows second way of getting action)
            int visitedFlagId = graph.AllocateVisitedFlag();
            Debug.Assert(visitedFlagId==0);
            IGraphElement[] param = new LGSPNode[1];
            param[0] = mb;
            IMatches matchesInexact;
            while((matchesInexact = actions.GetAction("markExpressionOfBody").Match(procEnv, 1, param)).Count == 1)
            {
                actions.GetAction("markExpressionOfBody").Modify(procEnv, matchesInexact.First);
            }

            // application of a graph rewrite sequence
            procEnv.SetVariableValue("src", src);
            procEnv.SetVariableValue("tgt", tgt);
            procEnv.SetVariableValue("mb", mb);
            procEnv.SetVariableValue("op", op);
            procEnv.ApplyGraphRewriteSequence(
                @"(p)=someParameterOfTargetType(mb,tgt) 
                    && !callToSuperExists && !isStatic(mb) && !methodNameExists(mb,tgt) 
                    && (!thisIsAccessed || thisIsAccessed && (srcparam)=addSourceParameter(op,src) && useSourceParameter(srcparam)*) 
                    && relinkOperationAndMethodBody(op,mb,src,tgt) 
                    && ( (call,pe)=getUnprocessedCallWithActualParameter(op,p) 
                         && ((def(srcparam) && addSourceToCall(call,srcparam)) || true) 
                         && (replaceAccess_Parameter_AccessWithoutLink(c,pe) || replaceAccess_Parameter_AccessWithLinkToExpression(c,pe)) 
                       )*");

            Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found.");
            procEnv.PerformanceInfo.Reset();

            // unmark the body of the expression by searching all occurences and modifying them
            actions.unmarkExpression.ApplyAll(0, procEnv);
            graph.FreeVisitedFlag(visitedFlagId);

            // export changed graph (alternatively you may export it as InstanceGraphAfter.gxl)
            // if we'd use a NamedGraph we'd get the graph exported with its persistent names; so we get it exported with some hash names
            List<String> exportParameters = new List<string>();
            exportParameters.Add("InstanceGraphAfter.grs");
            Porter.Export(graph, exportParameters);
        }
 /// <summary>
 /// Adds an existing LGSPNode object to the graph and assigns it to the given variable.
 /// The node must not be part of any graph, yet!
 /// The node may not be connected to any other elements!
 /// </summary>
 /// <param name="node">The node to be added.</param>
 /// <param name="varName">The name of the variable.</param>
 public void AddNode(LGSPNode node, String varName)
 {
     graph.AddNodeWithoutEvents(node, node.lgspType.TypeID);
     SetVariableValue(varName, node);
     graph.NodeAdded(node);
 }
Ejemplo n.º 31
0
 public static Edge_connection CreateEdge(LGSPGraph graph, LGSPNode source, LGSPNode target)
 {
     Edge_connection edge = new Edge_connection(source, target);
     graph.AddEdge(edge);
     return edge;
 }
Ejemplo n.º 32
0
		public Edge_fluffway(LGSPNode source, LGSPNode target)
			: base(EdgeType_fluffway.typeVar, source, target) { }
Ejemplo n.º 33
0
 /// <summary>
 /// Retypes a node by creating a new node of the given type.
 /// All incident edges as well as all attributes from common super classes are kept.
 /// </summary>
 /// <param name="node">The node to be retyped.</param>
 /// <param name="newNodeType">The new type for the node.</param>
 /// <returns>The new node object representing the retyped node.</returns>
 public virtual LGSPNode Retype(LGSPNode node, NodeType newNodeType)
 {
     LGSPNode newNode = (LGSPNode) newNodeType.CreateNodeWithCopyCommons(node);
     RetypingNode(node, newNode);
     ReplaceNode(node, newNode);
     return newNode;
 }
Ejemplo n.º 34
0
 private @UEdge(GRGEN_MODEL.@UEdge oldElem, GRGEN_LGSP.LGSPNode newSource, GRGEN_LGSP.LGSPNode newTarget)
     : base(GRGEN_MODEL.EdgeType_UEdge.typeVar, newSource, newTarget)
 {
 }
Ejemplo n.º 35
0
 public @UEdge(GRGEN_LGSP.LGSPNode source, GRGEN_LGSP.LGSPNode target)
     : base(GRGEN_MODEL.EdgeType_UEdge.typeVar, source, target)
 {
     // implicit initialization, container creation of UEdge
 }
Ejemplo n.º 36
0
		public static Edge_fluffway CreateEdge(LGSPGraph graph, LGSPNode source, LGSPNode target)
		{
			Edge_fluffway edge = new Edge_fluffway(source, target);
			graph.AddEdge(edge);
			return edge;
		}
Ejemplo n.º 37
0
        public void AddNode(LGSPNode node, String elemName)
        {
            if(elemName != null && NameToElem.ContainsKey(elemName))
                throw new ArgumentException("The name \"" + elemName + "\" is already used!");

            if(elemName == null)
                elemName = GetNextName();

            AddNodeWithoutEvents(node, node.lgspType.TypeID);

            NameToElem[elemName] = node;
            ElemToName[node] = elemName;

            NodeAdded(node);
        }
Ejemplo n.º 38
0
 public override void AddNode(LGSPNode node)
 {
     AddNode(node, null);
 }
Ejemplo n.º 39
0
 public Edge_connection(LGSPNode source, LGSPNode target)
     : base(EdgeType_connection.typeVar, source, target) { }
Ejemplo n.º 40
0
 /// <summary>
 /// Sets source and target to the LGSPEdge object instantiated before with source and target being null.
 /// </summary>
 /// <param name="sourceNode">The source node.</param>
 /// <param name="targetNode">The target node.</param>
 public void SetSourceAndTarget(LGSPNode sourceNode, LGSPNode targetNode)
 {
     lgspSource = sourceNode;
     lgspTarget = targetNode;
 }
Ejemplo n.º 41
0
 public override LGSPNode Retype(LGSPNode node, NodeType newNodeType)
 {
     String name;
     if(ElemToName.TryGetValue(node, out name)) // give new node the name of the old node in case it was named
     {
         LGSPNode newNode = (LGSPNode)newNodeType.CreateNodeWithCopyCommons(node);
         ElemToName[newNode] = name;
         RetypingNode(node, newNode);
         ReplaceNode(node, newNode);
         ElemToName.Remove(node);
         NameToElem[name] = newNode;
         return newNode;
     }
     else
         return base.Retype(node, newNodeType);
 }
Ejemplo n.º 42
0
 public override LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target)
 {
     return AddEdge(edgeType, source, target, null);
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Builds a pattern graph out of the graph.
        /// The pattern graph retains links to the original graph elements and uses them for attribute comparison.
        /// </summary>
        /// <param name="graph">The graph which is to be transfered into a pattern</param>
        /// <returns></returns>
        private static PatternGraph BuildPatternGraph(IGraph graph)
        {
            int numNodes = graph.NumNodes;
            int numEdges = graph.NumEdges;

            int count = 0;

            PatternNode[] nodes = new PatternNode[numNodes];
            INode[]       correspondingNodes = new INode[numNodes];
            foreach (INode node in graph.Nodes)
            {
                LGSPNode n = (LGSPNode)node;
                nodes[count] = new PatternNode(
                    n.Type.TypeID, n.Type, n.Type.PackagePrefixedName,
                    graph.Name + "_node_" + count, "node_" + count,
                    null, null,
                    1.0f, -1, false,
                    null, null, null, null, null,
                    null, false, null
                    );
                correspondingNodes[count] = node;
                ++count;
            }

            count = 0;
            PatternEdge[] edges = new PatternEdge[numEdges];
            IEdge[]       correspondingEdges = new IEdge[numEdges];
            foreach (IEdge edge in graph.Edges)
            {
                LGSPEdge e = (LGSPEdge)edge;
                edges[count] = new PatternEdge(
                    true,
                    e.Type.TypeID, e.Type, e.Type.PackagePrefixedName,
                    graph.Name + "_edge_" + count, "edge_" + count,
                    null, null,
                    1.0f, -1, false,
                    null, null, null, null, null,
                    null, false, null
                    );
                correspondingEdges[count] = edge;
                ++count;
            }

            bool[,] homNodes = new bool[numNodes, numNodes];
            for (int i = 0; i < numNodes; ++i)
            {
                for (int j = 0; j < numNodes; ++j)
                {
                    homNodes[i, j] = false;
                }
            }

            bool[,] homEdges = new bool[numEdges, numEdges];
            for (int i = 0; i < numEdges; ++i)
            {
                for (int j = 0; j < numEdges; ++j)
                {
                    homEdges[i, j] = false;
                }
            }

            bool[,] homNodesGlobal = new bool[numNodes, numNodes];
            for (int i = 0; i < numNodes; ++i)
            {
                for (int j = 0; j < numNodes; ++j)
                {
                    homNodesGlobal[i, j] = false;
                }
            }

            bool[,] homEdgesGlobal = new bool[numEdges, numEdges];
            for (int i = 0; i < numEdges; ++i)
            {
                for (int j = 0; j < numEdges; ++j)
                {
                    homEdgesGlobal[i, j] = false;
                }
            }

            bool[] totallyHomNodes = new bool[numNodes];
            for (int i = 0; i < numNodes; ++i)
            {
                totallyHomNodes[i] = false;
            }

            bool[] totallyHomEdges = new bool[numEdges];
            for (int i = 0; i < numEdges; ++i)
            {
                totallyHomEdges[i] = false;
            }

            List <PatternCondition> pcs = new List <PatternCondition>();

            for (int i = 0; i < numNodes; ++i)
            {
                if (nodes[i].Type.NumAttributes > 0)
                {
                    pcs.Add(new PatternCondition(new expression.AreAttributesEqual(correspondingNodes[i], nodes[i]),
                                                 new string[] { nodes[i].name }, new string[] { }, new string[] { },
                                                 new PatternNode[] { nodes[i] }, new PatternEdge[] { }, new PatternVariable[] { }));
                }
            }
            for (int i = 0; i < numEdges; ++i)
            {
                if (edges[i].Type.NumAttributes > 0)
                {
                    pcs.Add(new PatternCondition(new expression.AreAttributesEqual(correspondingEdges[i], edges[i]),
                                                 new string[] { }, new string[] { edges[i].name }, new string[] { },
                                                 new PatternNode[] { }, new PatternEdge[] { edges[i] }, new PatternVariable[] { }));
                }
            }
            PatternCondition[] patternConditions = pcs.ToArray();

            PatternGraph patternGraph = new PatternGraph(
                graph.Name,
                nodes, edges,
                patternConditions,
                homNodes, homEdges,
                homNodesGlobal, homEdgesGlobal,
                totallyHomNodes, totallyHomEdges,
                correspondingNodes, correspondingEdges
                );

            foreach (PatternNode node in nodes)
            {
                node.pointOfDefinition = patternGraph;
            }
            foreach (PatternEdge edge in edges)
            {
                edge.pointOfDefinition = patternGraph;
            }

            foreach (IEdge edge in graph.Edges)
            {
                int edgeIndex   = Array.IndexOf <IEdge>(correspondingEdges, edge);
                int sourceIndex = Array.IndexOf <INode>(correspondingNodes, edge.Source);
                int targetIndex = Array.IndexOf <INode>(correspondingNodes, edge.Target);
                patternGraph.edgeToSourceNode.Add(edges[edgeIndex], nodes[sourceIndex]);
                patternGraph.edgeToTargetNode.Add(edges[edgeIndex], nodes[targetIndex]);
            }

            PatternGraphAnalyzer.PrepareInline(patternGraph);

            return(patternGraph);
        }
Ejemplo n.º 44
0
 public override void AddNode(LGSPNode node)
 {
     AddNode(node, null);
 }
Ejemplo n.º 45
0
        public static bool IsMatched(LGSPNode node, IMatch lastMatchAtPreviousNestingLevel)
        {
            Debug.Assert(lastMatchAtPreviousNestingLevel!=null);

            // move through matches stack backwards to starting rule,
            // check if node is already matched somewhere on the derivation path
            IMatch match = lastMatchAtPreviousNestingLevel;
            while (match != null)
            {
                for (int i = 0; i < match.NumberOfNodes; ++i)
                {
                    if (match.getNodeAt(i) == node)
                    {
                        return true;
                    }
                }
                match = match.MatchOfEnclosingPattern;
            }
            return false;
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Adds an existing node to this graph.
        /// The graph may not already contain the node!
        /// The edge may not be connected to any other elements!
        /// Intended only for undo, clone, retyping and internal use!
        /// </summary>
        public void AddNodeWithoutEvents(LGSPNode node, int typeid)
        {
#if CHECK_RINGLISTS
            CheckNodeAlreadyInTypeRinglist(node);
#endif
            LGSPNode head = nodesByTypeHeads[typeid];
            LGSPNode oldTypeNext = head.lgspTypeNext;
            LGSPNode oldTypePrev = head.lgspTypePrev;
            head.lgspTypeNext.lgspTypePrev = node;
            node.lgspTypeNext = head.lgspTypeNext;
            node.lgspTypePrev = head;
            head.lgspTypeNext = node;

            ++nodesByTypeCounts[typeid];

            ++changesCounter;

#if CHECK_RINGLISTS
            CheckTypeRinglistBroken(head);
#endif
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Changes the source node of the edge from the old source to the given new source.
 /// </summary>
 /// <param name="edge">The edge to redirect.</param>
 /// <param name="newSource">The new source node of the edge.</param>
 /// <param name="oldSourceName">The name of the old source node (used for debug display of the new edge).</param>
 public void RedirectSource(LGSPEdge edge, LGSPNode newSource, string oldSourceName)
 {
     RedirectingEdge(edge);
     RemovingEdge(edge);
     edge.lgspSource.RemoveOutgoing(edge);
     newSource.AddOutgoing(edge);
     edge.lgspSource = newSource;
     nameOfSingleElementAdded[0] = "redirected from " + oldSourceName + " --> .";
     SettingAddedEdgeNames(nameOfSingleElementAdded);
     EdgeAdded(edge);
     ++changesCounter;
 }
Ejemplo n.º 48
0
        /// <summary>
        /// Adds a new edge to the graph.
        /// </summary>
        /// <param name="edgeType">The edge type for the new edge.</param>
        /// <param name="source">The source of the edge.</param>
        /// <param name="target">The target of the edge.</param>
        /// <returns>The newly created edge.</returns>
        public virtual LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target)
        {
//            LGSPEdge edge = new LGSPEdge(edgeType, source, target);
            LGSPEdge edge = (LGSPEdge) edgeType.CreateEdge(source, target);
            AddEdgeWithoutEvents(edge, edgeType.TypeID);
            EdgeAdded(edge);
            return edge;
        }
Ejemplo n.º 49
0
 /// <summary>
 /// Checks if the given node is already available in its type ringlist
 /// </summary>
 public void CheckNodeAlreadyInTypeRinglist(LGSPNode node)
 {
     LGSPNode head = nodesByTypeHeads[node.lgspType.TypeID];
     LGSPNode cur = head.lgspTypeNext;
     while(cur != head)
     {
         if(cur == node) throw new Exception("Internal error: Node already available in ringlist");
         cur = cur.lgspTypeNext;
     }
     cur = head.lgspTypePrev;
     while(cur != head)
     {
         if(cur == node) throw new Exception("Internal error: Node already available in ringlist");
         cur = cur.lgspTypePrev;
     }
 }
        public IGraph _graph; // for ToString only

        public LGSPUndoElemRedirecting(LGSPEdge edge, LGSPNode source, LGSPNode target, LGSPGraphProcessingEnvironment procEnv)
        {
            _edge = edge;
            _source = source;
            _target = target;
            if(procEnv.graph is LGSPNamedGraph) _name = ((LGSPNamedGraph)procEnv.graph).GetElementName(_edge);
            else _name = "?";
            _graph = procEnv.graph;
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Checks whether the incoming or outgoing ringlists of the given node are broken.
 /// Use for debugging purposes.
 /// </summary>
 /// <param name="node">The node to be checked.</param>
 public void CheckInOutRinglistsBroken(LGSPNode node)
 {
     LGSPEdge inHead = node.lgspInhead;
     if(inHead != null)
     {
         LGSPEdge headNext = inHead.lgspInNext;
         if(headNext == null) throw new Exception("Internal error: in Ringlist broken");
         LGSPEdge cur = headNext;
         LGSPEdge next;
         while(cur != inHead)
         {
             if(cur != cur.lgspInNext.lgspInPrev) throw new Exception("Internal error: Ringlist out of order");
             next = cur.lgspInNext;
             if(next == null) throw new Exception("Internal error: Ringlist broken");
             if(next == headNext) throw new Exception("Internal error: Ringlist loops bypassing head");
             cur = next;
         }
     }
     if(inHead != null)
     {
         LGSPEdge headPrev = inHead.lgspInPrev;
         if(headPrev == null) throw new Exception("Internal error: Ringlist broken");
         LGSPEdge cur = headPrev;
         LGSPEdge prev;
         while(cur != inHead)
         {
             if(cur != cur.lgspInPrev.lgspInNext) throw new Exception("Internal error: Ringlist out of order");
             prev = cur.lgspInPrev;
             if(prev == null) throw new Exception("Internal error: Ringlist broken");
             if(prev == headPrev) throw new Exception("Internal error: Ringlist loops bypassing head");
             cur = prev;
         }
     }
     LGSPEdge outHead = node.lgspOuthead;
     if(outHead != null)
     {
         LGSPEdge headNext = outHead.lgspOutNext;
         if(headNext == null) throw new Exception("Internal error: Ringlist broken");
         LGSPEdge cur = headNext;
         LGSPEdge next;
         while(cur != outHead)
         {
             if(cur != cur.lgspOutNext.lgspOutPrev) throw new Exception("Internal error: Ringlist out of order");
             next = cur.lgspOutNext;
             if(next == null) throw new Exception("Internal error: Ringlist broken");
             if(next == headNext) throw new Exception("Internal error: Ringlist loops bypassing head");
             cur = next;
         }
     }
     if(outHead != null)
     {
         LGSPEdge headPrev = outHead.lgspOutPrev;
         if(headPrev == null) throw new Exception("Internal error: Ringlist broken");
         LGSPEdge cur = headPrev;
         LGSPEdge prev;
         while(cur != outHead)
         {
             if(cur != cur.lgspOutPrev.lgspOutNext) throw new Exception("Internal error: Ringlist out of order");
             prev = cur.lgspOutPrev;
             if(prev == null) throw new Exception("Internal error: Ringlist broken");
             if(prev == headPrev) throw new Exception("Internal error: Ringlist loops bypassing head");
             cur = prev;
         }
     }
 }
Ejemplo n.º 52
0
 public Edge_Edge(LGSPNode source, LGSPNode target)
     : base(EdgeType_Edge.typeVar, source, target) { }
Ejemplo n.º 53
0
        /// <summary>
        /// Moves the type list head of the given node after the given node.
        /// Part of the "list trick".
        /// </summary>
        /// <param name="elem">The node.</param>
        public void MoveHeadAfter(LGSPNode elem)
        {
            if(elem.lgspType == null) return;       // elem is head
            LGSPNode head = nodesByTypeHeads[elem.lgspType.TypeID];

            head.lgspTypePrev.lgspTypeNext = head.lgspTypeNext;
            head.lgspTypeNext.lgspTypePrev = head.lgspTypePrev;

            elem.lgspTypeNext.lgspTypePrev = head;
            head.lgspTypeNext = elem.lgspTypeNext;
            head.lgspTypePrev = elem;
            elem.lgspTypeNext = head;
        }
Ejemplo n.º 54
0
        public LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target, String elemName)
        {
            if(elemName != null && NameToElem.ContainsKey(elemName))
                throw new ArgumentException("The name \"" + elemName + "\" is already used!");

            if(elemName == null)
                elemName = GetNextName();

            //            LGSPEdge edge = new LGSPEdge(edgeType, source, target);
            LGSPEdge edge = (LGSPEdge)edgeType.CreateEdge(source, target);
            AddEdgeWithoutEvents(edge, edgeType.TypeID);

            NameToElem[elemName] = edge;
            ElemToName[edge] = elemName;

            EdgeAdded(edge);

            return edge;
        }
Ejemplo n.º 55
0
 /// <summary>
 /// Adds an existing LGSPNode object to the graph.
 /// The node must not be part of any graph, yet!
 /// The node may not be connected to any other elements!
 /// </summary>
 /// <param name="node">The node to be added.</param>
 public virtual void AddNode(LGSPNode node)
 {
     AddNodeWithoutEvents(node, node.lgspType.TypeID);
     NodeAdded(node);
 }
Ejemplo n.º 56
0
 public override LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target)
 {
     return(AddEdge(edgeType, source, target, null));
 }
Ejemplo n.º 57
0
        internal void RemoveNodeWithoutEvents(LGSPNode node, int typeid)
        {
            node.lgspTypePrev.lgspTypeNext = node.lgspTypeNext;
            node.lgspTypeNext.lgspTypePrev = node.lgspTypePrev;
            node.lgspTypeNext = null;
            node.lgspTypePrev = null;

            --nodesByTypeCounts[typeid];

            ++changesCounter;

            if(reuseOptimization)
                node.Recycle();

#if CHECK_RINGLISTS
            CheckTypeRinglistBroken(nodesByTypeHeads[typeid]);
#endif
        }
 /// <summary>
 /// Adds a new edge to the graph and assigns it to the given variable.
 /// </summary>
 /// <param name="edgeType">The edge type for the new edge.</param>
 /// <param name="source">The source of the edge.</param>
 /// <param name="target">The target of the edge.</param>
 /// <param name="varName">The name of the variable.</param>
 /// <returns>The newly created edge.</returns>
 public LGSPEdge AddEdge(EdgeType edgeType, LGSPNode source, LGSPNode target, String varName)
 {
     //            LGSPEdge edge = new LGSPEdge(edgeType, source, target);
     LGSPEdge edge = (LGSPEdge)edgeType.CreateEdge(source, target);
     graph.AddEdgeWithoutEvents(edge, edgeType.TypeID);
     SetVariableValue(varName, edge);
     graph.EdgeAdded(edge);
     return edge;
 }
Ejemplo n.º 59
0
        /// <summary>
        /// Replaces a given node by another one.
        /// All incident edges and variables are transferred to the new node.
        /// The attributes are not touched.
        /// This function is used for retyping.
        /// </summary>
        /// <param name="oldNode">The node to be replaced.</param>
        /// <param name="newNode">The replacement for the node.</param>
        public void ReplaceNode(LGSPNode oldNode, LGSPNode newNode)
        {
            if(oldNode.lgspType != newNode.lgspType)
            {
                if(!oldNode.Valid)
                    throw new Exception("Fatal failure at retyping: The old node is not a member of the graph (any more).");

				oldNode.lgspTypePrev.lgspTypeNext = oldNode.lgspTypeNext;
				oldNode.lgspTypeNext.lgspTypePrev = oldNode.lgspTypePrev;
				nodesByTypeCounts[oldNode.lgspType.TypeID]--;

                AddNodeWithoutEvents(newNode, newNode.lgspType.TypeID);
            }
            else
            {
                newNode.lgspTypeNext = oldNode.lgspTypeNext;
                newNode.lgspTypePrev = oldNode.lgspTypePrev;
                oldNode.lgspTypeNext.lgspTypePrev = newNode;
                oldNode.lgspTypePrev.lgspTypeNext = newNode;
            }
            oldNode.lgspTypeNext = newNode;			// indicate replacement (checked in rewrite for hom nodes)
			oldNode.lgspTypePrev = null;			// indicate node is node valid anymore

            // Reassign all outgoing edges
            LGSPEdge outHead = oldNode.lgspOuthead;
            if(outHead != null)
            {
                LGSPEdge outCur = outHead;
                do
                {
                    outCur.lgspSource = newNode;
                    outCur = outCur.lgspOutNext;
                }
                while(outCur != outHead);
            }
            newNode.lgspOuthead = outHead;

            // Reassign all incoming edges
            LGSPEdge inHead = oldNode.lgspInhead;
            if(inHead != null)
            {
                LGSPEdge inCur = inHead;
                do
                {
                    inCur.lgspTarget = newNode;
                    inCur = inCur.lgspInNext;
                }
                while(inCur != inHead);
            }
            newNode.lgspInhead = inHead;

            ++changesCounter;

            if(reuseOptimization)
                oldNode.Recycle();

#if CHECK_RINGLISTS
            CheckTypeRinglistBroken(nodesByTypeHeads[newNode.lgspType.TypeID]);
            CheckInOutRinglistsBroken(newNode);
#endif
        }
Ejemplo n.º 60
0
 /// <summary>
 /// Instantiates an LGSPEdge object.
 /// </summary>
 /// <param name="edgeType">The edge type.</param>
 /// <param name="sourceNode">The source node.</param>
 /// <param name="targetNode">The target node.</param>
 protected LGSPEdge(EdgeType edgeType, LGSPNode sourceNode, LGSPNode targetNode)
 {
     lgspType   = edgeType;
     lgspSource = sourceNode;
     lgspTarget = targetNode;
 }