KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > TIR > Impl > ExprUnOperationDefImpl


1 /* $Id: ExprUnOperationDefImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.io.IOException JavaDoc;
4 import java.rmi.RemoteException JavaDoc;
5 import java.rmi.server.UnicastRemoteObject JavaDoc;
6
7 import SOFA.SOFAnode.Made.TIR.Container;
8 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
9 import SOFA.SOFAnode.Made.TIR.ExprDouble;
10 import SOFA.SOFAnode.Made.TIR.ExprFixed;
11 import SOFA.SOFAnode.Made.TIR.ExprFloat;
12 import SOFA.SOFAnode.Made.TIR.ExprLong;
13 import SOFA.SOFAnode.Made.TIR.ExprLongLong;
14 import SOFA.SOFAnode.Made.TIR.ExprOctet;
15 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
16 import SOFA.SOFAnode.Made.TIR.ExprOperKind;
17 import SOFA.SOFAnode.Made.TIR.ExprShort;
18 import SOFA.SOFAnode.Made.TIR.ExprUnOperationDef;
19 import SOFA.SOFAnode.Made.TIR.ExprUnsigLong;
20 import SOFA.SOFAnode.Made.TIR.ExprUnsigLongLong;
21 import SOFA.SOFAnode.Made.TIR.ExprUnsigShort;
22 import SOFA.SOFAnode.Made.TIR.Repository;
23 import SOFA.SOFAnode.Made.TIR.StateKind;
24 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate;
25 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
26
27 public class ExprUnOperationDefImpl extends UnicastRemoteObject JavaDoc implements ExprUnOperationDef, TIRImplObject {
28   ExprOperKindImpl eok;
29   DefinitionKindImpl defKindImpl;
30   StateKindImpl stKindImpl;
31   ExprOperDef oper;
32
33   public ExprUnOperationDefImpl(int kind, ExprOperDef op) throws RemoteException JavaDoc {
34     eok = new ExprOperKindImpl(kind);
35     oper = op;
36     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
37     stKindImpl = new StateKindImpl(StateKind.sk_work);
38   }
39
40   public ExprUnOperationDefImpl(int kind) throws RemoteException JavaDoc {
41     eok = new ExprOperKindImpl(kind);
42     oper = null;
43     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
44     stKindImpl = new StateKindImpl(StateKind.sk_normal);
45   }
46
47   public ExprUnOperationDefImpl() throws RemoteException JavaDoc {
48     eok = null;
49     oper = null;
50     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
51     stKindImpl = new StateKindImpl(StateKind.sk_normal);
52   }
53
54   /* from interface TIRObject */
55   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
56     return (DefinitionKind) defKindImpl;
57   }
58
59   /* from interface TIRObject */
60   public StateKind get_state() throws RemoteException JavaDoc {
61     return (StateKind) stKindImpl;
62   }
63
64   public ExprOperDef operand() throws RemoteException JavaDoc {
65     return oper;
66   }
67   
68   public ExprOperKind get_eok_kind() throws RemoteException JavaDoc {
69     return (ExprOperKind) eok;
70   }
71   
72   public ExprOperDef calculate() throws RemoteException JavaDoc, TIRExceptCalculate {
73     ExprOperDef a = oper.calculate();
74     ExprOperDef ret = null;
75     switch (a.get_eok_kind().value()) {
76       case ExprOperKind.eok_short:
77     if (eok.value()==ExprOperKind.eok_unminus) {
78       ret = new ExprShortImpl((short)-((ExprShort)a).value());
79     } else {
80           if (eok.value()==ExprOperKind.eok_unplus) {
81         ret = new ExprShortImpl(((ExprShort)a).value());
82       } else {
83             if (eok.value()==ExprOperKind.eok_untilde) {
84           ret = new ExprShortImpl((short)~((ExprShort)a).value());
85         } else {
86               throw new TIRExceptCalculate("Can't calculate.");
87             }
88       }
89     }
90     break;
91       case ExprOperKind.eok_long:
92     if (eok.value()==ExprOperKind.eok_unminus) {
93       ret = new ExprLongImpl(-((ExprLong)a).value());
94     } else {
95           if (eok.value()==ExprOperKind.eok_unplus) {
96         ret = new ExprLongImpl(((ExprLong)a).value());
97       } else {
98             if (eok.value()==ExprOperKind.eok_untilde) {
99               ret = new ExprLongImpl(~((ExprLong)a).value());
100         } else {
101               throw new TIRExceptCalculate("Can't calculate.");
102             }
103       }
104     }
105     break;
106       case ExprOperKind.eok_longlong:
107     if (eok.value()==ExprOperKind.eok_unminus) {
108       ret = new ExprLongLongImpl(-((ExprLongLong)a).value());
109     } else {
110           if (eok.value()==ExprOperKind.eok_unplus) {
111         ret = new ExprLongLongImpl(((ExprLongLong)a).value());
112       } else {
113             if (eok.value()==ExprOperKind.eok_untilde) {
114               ret = new ExprLongLongImpl(~((ExprLongLong)a).value());
115         } else {
116               throw new TIRExceptCalculate("Can't calculate.");
117             }
118       }
119     }
120     break;
121       case ExprOperKind.eok_unsigshort:
122     if (eok.value()==ExprOperKind.eok_unminus) {
123       ret = new ExprUnsigShortImpl((short)-((ExprUnsigShort)a).value());
124     } else {
125           if (eok.value()==ExprOperKind.eok_unplus) {
126         ret = new ExprUnsigShortImpl(((ExprUnsigShort)a).value());
127       } else {
128             if (eok.value()==ExprOperKind.eok_untilde) {
129               ret = new ExprUnsigShortImpl((short)~((ExprUnsigShort)a).value());
130         } else {
131               throw new TIRExceptCalculate("Can't calculate.");
132             }
133       }
134     }
135     break;
136       case ExprOperKind.eok_unsiglong:
137     if (eok.value()==ExprOperKind.eok_unminus) {
138       ret = new ExprUnsigLongImpl(-((ExprUnsigLong)a).value());
139     } else {
140           if (eok.value()==ExprOperKind.eok_unplus) {
141         ret = new ExprUnsigLongImpl(((ExprUnsigLong)a).value());
142       } else {
143             if (eok.value()==ExprOperKind.eok_untilde) {
144               ret = new ExprUnsigLongImpl(~((ExprUnsigLong)a).value());
145         } else {
146               throw new TIRExceptCalculate("Can't calculate.");
147             }
148       }
149     }
150     break;
151       case ExprOperKind.eok_unsiglonglong:
152     if (eok.value()==ExprOperKind.eok_unminus) {
153       ret = new ExprUnsigLongLongImpl(-((ExprUnsigLongLong)a).value());
154     } else {
155           if (eok.value()==ExprOperKind.eok_unplus) {
156         ret = new ExprUnsigLongLongImpl(((ExprUnsigLongLong)a).value());
157       } else {
158             if (eok.value()==ExprOperKind.eok_untilde) {
159               ret = new ExprUnsigLongLongImpl(~((ExprUnsigLongLong)a).value());
160         } else {
161               throw new TIRExceptCalculate("Can't calculate.");
162             }
163       }
164     }
165     break;
166       case ExprOperKind.eok_octet:
167     if (eok.value()==ExprOperKind.eok_unminus) {
168       ret = new ExprOctetImpl((byte)-((ExprOctet)a).value());
169     } else {
170           if (eok.value()==ExprOperKind.eok_unplus) {
171         ret = new ExprOctetImpl(((ExprOctet)a).value());
172       } else {
173             if (eok.value()==ExprOperKind.eok_untilde) {
174               ret = new ExprOctetImpl((byte)~((ExprOctet)a).value());
175         } else {
176               throw new TIRExceptCalculate("Can't calculate.");
177             }
178       }
179     }
180     break;
181       case ExprOperKind.eok_float:
182     if (eok.value()==ExprOperKind.eok_unminus) {
183       ret = new ExprFloatImpl(-((ExprFloat)a).value());
184     } else {
185           if (eok.value()==ExprOperKind.eok_unplus) {
186         ret = new ExprFloatImpl(((ExprFloat)a).value());
187       } else {
188             throw new TIRExceptCalculate("Can't calculate.");
189       }
190     }
191     break;
192       case ExprOperKind.eok_double:
193     if (eok.value()==ExprOperKind.eok_unminus) {
194       ret = new ExprDoubleImpl(-((ExprDouble)a).value());
195     } else {
196           if (eok.value()==ExprOperKind.eok_unplus) {
197         ret = new ExprDoubleImpl(((ExprDouble)a).value());
198       } else {
199             throw new TIRExceptCalculate("Can't calculate.");
200       }
201     }
202     break;
203       case ExprOperKind.eok_fixed:
204     if (eok.value()==ExprOperKind.eok_unminus) {
205       ret = new ExprFixedImpl(((ExprFixed)a).value().negate(),((ExprFixed)a).digits(),((ExprFixed)a).scale());
206     } else {
207           if (eok.value()==ExprOperKind.eok_unplus) {
208         ret = new ExprFixedImpl(((ExprFixed)a).value(),((ExprFixed)a).digits(),((ExprFixed)a).scale());
209       } else {
210             throw new TIRExceptCalculate("Can't calculate.");
211       }
212     }
213     break;
214       default: throw new TIRExceptCalculate("Can't calculate.");
215     }
216     return ret;
217   }
218
219   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
220     try {
221       st.curOutFile.writeInt(eok.value());
222       ((TIRImplObject)oper).save(st);
223     } catch (IOException JavaDoc e) {
224       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
225     }
226   }
227   
228   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
229     oper = Storage.readExprOperDef(st);
230   }
231
232   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
233     ((TIRImplObject) oper).postLoad(r);
234   }
235
236   public boolean isNew() {
237     return (stKindImpl.value()==StateKind.sk_work);
238   }
239
240   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
241
242   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
243     if (stKindImpl.value()==StateKind.sk_work) {
244       stKindImpl.toNormal();
245       ((TIRImplObject)oper).doCommit(in,rep);
246     }
247   }
248
249   public void doAbort(long workId) throws RemoteException JavaDoc {}
250 }
251
Popular Tags