Commit 91e8eaea authored by Sergio Pérez's avatar Sergio Pérez
Browse files

FIXES AND SUMMARY IMPROVEMENTS

* Erlang script path defined
* Fixes in code generation: some sliced expressions removed instead of replaced
* Fix guard stacks in CFG generation
* Logic simplification in Node-Result creation process
* Fixed dead clause detection
* Improvements added to summary generation:
    + Function calls associated to a particular formal-out-formal-in summary edge are only repended when the grammar term is created, and not for each added production
    + The list of constraints stacked after an AsteriskConstraint are removed when another AsteriskConstraint is pushed to the stack
parent 29d39027
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import java.io.File;
import java.util.*;
import java.util.function.Predicate;

import edg.constraint.AccessConstraint;
import edg.constraint.EdgeConstraint;
import edg.graph.EDG;
import edg.graph.Edge;
@@ -77,13 +78,17 @@ public class DotFactory {
			if (edgeType == Edge.Type.Structural)
				return true;

// SHOW ONLY VALUE EDGES WITH ACCESS CONSTRAINTS
//if (edgeType == Edge.Type.Value)
// 	return edge.getConstraint() instanceof AccessConstraint;

			return (edgeFlags == null || edgeFlags.get(edgeType)) &&
					!ignoreEdgeTypes.contains(edgeType) &&
					(edgeTypes.isEmpty() || edgeTypes.contains(edgeType)) &&
					(idFrom >= lowerBound && idTo >= lowerBound && idFrom <= upperBound && idTo <= upperBound) &&
					(nodeIds.isEmpty() || nodeIds.contains(idFrom) || nodeIds.contains(idTo))
					&& ((!ignoredNodeIds.contains(idFrom) && !ignoredNodeIds.contains(idTo))
					&& !(edgeType == Edge.Type.Control && edg.getNode(idFrom).getType() == Node.Type.Clause)); //IGNORE CLAUSE CONTROL EDGES TO ALL ELEMENTS
					&& !(edgeType == Edge.Type.Control && (edg.getNode(idFrom).getType() == Node.Type.Clause || edg.getNode(idFrom).getType() == Node.Type.Parameters))); //IGNORE CLAUSE CONTROL EDGES TO ALL ELEMENTS
		});

		DOTExporter<Node, Edge> exporter = new DOTExporter<>(
+4 −29
Original line number Diff line number Diff line
@@ -89,22 +89,6 @@ public class EDGFactory {

		// new ExceptionEdgeGenerator(edg).generate();
	}
	//	private void generateDependencies()
//	{
//		new ControlEdgeGenerator(edg).generate();
//		new ModuleEdgeGenerator(edg).generate();
//
//		InterproceduralEdgeGenerator ieg = new InterproceduralEdgeGenerator(edg);
//		if (isOOLanguage)
//			ieg.generateCallEdges(); // Specially Generated for OOPrograms
//		else
//			new InterproceduralEdgeGenerator(edg).generateNoInheritance(); // TODO Implement without module analysis
//
//		new FlowEdgeGenerator(edg).generate();
//		ieg.generateIO();
//		new SummaryEdgeGenerator(edg).generate();
////		new ExceptionEdgeGenerator(edg).generate();
//	}

	private void createNodeResultStructures(Node node)
	{
@@ -137,19 +121,10 @@ public class EDGFactory {
		edg.addStructuralEdge(parent, result);

		// Modify Value Arcs
		switch (node.getType())
		{
			case DataConstructor:
				final boolean isPatternZone = edg.isPatternZone(node);
				if (!isPatternZone)
				{
		if (node.getType() == Node.Type.DataConstructor && !edg.isPatternZone(node))
			treatDataConstructorExpressions(node, result);
					break;
				}
			default:
		else
			treatCommonNodes(node, result);
				break;
		}

		// Value arcs between initial node and its result
		edg.addEdge(node, result, Edge.Type.Value);
+25 −1
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ public class AsteriskConstraint extends EdgeConstraint
			return super.wrap(new Constraints());
		super.check(phase, Phase.SummaryGeneration);

		if (existsPreviousAsteriskConstraint(constraints))
			return super.wrap(this.popToAsteriskConstraint(constraints));

		if (topConstraint.operation == AccessConstraint.Operation.Remove)
			return super.wrap(super.push(phase, constraints));
		super.check(topConstraint.operation, AccessConstraint.Operation.Add);
@@ -53,6 +56,9 @@ public class AsteriskConstraint extends EdgeConstraint
	{
		super.check(phase, Phase.SummaryGeneration);

		if (existsPreviousAsteriskConstraint(constraints))
			return super.wrap(this.popToAsteriskConstraint(constraints));

		return super.wrap(super.push(phase, constraints));
	}
	protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, SeekingConstraint topConstraint, int productionDepth)
@@ -61,6 +67,9 @@ public class AsteriskConstraint extends EdgeConstraint
			return super.wrap(new Constraints());
		super.check(phase, Phase.SummaryGeneration);

		if (existsPreviousAsteriskConstraint(constraints))
			return super.wrap(this.popToAsteriskConstraint(constraints));

		if (topConstraint.operation == SeekingConstraint.Operation.LetThrough || topConstraint.operation == SeekingConstraint.Operation.Remove)
			return super.wrap(super.push(phase, constraints));
		super.check(topConstraint.operation, SeekingConstraint.Operation.Add);
@@ -76,7 +85,22 @@ public class AsteriskConstraint extends EdgeConstraint
	protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AsteriskConstraint topConstraint, int productionDepth)
	{
		super.check(phase, Phase.SummaryGeneration);

		return super.wrap(constraints);
	}

	private boolean existsPreviousAsteriskConstraint(Constraints constraints){
		for(Constraint c : constraints.getEdgeConstraints())
			if (c instanceof AsteriskConstraint)
				return true;
		return false;
	}

	private Constraints popToAsteriskConstraint(Constraints constraints){
		Constraint topConstraint = constraints.getEdgeConstraints().peek();
		while(!(topConstraint instanceof AsteriskConstraint)){
			constraints.getEdgeConstraints().pop();
			topConstraint = constraints.getEdgeConstraints().peek();
		}
		return constraints;
	}
}
 No newline at end of file
