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

* Library function lists:nth added to summary generation

* Repeated recursive grammar states ignored in summary generation
* Increased the number of constraints that the stack can contain to 20
* Slice of 3 benchmarks improved
parent 2366d705
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ public final class Config extends misc.Config
	/********************************************************************************************************************************/
	private static final Config config = new Config();
	public static final int MAX_PRODUCTION_DEPTH = 5;
	public static final int MAX_STACK_SIZE = 9;
	public static final int MAX_STACK_SIZE = 20;
	public static final LAST.Direction SLICE_DIRECTION = LAST.Direction.Backwards;
	public static final boolean GLOBAL_VARIABLES = false;
	public static final boolean PDG = true;
@@ -41,8 +41,6 @@ public final class Config extends misc.Config
	/********************************************************************************************************************************/
	/************************************************************ OBJECT ************************************************************/
	/********************************************************************************************************************************/
	public final int maxProductionDepth = 5;
	public final int maxStackSize = 9;

	/****************************************************************/
	/************************* Constructor **************************/
+36 −13
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@ import edg.config.Config;
import edg.graph.*;
import edg.slicing.Phase;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class GrammarConstraint extends EdgeConstraint {
	private final Grammar grammar;
@@ -65,20 +67,20 @@ public class GrammarConstraint extends EdgeConstraint {
	protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, int productionDepth)
	{
		if (phase.isInstanceof(Phase.Slicing))
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth);
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth, new HashMap<>());
		super.check(phase, Phase.SummaryGeneration);
		return super.wrap(super.push(phase, constraints));
	}
	protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AccessConstraint topConstraint, int productionDepth)
	{
		if (phase.isInstanceof(Phase.Slicing))
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth);
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth, new HashMap<>());
		super.check(phase, Phase.SummaryGeneration);
		return super.wrap(super.push(phase, constraints));
	}
	protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){
		if (phase.isInstanceof(Phase.Slicing))
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth);
			return this.resolveProductions(phase, edg, edge, constraints, productionDepth, new HashMap<>());
		super.check(phase, Phase.SummaryGeneration);
		return super.wrap(super.push(phase, constraints));
	}
