// Path: src/main/wcanalysis/heuristic/ContextManager.java
// static class CGContext {
//   final StackFrame stackFrame;
//   final StateBuilder stateBuilder;
//     
//   public CGContext(StackFrame sf, StateBuilder stateBuilder) {
//     this.stackFrame = sf;
//     this.stateBuilder = stateBuilder;
//   }
// }


import gov.nasa.jpf.vm.StackFrame;
import wcanalysis.heuristic.ContextManager.CGContext;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.vm.ChoiceGenerator;
/*
 * MIT License
 *
 * Copyright (c) 2017 The ISSTAC Authors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package wcanalysis.heuristic;



/**
 * @author Kasper Luckow
 * TODO: Clean up how (sub)paths can be generated (static methods, from CGs, ...)
 * both context preserving and not context preserving. 
 */
public class Path extends ArrayList<Decision> {
  
  private static final long serialVersionUID = -1691414612424473640L;
  
  public Path() { }

  public Path(Path other) {
    super(other);
  }
  
  //TODO: ugly
  public static Path generateCtxPreservingHistory(ChoiceGenerator<?> endCG, ContextManager ctxManager, int maxSize) {
    Path p = new Path();
    if(maxSize <= 0)
      return p;
    PCChoiceGenerator previousPCcg = endCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
    generatePath(p, previousPCcg, ctxManager, ctxManager.getContext(endCG), true, maxSize);
    return p;
  }
  
// Path: src/main/wcanalysis/heuristic/ContextManager.java
// static class CGContext {
//   final StackFrame stackFrame;
//   final StateBuilder stateBuilder;
//     
//   public CGContext(StackFrame sf, StateBuilder stateBuilder) {
//     this.stackFrame = sf;
//     this.stateBuilder = stateBuilder;
//   }
// }


// Path: src/main/wcanalysis/heuristic/Path.java
import gov.nasa.jpf.vm.StackFrame;
import wcanalysis.heuristic.ContextManager.CGContext;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.vm.ChoiceGenerator;

/*
 * MIT License
 *
 * Copyright (c) 2017 The ISSTAC Authors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package wcanalysis.heuristic;



/**
 * @author Kasper Luckow
 * TODO: Clean up how (sub)paths can be generated (static methods, from CGs, ...)
 * both context preserving and not context preserving. 
 */
public class Path extends ArrayList<Decision> {
  
  private static final long serialVersionUID = -1691414612424473640L;
  
  public Path() { }

  public Path(Path other) {
    super(other);
  }
  
  //TODO: ugly
  public static Path generateCtxPreservingHistory(ChoiceGenerator<?> endCG, ContextManager ctxManager, int maxSize) {
    Path p = new Path();
    if(maxSize <= 0)
      return p;
    PCChoiceGenerator previousPCcg = endCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
    generatePath(p, previousPCcg, ctxManager, ctxManager.getContext(endCG), true, maxSize);
    return p;
  }
  
  private static void generatePath(Path path, ChoiceGenerator<?> endCG, ContextManager ctxManager, CGContext ctx, boolean ctxPreserving, int maxSize) {