1 package org.kit.furia.fragment.asm;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.LinkedList;
7 import java.util.List;
8 import java.util.Set;
9
10 import org.kit.furia.fragment.soot.HugeFragmentException;
11 import org.kit.furia.misc.IntegerHolder;
12 import org.objectweb.asm.tree.analysis.BasicValue;
13 import org.objectweb.asm.tree.analysis.Value;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public abstract class AbstractFunction implements FValue{
39 protected List < Value > params;
40 protected Set < Value > paramSet;
41 private int size;
42 protected AbstractFunction(){
43 super();
44 params = new LinkedList<Value>();
45 paramSet = new HashSet<Value>();
46 size = 0;
47 }
48
49
50
51
52
53 public void addParam(Value param){
54 if(!paramSet.contains(param) && this != param){
55 params.add(param);
56 paramSet.add(param);
57 size+= param.getSize();
58 }
59 }
60
61 public int getSize(){
62 return size;
63 }
64
65
66
67
68
69 protected abstract String printFunctionName();
70
71
72
73
74
75
76 protected abstract boolean equalFunctions(Value x);
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 protected abstract int hashCodeFunctionName();
98
99
100
101
102
103
104
105
106 public void toFragment(StringBuilder result, Set visited, IntegerHolder count, int max) throws HugeFragmentException{
107 if(count.getValue()> max){
108 throw new HugeFragmentException();
109 }
110
111
112 if(visited.contains(this)){
113 result.append("s()");
114 count.inc();
115 return;
116 }else{
117 visited.add(this);
118 }
119 result.append(printFunctionName());
120 count.inc();
121 result.append("(");
122 Iterator<Value> it = params.iterator();
123 String comma = "";
124 while(it.hasNext()){
125 Value n = it.next();
126 result.append(comma);
127 if(n instanceof BasicValue){
128 BasicValue n2 = (BasicValue)n;
129 String j = n2.toString();
130 if(j.equals(".")){
131 j = "z";
132 }
133 result.append(j);
134 count.inc();
135 }else if (n instanceof FValue){
136 FValue n2 = (FValue)n;
137 n2.toFragment(result, visited, count, max);
138 }else{
139 throw new IllegalArgumentException("Not supported value");
140 }
141 comma = ",";
142 }
143
144 result.append(")");
145 }
146 }