@@ -91,7 +93,8 @@ public class GrammarConstraint extends EdgeConstraint {
	{
		if (topConstraint.operation == SeekingConstraint.Operation.Add)
			if (phase.isInstanceof(Phase.Slicing))
				return this.resolveProductions(phase, edg, edge, constraints, productionDepth);
				// NOT INTERESTED IN SEEKING CONSTRAINT GRAMMAR OPTIMIZATION
				return this.resolveProductions(phase, edg, edge, constraints, productionDepth, new HashMap<>());

		super.check(phase, Phase.SummaryGeneration);
		return super.wrap(super.push(phase, constraints));
@@ -102,15 +105,16 @@ public class GrammarConstraint extends EdgeConstraint {
		return super.wrap(super.push(phase, constraints));
	}

	private List<Constraints> resolveProductions(Phase phase, EDG edg, Edge edge, Constraints constraints, int productionDepth)
	private List<Constraints> resolveProductions(Phase phase, EDG edg, Edge edge, Constraints constraints, int productionDepth,
												 Map<GrammarConstraint, List<Constraints>> processedStates)
	{
		super.check(phase, Phase.Slicing);
		if (productionDepth == Config.MAX_PRODUCTION_DEPTH)
			throw new StackOverflowError();

		final List<Constraints> newConstraintsList = new LinkedList<>();
		final List<Production> productions = this.grammar.getProductions(this);

		productionLoop:
		for (Production production : productions)
		{
			final Constraints constraintsClone = (Constraints) constraints.clone();
@@ -121,20 +125,39 @@ public class GrammarConstraint extends EdgeConstraint {
// TODO NO SE SI ESTO PUEDE TENER CONSECUENCIAS, REVISAR.
// Esto es para que los summaries sin producciones que no pueden resolver una Seeking Constraint no se atraviesen
/* ************************************* */

if (!constraints.getEdgeConstraints().isEmpty())
	if(constraints.getEdgeConstraints().peek() instanceof SeekingConstraint && productionSize == 0)   
		continue;
//if (!constraints.getEdgeConstraints().isEmpty())
//	if(constraints.getEdgeConstraints().peek() instanceof SeekingConstraint && productionSize == 0)
//		continue;
/* ************************************* */
			for (int constraintIndex = 0; constraintIndex < productionSize; constraintIndex++)
			for (int productionIndex = 0; productionIndex < productionSize; productionIndex++)
			{
				final EdgeConstraint constraint = production.getEdgeConstraint(constraintIndex);
				final EdgeConstraint constraint = production.getEdgeConstraint(productionIndex);
				final List<Constraints> resolvedConstraintsList = new LinkedList<>();

				for (Constraints pendingConstraints : pendingConstraintsList)
				{
					final EdgeConstraint topConstraint = pendingConstraints.isEdgeConstraintsEmpty() ? null : pendingConstraints.peekEdgeConstraint();
					if (!(constraint instanceof GrammarConstraint))
						resolvedConstraintsList.addAll(constraint.resolve(phase, edg, edge, pendingConstraints, topConstraint, productionDepth + 1));
					else {
						Map<GrammarConstraint, List<Constraints>> newProcessedStates = new HashMap<>();
						newProcessedStates.putAll(processedStates);

						GrammarConstraint gConstraint = (GrammarConstraint) constraint;

						if (newProcessedStates.containsKey(gConstraint)) {
							if (newProcessedStates.get(gConstraint).contains(pendingConstraints))
								continue productionLoop;
						}
						else {
							newProcessedStates.put(gConstraint, new LinkedList<>());
						}
						newProcessedStates.get(gConstraint).add(pendingConstraints);

						resolvedConstraintsList.addAll(
								((GrammarConstraint) constraint)
										.resolveProductions(phase, edg, edge, pendingConstraints, productionDepth, newProcessedStates));
					}
				}
				pendingConstraintsList.clear();
				pendingConstraintsList.addAll(resolvedConstraintsList);
+80 −2
Original line number Diff line number Diff line
@@ -36,8 +36,14 @@ public class SummaryEdgeGenerator extends EdgeGenerator
			final Node callee = edg.getChild(call, Node.Type.Callee);
			final Node calleeResult = edg.getResFromNode(callee);
			final Set<Edge> callEdges = edg.getEdges(calleeResult, LAST.Direction.Forwards, Edge.Type.Call);
			if (!callEdges.isEmpty())
			if (!callEdges.isEmpty()) {
				continue;
			}

			if (isKnownModuleFunction(callee)) {
				buildSummaryEdges(call, callee);
				continue;
			}

			final Node callResult = edg.getResFromNode(call);
			final Node argumentsNode = edg.getChild(call, Node.Type.Arguments);
@@ -145,7 +151,10 @@ public class SummaryEdgeGenerator extends EdgeGenerator
			grammarConstraint.setFlowReached(true);
			grammar.removeControlReachingProductions(grammarConstraint);
		}
		if (!isLeftRecursiveGrammar(grammarConstraint, production)) {
		if (isLeftRecursiveGrammar(grammarConstraint, production)) {
			production.setLeftRecursive();
		}
		else{
			this.edg.addProduction(grammarConstraint, production);
		}

@@ -185,4 +194,73 @@ public class SummaryEdgeGenerator extends EdgeGenerator
		String stackBottomTerm = constraints.getEdgeConstraints().firstElement().toString();
		return grammarId.equals(stackBottomTerm);
	}

	private void buildSummaryEdges(Node call, Node callee) {
		Node scopeNode = this.edg.getChild(callee, Node.Type.Scope);
		Node scopeExpr = this.edg.getChild(scopeNode, Node.Type.Value);

		Node nameNode = this.edg.getChild(callee, Node.Type.Name);
		Node nameExpr = this.edg.getChild(nameNode, Node.Type.Value);

		buildSummaryEdges(call, scopeExpr, nameExpr);
	}

	private boolean isKnownModuleFunction(Node callee){
		// Search scope referred module
		Node scopeNode = this.edg.getChild(callee, Node.Type.Scope);
		Node scopeExpr = this.edg.getChild(scopeNode, Node.Type.Value);
		if (scopeExpr == null)
			return false;

		// Search name of the function
		Node nameNode = this.edg.getChild(callee, Node.Type.Name);
		Node nameExpr = this.edg.getChild(nameNode, Node.Type.Value);

		if (scopeExpr.getType() != Node.Type.Literal || nameExpr.getType() != Node.Type.Literal)
			return false;

		switch (scopeExpr.getName()){
			case "lists":
				switch (nameExpr.getName()){
					case "nth":
						return true;
					default:
						return false;
				}
			default:
				return false;
		}
	}

	private void buildSummaryEdges(Node call, Node scope, Node name){
		switch (scope.getName()){
			case "lists":
				switch (name.getName()) {
					case "nth":
						buildListsNthSummaries(call);
						break;
					default:
						break;
				}
				break;
			default:
				break;
		}
	}

	private void buildListsNthSummaries(Node call){
		final Node callResult = edg.getResFromNode(call);
		final Node argumentsNode = edg.getChild(call, Node.Type.Arguments);
		final List<Node> arguments = edg.getChildren(argumentsNode);
		arguments.removeIf(n -> n.getType() == Node.Type.Result);

		// First argument (Position)
		final Node firstArgumentResult = edg.getResFromNode(arguments.get(0));
		this.edg.addEdge(firstArgumentResult, callResult, new Edge(Edge.Type.Summary, AsteriskConstraint.getConstraint()));

		// Second argument (List)
		final Node secondArgumentResult = edg.getResFromNode(arguments.get(1));
		this.edg.addEdge(secondArgumentResult, callResult, new Edge(Edge.Type.Summary,
				new ListComprehensionConstraint(AccessConstraint.Operation.Add)));
	}
}
 No newline at end of file
+0 −7
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package edg.slicing;
import edg.constraint.Constraints;
import edg.constraint.EdgeConstraint;
import edg.constraint.NodeConstraint;
import edg.constraint.StructuralConstraint;
import edg.graph.EDG;
import edg.graph.Edge;
import edg.graph.LAST.Direction;
@@ -125,12 +124,6 @@ public class ConstrainedAlgorithm implements SlicingAlgorithm
			final EdgeConstraint constraint = currentEdge.getConstraint();
			final EdgeConstraint topConstraint = constraintsClone.isEdgeConstraintsEmpty() ? null : constraintsClone.peekEdgeConstraint();

			// Forbid valueStructure arc traversal in case:
			// 	1) the stack is not empty and
			// 	2) the topConstraint is not a StructureConstraint
			if (edgeType == Edge.Type.ValueStructure && topConstraint != null && !(topConstraint instanceof StructuralConstraint))
				return newWorks;

			final List<Constraints> newConstraintsList = constraint.resolve(phase, edg, currentEdge, constraintsClone, topConstraint, 0);

			for (Constraints newConstraints : newConstraintsList)
+29 −69
Original line number Diff line number Diff line
@@ -8,75 +8,35 @@ main(Number)
        andalso
        Number < 7 ->
    Database =
        [["Rihanna",
          28,
          {albums,
           [{"Music of the Sun", 2005},
            {"A Girl like me", 2006},
            {"Good Girl Gone Bad", 2007},
            {"Rater D", 2009},
            {"Loud", 2010},
            {"Talk That Talk", 2011},
            {"Unapologetic", 2012},
            {"ANTi", 2016}]},
          {concerts,
           [{"Amsterdam", {2016, 6, 17}},
            {"Manchester", {2016, 6, 29}},
            {"Barcelona", {2016, 7, 21}},
            {"Bucarest", {2017, 8, 14}}]}],
         ["Christina Aguilera",
          35,
          {albums,
           [{"Christina Aguilera", 1999},
            {"Mi Reflejo", 2000},
            {"Stripped", 2002},
            {"Back to Basics", 2006},
            {"Bionic", 2010},
            {"Lotus", 2012}]},
          {concerts,
           [{"Tokio", {2007, 6, 21}}, {"Abu Dabi", {2008, 10, 28}}]}],
         ["Bruno Mars",
          30,
          {albums,
           [{"Doo-Wops & Hooligans", 2010},
            {"Unorthodox Jukebox", 2012}]},
          {concerts,
           [{"Santo Domingo", {2014, 10, 4}},
            {"Las Vegas", {2014, 10, 18}},
            {"Liverpool", {2013, 11, 24}}]}],
         ["Daddy Yankee",
          39,
          {albums,
           [{"No Mercy", 1995},
            {"El Cangri.Com", 2002},
            {"Barrio Fino", 2004},
            {"El Cartel: The Big Boss", 2007},
            {"Mundial", 2010},
            {"Prestige", 2012},
            {"Cartel IV", 2015}]},
          {concerts,
           [{"Mexico City", {2015, 11, 8}},
            {"Las Vegas", {2016, 5, 6}},
            {"New York", {2017, 7, 30}}]}],
         ["Justin Bieber",
          22,
          {albums,
           [{"My World 2.0", 2010},
            {"Under the mistletoe", 2011},
            {"Believe", 2012},
            {"Purpose", 2015}]},
          {concerts,
           [{"Miami", {2016, 7, 3}},
            {"Munich", {2016, 9, 16}},
            {"Birmingham", {2017, 10, 24}}]}],
         ["Adele",
          28,
          {albums, [{"19", 2008}, {"21", 2011}, {"25", 2015}]},
          {concerts,
           [{"Lisboa", {2016, 5, 22}},
            {"Paris", {2016, 6, 10}},
            {"Oakland", {2016, 8, 2}},
            {"Toronto", {2017, 10, 6}}]}]],
        [[sliced, sliced, sliced,
          {sliced,
           [{sliced, {2016, 6, 17}},
            {sliced, {2016, 6, 29}},
            {sliced, {2016, 7, 21}},
            {sliced, {2017, 8, 14}}]}],
         [sliced, sliced, sliced,
          {sliced, [{sliced, {2007, 6, 21}}, {sliced, {2008, 10, 28}}]}],
         [sliced, sliced, sliced,
          {sliced,
           [{sliced, {2014, 10, 4}},
            {sliced, {2014, 10, 18}},
            {sliced, {2013, 11, 24}}]}],
         [sliced, sliced, sliced,
          {sliced,
           [{sliced, {2015, 11, 8}},
            {sliced, {2016, 5, 6}},
            {sliced, {2017, 7, 30}}]}],
         [sliced, sliced, sliced,
          {sliced,
           [{sliced, {2016, 7, 3}},
            {sliced, {2016, 9, 16}},
            {sliced, {2017, 10, 24}}]}],
         [sliced, sliced, sliced,
          {sliced,
           [{sliced, {2016, 5, 22}},
            {sliced, {2016, 6, 10}},
            {sliced, {2016, 8, 2}},
            {sliced, {2017, 10, 6}}]}]],
    Artist = lists:nth(Number, Database),
    NextConcert = getNextConcert(Artist),
    Info = getConcertLocationAndYear(NextConcert),
Loading