switch to spaces only..
[IRC.git] / Robust / src / IR / Flat / FlatCall.java
1 package IR.Flat;
2 import IR.MethodDescriptor;
3
4 public class FlatCall extends FlatNode {
5   TempDescriptor args[];
6   TempDescriptor this_temp;
7   TempDescriptor dst;
8   MethodDescriptor method;
9   boolean isSuper;
10
11   public FlatCall(MethodDescriptor md, TempDescriptor dst, TempDescriptor this_temp, TempDescriptor[] args) {
12     this(md, dst, this_temp, args, false);
13   }
14
15   public FlatCall(MethodDescriptor md, TempDescriptor dst, TempDescriptor this_temp, TempDescriptor[] args, boolean isSuper) {
16     this.method=md;
17     this.dst=dst;
18     this.this_temp=this_temp;
19     this.args=args;
20     this.isSuper=isSuper;
21   }
22   public void rewriteUse(TempMap t) {
23     for(int i=0; i<args.length; i++)
24       args[i]=t.tempMap(args[i]);
25     this_temp=t.tempMap(this_temp);
26   }
27   public void rewriteDef(TempMap t) {
28     dst=t.tempMap(dst);
29   }
30   public FlatNode clone(TempMap t) {
31     TempDescriptor ndst=t.tempMap(dst);
32     TempDescriptor nthis=t.tempMap(this_temp);
33     TempDescriptor[] nargs=new TempDescriptor[args.length];
34     for(int i=0; i<nargs.length; i++)
35       nargs[i]=t.tempMap(args[i]);
36
37     return new FlatCall(method, ndst, nthis, nargs);
38   }
39   public boolean getSuper() {
40     return isSuper;
41   }
42
43   public MethodDescriptor getMethod() {
44     return method;
45   }
46
47   public TempDescriptor getThis() {
48     return this_temp;
49   }
50
51   public TempDescriptor getReturnTemp() {
52     return dst;
53   }
54
55   public int numArgs() {
56     return args.length;
57   }
58
59   public TempDescriptor getArg(int i) {
60     return args[i];
61   }
62
63   public TempDescriptor getArgMatchingParamIndex(FlatMethod fm, int i) {
64     // in non-static methods the "this" pointer
65     // affects the matching index
66     if( method.isStatic() ) {
67       assert numArgs()   == fm.numParameters();
68     } else {
69       assert numArgs()+1 == fm.numParameters();
70     }
71
72     if( method.isStatic() ) {
73       return args[i];
74     }
75
76     if( i == 0 ) {
77       return this_temp;
78     }
79
80     return args[i-1];
81   }
82
83   // return the temp for the argument in caller that
84   // becomes the given parameter
85   public TempDescriptor getArgMatchingParam(FlatMethod fm,
86                                             TempDescriptor tdParam) {
87     // in non-static methods the "this" pointer
88     // affects the matching index
89     if( method.isStatic() ) {
90       assert numArgs()   == fm.numParameters();
91     } else {
92       assert numArgs()+1 == fm.numParameters();
93     }
94
95     for( int i = 0; i < fm.numParameters(); ++i ) {
96       TempDescriptor tdParamI = fm.getParameter(i);
97
98       if( tdParamI.equals(tdParam) ) {
99
100         if( method.isStatic() ) {
101           return args[i];
102         }
103
104         if( i == 0 ) {
105           return this_temp;
106         }
107
108         return args[i-1];
109       }
110     }
111
112     return null;
113   }
114
115   public String toString() {
116     String st="FlatCall_";
117     if (dst==null) {
118       if (method==null)
119         st+="null(";
120       else
121         st+=method.getSymbol()+"(";
122     } else
123       st+=dst+"="+method.getSymbol()+"(";
124     if (this_temp!=null) {
125       st+=this_temp;
126       if (args.length!=0)
127         st+=", ";
128     }
129
130     for(int i=0; i<args.length; i++) {
131       st+=args[i].toString();
132       if ((i+1)<args.length)
133         st+=", ";
134     }
135     return st+")";
136   }
137
138   public int kind() {
139     return FKind.FlatCall;
140   }
141
142   public TempDescriptor [] readsTemps() {
143     int size=args.length;
144     if (this_temp!=null)
145       size++;
146     TempDescriptor [] t=new TempDescriptor[size];
147     int offset=0;
148     if (this_temp!=null)
149       t[offset++]=this_temp;
150     for(int i=0; i<args.length; i++)
151       t[offset++]=args[i];
152     return t;
153   }
154
155   public TempDescriptor [] writesTemps() {
156     if (dst!=null)
157       return new TempDescriptor[] {dst};
158     else
159       return new TempDescriptor[0];
160   }
161 }