+6 −1
Original line number Diff line number Diff line
@@ -334,7 +334,6 @@ public class InterproceduralEdgeGenerator extends EdgeGenerator

		for (Node matchingClause : matchingClauses)
		{
			final Node clauseResult = edg.getResFromNode(matchingClause);
			final Node parameters = edg.getChild(matchingClause, Node.Type.Parameters);
			final List<Node> parameterNodes = edg.getChildren(parameters);
			parameterNodes.removeIf(n -> n.getType() == Node.Type.Result);
@@ -479,6 +478,12 @@ public class InterproceduralEdgeGenerator extends EdgeGenerator
			allMatch = allMatch && matchStatus.isMatch();
			allComplete = allComplete && matchStatus.isCompleteMatch();
		}
		if (allComplete){
			Node guard = edg.getChild(possibleClause, Node.Type.Guard);
			if (!edg.getChildren(guard).isEmpty())
				allComplete = false;
		}

		return new MatchStatus(allMatch,allComplete);
	}

+10 −32
Original line number Diff line number Diff line
@@ -55,37 +55,16 @@ public class SummaryEdgeGenerator extends EdgeGenerator
	/* ********************************** */
	/* ************ Internal ************ */
	/* ********************************** */
private final Map<String, Integer> ids = new Hashtable<>();
	private void generateInternalSummaryEdges()
	{
		final List<Work> initialWorks = this.getInitialWorks();
		final WorkList workList = new WorkList(initialWorks);
		final ConstrainedAlgorithm slicingAlgorithm = new ConstrainedAlgorithm(edg);

long worksProcessed = 0;
		while (workList.hasMore())
		{
		
//if (workList.getPendingWorks().size() == 1)
//	System.out.println("PARA");
//if (workList.getPendingWorks().containsKey("203->228"))
//	System.out.println("Aun esta 1");
			final Work work = workList.next();
//if (workList.contains(work))
//	continue;
			
// TODO Borrame
//worksProcessed++;
//final String id = work.getId();
//final Integer prev = ids.get(id);
//ids.put(id, prev == null ? 0 : prev + 1);
//if (prev != null && prev == 100000)
//System.out.println(work.getId() + " - " + work.getConstraints().getEdgeConstraints().toString());
			final Node initialNode = work.getInitialNode();
			
//final int initialNodeId = initialNode.getId();
//if(initialNodeId == 48)
//	System.out.print("");
			final Constraints constraints = work.getConstraints();
			boolean isFormalIn = false;
			
@@ -93,9 +72,6 @@ long worksProcessed = 0;
			{
				final NodeWork nodeWork = (NodeWork) work;
				final Node currentNode = nodeWork.getCurrentNode();
//final int currentNodeId = currentNode.getId();
//if(currentNodeId == 228)
//System.out.println(" Node "+currentNodeId);

				// The current node is the clause node of the initial node or the routine node of this clause result
				if (currentNode == edg.getNodeFromRes(initialNode) || currentNode == edg.getParent(initialNode))
@@ -117,14 +93,8 @@ long worksProcessed = 0;
				continue;

			final List<Work> newWorks = slicingAlgorithm.processWork(Phase.SummaryGeneration, work);
//if(initialNodeId == 48)
//	System.out.print("");
			workList.pendAll(newWorks);
		}
// TODO Borrame
//System.out.println("Works done: " + workList.getDoneNodes().size());
//System.out.println("Works processed: " + worksProcessed);
//System.out.println();
	}
	private List<Work> getInitialWorks()
	{
@@ -137,6 +107,11 @@ long worksProcessed = 0;
			final List<Node> clauses = edg.getChildrenNonResult(routine);
			for (Node clause : clauses)
			{
				Set<Edge> incomingEdges = edg.getEdges(clause,Direction.Backwards);
				incomingEdges.removeIf(e -> e.getType() != Edge.Type.Call);
				if (incomingEdges.isEmpty())
					continue;

				// Summary Edges for the result node
				final Node clauseResult = edg.getResFromNode(clause);
				workList.add(new NodeWork(clauseResult, clauseResult, new Constraints()));
@@ -163,11 +138,14 @@ long worksProcessed = 0;
	{
		final Grammar grammar = this.edg.getGrammar();
		final GrammarConstraint grammarConstraint = new GrammarConstraint(grammar, formalIn);
		boolean isNewGrammarTerm = grammar.isNewGrammarTerm(grammarConstraint);
		this.edg.addProduction(grammarConstraint, constraints);

		final List<Node> nodesToContinue = new LinkedList<>();
		final List<Node> inputs = edg.getInputs(formalIn, Direction.Backwards);
		if (!isNewGrammarTerm)
			return nodesToContinue;

		final List<Node> inputs = edg.getInputs(formalIn, Direction.Backwards);
		for (Node input : inputs)
		{
			final Node call = edg.getAncestor(input, Node.Type.Call);
Loading