OSDN Git Service

add preprocessor
[stigmata/stigmata-plugins.git] / wsp / src / main / java / jp / sourceforge / stigmata / birthmarks / wsp / Opcode.java
1 package jp.sourceforge.stigmata.birthmarks.wsp;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.Iterator;
11 import java.util.List;
12
13 import org.objectweb.asm.Label;
14
15 /**
16  * 
17  * @author Haruaki Tamada
18  * @version $Revision$
19  */
20 public class Opcode implements Serializable{
21     private static final long serialVersionUID = -2349834745416345564L;
22
23     public static enum Category{
24         NORMAL, BRANCH, OBJECT, INVOKE, TARGETER,
25     };
26     private int opcode;
27     private String name;
28     private int argumentCount;
29     private int act;
30     private int weight;
31     private Category category;
32     private List<Label> labels = new ArrayList<Label>();
33
34     public Opcode(Opcode opcode){
35         this(opcode.getOpcode(), opcode.getName(), opcode.getArgumentCount(), opcode.getAct(), opcode.getCategory());
36     }
37
38     public Opcode(int opcode, String name, int argumentCount, int act, String category){
39         this(opcode, name, argumentCount, act, Category.valueOf(category));
40     }
41
42     public Opcode(int opcode, String name, int argumentCount, int act, Category category){
43         this.opcode = opcode;
44         this.name = name;
45         this.argumentCount = argumentCount;
46         this.act = act;
47         this.category = category;
48     }
49
50     Opcode(int opcode, String name, int argumentCount, int act, Category category, int weight){
51         this(opcode, name, argumentCount, act, category);
52         setWeight(weight);
53     }
54
55     public int getOpcode(){
56         return opcode;
57     }
58
59     public String getName(){
60         return name;
61     }
62
63     public int getArgumentCount(){
64         return argumentCount;
65     }
66
67     public void addLabel(Label label){
68         if(category != Category.BRANCH){
69             throw new IllegalStateException("this method allows only branch category");
70         }
71         labels.add(label);
72     }
73
74     public void setLabels(Label[] labelArray){
75         if(category != Category.BRANCH){
76             throw new IllegalStateException("this method allows only branch category");
77         }
78         for(Label label: labelArray){
79             labels.add(label);
80         }
81     }
82
83     public Iterator<Label> labels(){
84         return Collections.unmodifiableList(labels).iterator();
85     }
86
87     public void setAct(int act){
88         if(category != Category.OBJECT && category != Category.INVOKE){
89             throw new IllegalStateException("setAct can be called only object and invoke category.");
90         }
91         this.act = act;
92     }
93
94     public int getAct(){
95         return act;
96     }
97
98     public Category getCategory(){
99         return category;
100     }
101
102     public void setWeight(int weight){
103         this.weight = weight;
104     }
105
106     public int getWeight(){
107         return weight;
108     }
109 }