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 */
013package org.jikesrvm.compilers.opt.dfsolver;
014
015import java.util.ArrayList;
016import java.util.Enumeration;
017
018import org.jikesrvm.compilers.opt.OptimizingCompilerException;
019import org.jikesrvm.compilers.opt.util.Graph;
020import org.jikesrvm.compilers.opt.util.GraphNode;
021
022/**
023 * Implementation of a graph used in the guts of the dataflow equation
024 * solver.
025 */
026class 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  @Override
039  public int numberOfNodes() {
040    return count;
041  }
042
043  /**
044   * Implementation for Graph Interface.  TODO: why is this in the
045   * Graph interface?
046   */
047  @Override
048  public void compactNodeNumbering() {}
049
050  /**
051   * Enumerate the nodes in the graph.
052   * @return an enumeration of the nodes in the graph
053   */
054  @Override
055  public Enumeration<GraphNode> enumerateNodes() {
056    return new Enumeration<GraphNode>() {
057      private int i = 0;
058
059      @Override
060      public boolean hasMoreElements() {
061        return i < count;
062      }
063
064      @Override
065      public GraphNode nextElement() {
066        return nodes.get(i++);
067      }
068    };
069  }
070
071  /**
072   * @param x the node to add
073   */
074  @Override
075  public void addGraphNode(GraphNode x) {
076    x.setIndex(count);
077    nodes.add(x);
078    count++;
079  }
080
081  /**
082   * Unsupported.  Why is this here?
083   */
084  @Override
085  public void addGraphEdge(GraphNode x, GraphNode y) {
086    throw new OptimizingCompilerException("DF_Graph edges implicit");
087  }
088}