Commit 8cc90bb6 authored by EmaJasekova's avatar EmaJasekova
Browse files

Added Source Files

parent d2d3bba5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@ public class ConstraintsViewer extends TextViewerBase {

    public void showConstraints(ExecutionState executionState) {
        textArea.setText("");
        for (String constraint : executionState.constraints) {
        for (String constraint : executionState.constraints)
            textArea.append(constraint + "\n");
        }
        textArea.setCaretPosition(0);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ public class ContextViewer extends TextViewerBase {

    public void showContext(ExecutionState executionState) {
        textArea.setText("");
//        textArea.append(node.other.toString());
        textArea.append(executionState.context.toString());
        textArea.setCaretPosition(0);
    }
}
+1 −2
Original line number Diff line number Diff line
package jetklee;

import javax.swing.*;

public class MemoryViewer extends TextViewerBase {
    public MemoryViewer() {
        super();
@@ -20,5 +18,6 @@ public class MemoryViewer extends TextViewerBase {
            textArea.append(executionState.objectStates.get(i).toString());
            textArea.append("\n\n");
        }
        textArea.setCaretPosition(0);
    }
}
+97 −118
Original line number Diff line number Diff line
@@ -14,8 +14,18 @@ public class ProgressExplorer implements ListSelectionListener, MouseWheelListen
    private static final int ARGS_COUNT = 1;
    private Tree tree;
    private TreeViewer treeViewer;
    private SourceMapping sourceMapping;
    private SourceViewerC sourceC;
    private SourceViewerLL sourceLL;
    private JPanel rootPanel;
    private JList<String> roundsList;
    private JTabbedPane mainTabbedPane;
    private JTabbedPane leftTabbedPane;
    private JSplitPane splitPane;
    private JScrollPane roundScrollPane;
    private JSplitPane mainSplitPane;
    private JPanel treePanel;
    private JScrollPane treeScrollPane;
    private ConstraintsViewer constraintsViewer;
    private MemoryViewer memoryViewer;
    private ContextViewer contextViewer;
@@ -24,128 +34,99 @@ public class ProgressExplorer implements ListSelectionListener, MouseWheelListen
    public ProgressExplorer() {
        tree = new Tree();
        treeViewer = new TreeViewer(tree);
        rootPanel = new JPanel(new BorderLayout());
        treeViewer.addMouseListener(this);

        sourceMapping = new SourceMapping();
        sourceC = new SourceViewerC(sourceMapping);
        sourceLL = new SourceViewerLL(sourceMapping);

        constraintsViewer = new ConstraintsViewer();
        memoryViewer = new MemoryViewer();
        contextViewer = new ContextViewer();
        divider = 800;
//        ListSelectionModel model = roundsList.getSelectionModel();
    }

    public void valueChanged(ListSelectionEvent e) {
        if (e.getSource() != roundsList) return;
        if (roundsList.getValueIsAdjusting()) return;
        if (roundsList.getSelectedIndex() < 0) return;
        treeViewer.selectedRound = roundsList.getSelectedIndex();
        treeViewer.updateArea();
    }

    private void showNodeInformation(Node node) {
        contextViewer.showContext(node.executionState);
        constraintsViewer.showConstraints(node.executionState);
        memoryViewer.showMemory(node.executionState);

        constraintsViewer.textArea.setCaretPosition(0);
        memoryViewer.textArea.setCaretPosition(0);
        contextViewer.textArea.setCaretPosition(0);
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("JetKlee: ProgressExplorer");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setPreferredSize(new Dimension(800, 600));
        divider = 1000;

                ProgressExplorer explorer = new ProgressExplorer();
                if (args.length != ARGS_COUNT) {
                    throw new IllegalArgumentException("Invalid number of arguments. Expected " + ARGS_COUNT + " arguments.");
                }

                try {
                    explorer.tree.loadFiles(Paths.get(args[0]));
                } catch (Exception e) {
                    System.out.println("File load failed: " + e);
                    return;
                }
                explorer.treeViewer.load();

                JScrollPane treeScrollPane = new JScrollPane(explorer.treeViewer);
        treeScrollPane = new JScrollPane(treeViewer);
        treeScrollPane.setWheelScrollingEnabled(false);
        treeScrollPane.addMouseWheelListener(new MouseWheelListener() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                        explorer.treeViewer.onZoomChanged(-e.getWheelRotation());
                treeViewer.onZoomChanged(-e.getWheelRotation());
            }
        });

                String[] roundsArray = explorer.tree.rounds.toArray(new String[0]);
                explorer.roundsList = new JList<>(roundsArray);
                explorer.roundsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                explorer.roundsList.addListSelectionListener(explorer);

                JScrollPane roundScrollPane = new JScrollPane(explorer.roundsList);

                JPanel treePanel = new JPanel(new BorderLayout());
        treePanel = new JPanel(new BorderLayout());
        treePanel.add(treeScrollPane, BorderLayout.CENTER);

                JPanel sourceC = new JPanel(new BorderLayout());
                JPanel sourceLL = new JPanel(new BorderLayout());
        roundsList = new JList<>(new DefaultListModel<>());
        roundsList.addListSelectionListener(this);
        roundsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        roundScrollPane = new JScrollPane(roundsList);

                JTabbedPane mainTabbedPane = new JTabbedPane(JTabbedPane.TOP);
        mainTabbedPane = new JTabbedPane(JTabbedPane.TOP);
        mainTabbedPane.addTab("Tree", treePanel);
        mainTabbedPane.addTab("C", sourceC);
        mainTabbedPane.addTab("LL", sourceLL);

                JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
                tabbedPane.addTab("Context", explorer.contextViewer);
                tabbedPane.addTab("Constraints", explorer.constraintsViewer);
                tabbedPane.addTab("Memory", explorer.memoryViewer);
        leftTabbedPane = new JTabbedPane(JTabbedPane.TOP);
        leftTabbedPane.addTab("Context", contextViewer);
        leftTabbedPane.addTab("Constraints", constraintsViewer);
        leftTabbedPane.addTab("Memory", memoryViewer);
        leftTabbedPane.setVisible(false);

                tabbedPane.setVisible(false);
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainTabbedPane, leftTabbedPane);
        mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, roundScrollPane, splitPane);
        mainSplitPane.setDividerLocation(50);

                JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainTabbedPane, tabbedPane);

                JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, roundScrollPane, splitPane);
                mainSplitPane.setDividerLocation(100);

                explorer.rootPanel.add(mainSplitPane, BorderLayout.CENTER);
                explorer.treeViewer.addMouseListener(new MouseListener() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        Node node = explorer.treeViewer.onMouseClicked(e.getX(), e.getY());
                        if (tabbedPane.isVisible())
                            explorer.divider = splitPane.getDividerLocation();

                        if (node != null){
                            explorer.showNodeInformation(node);
                            tabbedPane.setVisible(true);
                            splitPane.setDividerLocation(explorer.divider);
                        } else{
                            tabbedPane.setVisible(false);
                        }
        rootPanel = new JPanel(new BorderLayout());
        rootPanel.add(mainSplitPane, BorderLayout.CENTER);
    }

                    @Override
                    public void mousePressed(MouseEvent e) {

    public void valueChanged(ListSelectionEvent e) {
        if (e.getSource() != roundsList) return;
        if (roundsList.getValueIsAdjusting()) return;
        if (roundsList.getSelectedIndex() < 0) return;
        treeViewer.selectedRound = roundsList.getSelectedIndex();
        treeViewer.updateArea();
    }

                    @Override
                    public void mouseReleased(MouseEvent e) {

    public void clear() {
        sourceMapping.clear();
        tree.clear();
        ((DefaultListModel<String>)roundsList.getModel()).clear();
        treeViewer.clear();
        sourceC.clear();
        sourceLL.clear();
    }

                    @Override
                    public void mouseEntered(MouseEvent e) {
    private void load(String dir) {
        try{
            tree.load(Paths.get(dir));
            sourceMapping.load(dir);
        } catch(Exception e){
            JOptionPane.showMessageDialog(rootPanel, "Load has FAILED: " + e);
            clear();
            rootPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            return;
        }
        treeViewer.load();
        sourceC.load();
        sourceLL.load();

        for (int i = 0; i < tree.rounds.size(); ++i)
            ((DefaultListModel<String>)roundsList.getModel()).addElement(tree.rounds.get(i));
    }

                    @Override
                    public void mouseExited(MouseEvent e) {
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("JetKlee: ProgressExplorer");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setPreferredSize(new Dimension(800, 600));

                    }
                });
                ProgressExplorer explorer = new ProgressExplorer();
                if (args.length != ARGS_COUNT)
                    throw new IllegalArgumentException("Invalid number of arguments. Expected " + ARGS_COUNT + " arguments.");

                explorer.load(args[0]);

                frame.setContentPane(explorer.rootPanel);
                frame.pack();
@@ -154,33 +135,31 @@ public class ProgressExplorer implements ListSelectionListener, MouseWheelListen
            }
        });
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        Node node = treeViewer.onMouseClicked(e.getX(), e.getY());
        if (leftTabbedPane.isVisible())
            divider = splitPane.getDividerLocation();

    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (node != null){
            contextViewer.showContext(node.executionState);
            constraintsViewer.showConstraints(node.executionState);
            memoryViewer.showMemory(node.executionState);

            leftTabbedPane.setVisible(true);
            splitPane.setDividerLocation(divider);
        } else{
            leftTabbedPane.setVisible(false);
        }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    public void mouseWheelMoved(MouseWheelEvent e) {}
    @Override
    public void mouseExited(MouseEvent e) {

    }
    public void mousePressed(MouseEvent e) {}
    @Override
    public void mouseReleased(MouseEvent e) {}
    @Override
    public void mouseEntered(MouseEvent e) {}
    @Override
    public void mouseExited(MouseEvent e) {}
}
+33 −0
Original line number Diff line number Diff line
package jetklee;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class SourceMapping {
    public List<String> sourceC;
    public List<String> sourceLL;

    public SourceMapping(){
    }
    private List<String> loadFile(File sourceFile) throws IOException {
        List<String> source = new ArrayList<>();
        if (sourceFile.isFile())
            source = Files.lines(Paths.get(sourceFile.getPath())).toList();
        else
            source.add("Cannot access source code file: " + sourceFile.getAbsolutePath());
        return source;
    }
    public void load(String dir) throws IOException {
        sourceC = loadFile(new File(dir + "/source.c"));
        sourceLL = loadFile(new File(dir + "/source.ll"));
    }

    public void clear() {
        sourceC = null;
        sourceLL = null;
    }
}
Loading