KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ExprBinOperationDefImpl.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.ExprBinOperationDef;
10 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
11 import SOFA.SOFAnode.Made.TIR.ExprOperKind;
12 import SOFA.SOFAnode.Made.TIR.Repository;
13 import SOFA.SOFAnode.Made.TIR.StateKind;
14 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate;
15 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
16
17 public class ExprBinOperationDefImpl extends UnicastRemoteObject JavaDoc implements ExprBinOperationDef, TIRImplObject {
18   ExprOperKindImpl eok;
19   DefinitionKindImpl defKindImpl;
20   StateKindImpl stKindImpl;
21   ExprOperDef oper1;
22   ExprOperDef oper2;
23
24   public ExprBinOperationDefImpl(int kind) throws RemoteException JavaDoc {
25     eok = new ExprOperKindImpl(kind);
26     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
27     stKindImpl = new StateKindImpl(StateKind.sk_normal);
28     oper1 = null;
29     oper2 = null;
30   }
31
32   public ExprBinOperationDefImpl(int kind, ExprOperDef op1, ExprOperDef op2) throws RemoteException JavaDoc {
33     eok = new ExprOperKindImpl(kind);
34     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
35     stKindImpl = new StateKindImpl(StateKind.sk_work);
36     oper1 = op1;
37     oper2 = op2;
38   }
39
40   public ExprBinOperationDefImpl() throws RemoteException JavaDoc {
41     eok = null;
42     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression);
43     stKindImpl = new StateKindImpl(StateKind.sk_normal);
44     oper1 = null;
45     oper2 = null;
46   }
47
48   /* from interface TIRObject */
49   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
50     return (DefinitionKind) defKindImpl;
51   }
52
53   /* from interface TIRObject */
54   public StateKind get_state() throws RemoteException JavaDoc {
55     return (StateKind) stKindImpl;
56   }
57
58   public ExprOperDef operand1() throws RemoteException JavaDoc {
59     return oper1;
60   }
61   
62   public ExprOperDef operand2() throws RemoteException JavaDoc {
63     return oper2;
64   }
65
66   public ExprOperKind get_eok_kind() throws RemoteException JavaDoc {
67     return (ExprOperKind) eok;
68   }
69
70   public ExprOperDef calculate() throws RemoteException JavaDoc, TIRExceptCalculate {
71     ExprOperDef ret = null;
72     ExprOperDef a = oper1.calculate();
73     ExprOperDef b = oper2.calculate();
74     switch (eok.value()) {
75     case ExprOperKind.eok_plus:
76       ret = ExprHelp.plus(a,b);
77       break;
78     case ExprOperKind.eok_minus:
79       ret = ExprHelp.minus(a,b);
80       break;
81     case ExprOperKind.eok_mul:
82       ret = ExprHelp.mul(a,b);
83       break;
84     case ExprOperKind.eok_div:
85       ret = ExprHelp.div(a,b);
86       break;
87     case ExprOperKind.eok_mod:
88       ret = ExprHelp.mod(a,b);
89       break;
90     case ExprOperKind.eok_or:
91       ret = ExprHelp.or(a,b);
92       break;
93     case ExprOperKind.eok_xor:
94       ret = ExprHelp.xor(a,b);
95       break;
96     case ExprOperKind.eok_and:
97       ret = ExprHelp.and(a,b);
98       break;
99     case ExprOperKind.eok_shr:
100       ret = ExprHelp.shr(a,b);
101       break;
102     case ExprOperKind.eok_shl:
103       ret = ExprHelp.shl(a,b);
104       break;
105     default: throw new TIRExceptCalculate("Can't calculate.");
106     }
107
108     return ret;
109   }
110
111   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
112     try {
113       st.curOutFile.writeInt(eok.value());
114       ((TIRImplObject)oper1).save(st);
115       ((TIRImplObject)oper2).save(st);
116     } catch (IOException JavaDoc e) {
117       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
118     }
119   }
120   
121   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
122     oper1 = Storage.readExprOperDef(st);
123     oper2 = Storage.readExprOperDef(st);
124   }
125
126   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
127     ((TIRImplObject) oper1).postLoad(r);
128     ((TIRImplObject) oper2).postLoad(r);
129   }
130
131   public boolean isNew() {
132     return (stKindImpl.value()==StateKind.sk_work);
133   }
134
135   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
136
137   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
138     if (stKindImpl.value()==StateKind.sk_work) {
139       stKindImpl.toNormal();
140       ((TIRImplObject)oper1).doCommit(in,rep);
141       ((TIRImplObject)oper2).doCommit(in,rep);
142     }
143   }
144
145   public void doAbort(long workId) throws RemoteException JavaDoc {}
146 }
147
Popular Tags