/* * Copyright 2009 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package Sequenic.T2ext.Instrumenter; import java.io.Serializable; import java.util.* ; import Sequenic.Graph.* ; /** * Represents a node in a CFG. It represents a "block", which roughly is a * maximal piece of the original byte-code without a jump or a jump-target. * * To be more precise, a block either begins at the target method's start, * or at a jump-target. It ends with either a "return", a "throw", a goto, * a branch instruction, a switch instruction, or if the next instruction * is a jump-target. * * A block may have up to two successors (children), which is the case if at * the block's end there is a branching instruction. Note that this * "two-successors" limit is sufficient for Java byte code. * * Note that some block may map to just a single instruction; this is * e.g. the case if the method starts immediately with a branch instruction, * or in a branches-cascade. * * For every block B we will also keep: * * (1) the line numbers where the block starts and ends. * * (2) pointers to "neighboring blocks"; these are blocks that end in the same * line number as B's starting line number. * * (3) branch-out category of the block: * * EXIT : node with no successors * BRANCH : block ends with a branch instruction (multiple successors) * SWITCH: block ends with a switch instruction (multiple successors) * ORDINARY: block has only 1 successor * * * Exception throwing and handling : pending. * * @author Wishnu Prasetya * @author Maaike Gerritsen */ public class Node extends Vertex implements Serializable{ private static final long serialVersionUID = 1L; static final String EXIT = "EXIT" ; static final String BRANCH = "BRANCH" ; static final String SWITCH = "SWITCH" ; static final String ORDINARY = "ORDINARY" ; /** * The kind of branch-out that this node has. */ String kind = ORDINARY ; /* * Set this to true if this node is an entry node in a CFG. The starting node * is an entry node; but in our model, so are the start of an exception * handler. * * Note: will be detected by by our graph algorithm as a node without * parent. */ //boolean isEntryNode = false ; int lineNr_start ; int lineNr_end ; /** * If not null this node has one out-going arrow which is a back-edge. * The value of this variable is then the id of the target node of * the back-edge. */ //Integer hasBackEdge = null ; List neighbors = new LinkedList() ; /** * List of constants loaded in this node. */ LinkedList constants = new LinkedList() ; public int getId() { return id; } public List getConstants() { return constants ; } /** * Return the int constants loaded in this node. */ Integer[] getIntConstants(){ List res = new LinkedList() ; for (Object x : constants) { if (x instanceof Integer) res.add((Integer) x) ; } return res.toArray(new Integer[0]) ; } /** * Return the string constants loaded in this node. */ String[] getStringConstants(){ List res = new LinkedList() ; for (Object x : constants) { if (x instanceof String) res.add("" + (String) x) ; } return res.toArray(new String[0]) ; } }