Commit 89af17e2 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Add an output cell argument for the depth first walker interface.

To avoid having each generator contain the knowledge of how to grab the output
cell's contents, add a parameter to each walker that exposes this information
when hitting the leaf cells of the hierarchy.
parent 6bdf0208
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ final public class HierarchicalGridEventBGenerator implements HierarchicalGridDe
    }

    @Override
    public void handleLeafCell(Cell cell) {
    public void handleLeafCell(Cell cell, Map<Variable, Cell> outputCells) {
        m_tableRowNo++;
        m_subGridCellIndex++;
        generatorGenerateEventNo();
+5 −4
Original line number Diff line number Diff line
@@ -29,14 +29,15 @@

package ca.mcscert.jtet.salgenerator;

import ca.mcscert.jtet.expression.BooleanVariableType;
import ca.mcscert.jtet.expression.RealVariableType;
import ca.mcscert.jtet.expression.VariableCollection;
import ca.mcscert.jtet.expression.*;
import ca.mcscert.jtet.parsers.MatlabParser;
import ca.mcscert.jtet.tablularexpression.Cell;
import ca.mcscert.jtet.tablularexpression.HierarchicalGridDepthFirstCheckerGenerator;
import ca.mcscert.jtet.tablularexpression.TwoDimensionalGrid;

import java.util.List;
import java.util.Map;

/**
 * Created by matthew on 6/3/14.
 */
@@ -77,7 +78,7 @@ public class HierarchicalGridSALGenerator implements HierarchicalGridDepthFirstC
    }

    @Override
    public void handleLeafCell(Cell cell)
    public void handleLeafCell(Cell cell, Map<Variable, Cell> outputCells)
    {
        outputCellPrelude(cell);
        result.append(getOutputCellAsSALCode(m_rightMostGridIndex++));
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@
 */
package ca.mcscert.jtet.tablularexpression;

import ca.mcscert.jtet.expression.Variable;

import java.util.Map;

/**
 *
 * @author Matthew Dawson <matthew@mjdsystems.ca>
@@ -36,7 +40,7 @@ public interface HierarchicalGridDepthFirstCheckerGenerator {
    void descendIntoGridFromCell(Cell cell);
    void ascendFromGrid();

    void handleLeafCell(Cell cell);
    void handleLeafCell(Cell cell, Map<Variable, Cell> outputCells);
    void handleEdgeCell(Cell cell);

    String getFinalString();
+11 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import ca.mcscert.jtet.expression.Variable;
import ca.mcscert.jtet.expression.VariableCollection;

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

@@ -79,24 +80,30 @@ public class Table {
        return m_variables;
    }

    private static void HandleGrid(SubHierarchyFetcher grid, HierarchicalGridDepthFirstCheckerGenerator generator) {
    private int HandleGrid(SubHierarchyFetcher grid, HierarchicalGridDepthFirstCheckerGenerator generator, int outputCellIndex) {
        List<HierarchicalCell> cells = grid.getSubHierarchy();
        for (int i = 0; i < cells.size(); ++i) {
            HierarchicalCell cell = cells.get(i);

            if (cell.getSubHierarchy().isEmpty()) {
                generator.handleLeafCell(cell);
                Map<Variable, Cell> outputCells = new LinkedHashMap<Variable, Cell>();
                for(Variable outputVariable : m_variables.getOutputVariables().values()) {
                    outputCells.put(outputVariable, variableOutputs.get(outputVariable).get(0, outputCellIndex));
                }
                generator.handleLeafCell(cell, outputCells);
                outputCellIndex++;
            } else {
                generator.handleEdgeCell(cell);
                generator.descendIntoGridFromCell(cell);
                HandleGrid(cell, generator);
                outputCellIndex = HandleGrid(cell, generator, outputCellIndex);
                generator.ascendFromGrid();
            }
        }
        return outputCellIndex;
    }

    public String walk(HierarchicalGridDepthFirstCheckerGenerator generator) {
        HandleGrid(leftGrid, generator);
        HandleGrid(leftGrid, generator, 0);
        return generator.getFinalString();
    }