001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.dfsolver;
014    
015    import java.util.ArrayList;
016    
017    import org.jikesrvm.compilers.opt.OptimizingCompilerException;
018    import org.jikesrvm.compilers.opt.util.Graph;
019    import org.jikesrvm.compilers.opt.util.GraphNode;
020    import org.jikesrvm.compilers.opt.util.GraphNodeEnumeration;
021    
022    /**
023     * Implementation of a graph used in the guts of the dataflow equation
024     * solver.
025     */
026    class DF_Graph implements Graph {
027    
028      /**
029       * The nodes of the graph.
030       */
031      public final ArrayList<GraphNode> nodes = new ArrayList<GraphNode>();
032    
033      /**
034       * Number of nodes in the graph.
035       */
036      private int count = 0;
037    
038      /**
039       * @return number of nodes in the graph
040       */
041      public int numberOfNodes() {
042        return count;
043      }
044    
045      /**
046       * Implementation for Graph Interface.  TODO: why is this in the
047       * Graph interface?
048       */
049      public void compactNodeNumbering() {}
050    
051      /**
052       * Enumerate the nodes in the graph.
053       * @return an enumeration of the nodes in the graph
054       */
055      public GraphNodeEnumeration enumerateNodes() {
056        return new GraphNodeEnumeration() {
057          private int i = 0;
058    
059          public boolean hasMoreElements() {
060            return i < count;
061          }
062    
063          public GraphNode next() {
064            return nodes.get(i++);
065          }
066    
067          public GraphNode nextElement() {
068            return next();
069          }
070        };
071      }
072    
073      /**
074       * Add a node to the graph.
075       * @param x the node to add
076       */
077      public void addGraphNode(GraphNode x) {
078        x.setIndex(count);
079        nodes.add(x);
080        count++;
081      }
082    
083      /**
084       * Unsupported.  Why is this here?
085       */
086      public void addGraphEdge(GraphNode x, GraphNode y) {
087        throw new OptimizingCompilerException("DF_Graph edges implicit");
088      }
089    }