View Javadoc

1   package org.kit.furia.fragment.asm;
2   
3   import org.objectweb.asm.tree.AbstractInsnNode;
4   import org.objectweb.asm.tree.analysis.Value;
5   
6   /*
7    Furia-chan: An Open Source software license violation detector.    
8    Copyright (C) 2008 Kyushu Institute of Technology
9   
10   This program is free software: you can redistribute it and/or modify
11   it under the terms of the GNU General Public License as published by
12   the Free Software Foundation, either version 3 of the License, or
13   (at your option) any later version.
14  
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19  
20   You should have received a copy of the GNU General Public License
21   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22   */
23  
24  /**
25   * FunctionValue is
26   * @author Arnoldo Jose Muller Molina
27   */
28  
29  public class FunctionValue extends AbstractFunction {
30  
31      private AbstractInsnNode insn;
32      
33      private static String[] functionNameCache = new String[10000];
34  
35      public FunctionValue(AbstractInsnNode insn) {
36          super();
37          this.insn = insn;
38      }
39      
40      protected boolean equalFunctions(Value x){
41          if(x == this){
42              return true;
43          }else if(x instanceof  FunctionValue){
44              FunctionValue comp = (FunctionValue)x;
45              return insn.getOpcode() == comp.insn.getOpcode();
46          }else{
47              return false;
48          }
49      }
50      
51      /**
52       * Generate the hash code for the function name.
53       */
54      protected int  hashCodeFunctionName(){
55          return insn.getOpcode();
56      }
57  
58      protected  String printFunctionName(){
59          
60          if(functionNameCache[insn.getOpcode()] == null){
61              String fName = (new Integer(insn.getOpcode())).toString()
62              .replace("1", "a")
63              .replace("2", "b")
64              .replace("3", "c")
65              .replace("4", "d")
66              .replace("5", "e")
67              .replace("6", "f")
68              .replace("7", "g")
69              .replace("8", "h")
70              .replace("9", "i")
71              .replace("0", "j")
72              ; 
73              functionNameCache[insn.getOpcode()]  = fName;
74          }
75          
76         
77          return functionNameCache[insn.getOpcode()];
78      }
79  }