void DoEdge1() { graph = new StdGraph(); actions = new edge1Actions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("init3"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use old inexact interface IMatches matches = actions.GetAction("findTripleCircle").Match(procEnv, 0, null); Console.WriteLine(matches.Count + " matches found."); // use new exact interface IMatchesExact <Rule_findTripleCircle.IMatch_findTripleCircle> matchesExact = actions.findTripleCircle.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " matches found."); actions.findTripleCircle.Modify(procEnv, matchesExact.FirstExact); // rewrite first match (largely nop, as findTripleCircle is a test) }
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 DoIter() { graph = new LGSPGraph(new StdGraphModel()); actions = new spanningTreeActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); IAction_initUndirected init = actions.initUndirected; IMatchesExact <Rule_initUndirected.IMatch_initUndirected> matchesInitUndirected = init.Match(procEnv, 0); INode root; init.Modify(procEnv, matchesInitUndirected.FirstExact, out root); IMatchesExact <Rule_spanningTree.IMatch_spanningTree> matchesSpanningTree = actions.spanningTree.Match(procEnv, 0, root); actions.spanningTree.Modify(procEnv, matchesSpanningTree.FirstExact); Console.WriteLine(matchesSpanningTree.Count + " matches found."); }
void DoFPE() { graph = new FunctionsProceduresExampleGraph(); actions = new FunctionsProceduresExampleActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("init"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use new 2.5 exact interface IMatchesExact <Rule_r.IMatch_r> matchesExact = actions.r.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " matches found."); actions.r.Modify(procEnv, matchesExact.FirstExact); }
// Have a look at the .gm + .grg, the ExternalFiltersAndSequencesActionsExternalFunctions.cs, // and the ExternalFiltersAndSequencesActionsExternalFunctionsImpl.cs files. // They show how to declare external match filters and external sequences in the rules file, // and how to use them in the sequences in the rule file or the shell script file. // The generated XXXExternalFunctions.cs file contains the partial classes of the filters and sequences // and the manually coded XXXExternalFunctionsImpl.cs file exemplifies how to implement these external functions. void DoEFS() { graph = new ExternalFiltersAndSequencesGraph(); actions = new ExternalFiltersAndSequencesActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("(::n)=init"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use new 2.5 exact interface IMatchesExact <Rule_r.IMatch_r> matchesExact = actions.r.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " matches found."); actions.r.Modify(procEnv, matchesExact.FirstExact); procEnv.ApplyGraphRewriteSequence("(::x,::y,::z,::u,::v)=foo(42, 3.141, Enu::hurz, \"S21-heiteitei\", true)"); procEnv.ApplyGraphRewriteSequence("filterBase\\f1"); }
void DoTNT() { graph = new LGSPGraph(new TNTGraphModel()); actions = new TNTActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("createTNT"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use old inexact interface IMatches matchesInexact = actions.GetAction("TNT").Match(procEnv, 0, null); Console.WriteLine(matchesInexact.Count + " matches found."); // use new 2.5 exact interface IMatchesExact <Rule_ToluolCore.IMatch_ToluolCore> matchesExact = actions.ToluolCore.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " matches found."); }
void DoAlt() { graph = new LGSPGraph(new AlternativesGraphModel()); actions = new AlternativesActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // use graph rewrite sequence procEnv.ApplyGraphRewriteSequence("createComplex"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); // use old inexact interface IMatches matches = actions.GetAction("Complex").Match(procEnv, 0, null); Console.WriteLine(matches.Count + " Complex matches found."); // use new 2.5 exact interface IMatchesExact <Rule_ComplexMax.IMatch_ComplexMax> matchesExact = actions.ComplexMax.Match(procEnv, 0); Console.WriteLine(matchesExact.Count + " ComplexMax matches found."); }
void DoIdpt() { graph = new LGSPGraph(new IndependentGraphModel()); actions = new IndependentActions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); procEnv.ApplyGraphRewriteSequence("create"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); IMatches matches = actions.GetAction("findIndependent").Match(procEnv, 0, null); Console.WriteLine(matches.Count + " matches found."); graph.Clear(); procEnv.ApplyGraphRewriteSequence("createIterated"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); Console.WriteLine(procEnv.PerformanceInfo.RewritesPerformed + " rewrites performed."); procEnv.PerformanceInfo.Reset(); IAction_createIterated createIterated = actions.createIterated; IMatchesExact <Rule_createIterated.IMatch_createIterated> matchesCreateIterated = createIterated.Match(procEnv, 0); IintNode beg; INode end; createIterated.Modify(procEnv, matchesCreateIterated.FirstExact, out beg, out end); IMatchesExact <Rule_findChainPlusChainToIntIndependent.IMatch_findChainPlusChainToIntIndependent> matchesFindChain = actions.findChainPlusChainToIntIndependent.Match(procEnv, 0, beg, end); Console.WriteLine(matchesFindChain.Count + " matches found."); }
void DoIt() { // create the LibGr Search Plan backend we want to use LGSPBackend backend = LGSPBackend.Instance; // 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); }