1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.io.IOException ; 5 6 import SOFA.SOFAnode.Made.TIR.PrimitiveKind; 7 8 12 public class PrimitiveGeneratedObject extends GeneratedObject { 13 String inRef; 14 String outRef; 15 String defVal; 16 String readVal; 17 String writeVal; 18 19 int primKind; 20 21 25 public PrimitiveGeneratedObject(int primKind) { 26 this.primKind = primKind; 27 switch (primKind) { 28 case PrimitiveKind.pk_void: 29 inRef = "void"; 30 outRef = ""; 31 key = "void"; 32 defVal = ""; 33 readVal = ""; 34 writeVal = ""; 35 break; 36 case PrimitiveKind.pk_ushort: 37 inRef = "short"; 38 outRef = stdPackage+"ShortHolder"; 39 key = "ushort"; 40 defVal = "(short) 0"; 41 readVal = " = "+defaultIstream+".read_ushort()"; 42 writeVal = defaultOstream+".write_ushort("; 43 break; 44 case PrimitiveKind.pk_short: 45 inRef = "short"; 46 outRef = stdPackage+"ShortHolder"; 47 key = "short"; 48 defVal = "(short) 0"; 49 readVal = " = "+defaultIstream+".read_short()"; 50 writeVal = defaultOstream+".write_short("; 51 break; 52 case PrimitiveKind.pk_ulong: 53 inRef = "int"; 54 outRef = stdPackage+"IntHolder"; 55 key = "ulong"; 56 defVal = "(int) 0"; 57 readVal = " = "+defaultIstream+".read_ulong()"; 58 writeVal = defaultOstream+".write_ulong("; 59 break; 60 case PrimitiveKind.pk_long: 61 inRef = "int"; 62 outRef = stdPackage+"IntHolder"; 63 key = "long"; 64 defVal = "(int) 0"; 65 readVal = " = "+defaultIstream+".read_long()"; 66 writeVal = defaultOstream+".write_long("; 67 break; 68 case PrimitiveKind.pk_ulonglong: 69 inRef = "long"; 70 outRef = stdPackage+"LongHolder"; 71 key = "ulonglong"; 72 defVal = "(long) 0"; 73 readVal = " = "+defaultIstream+".read_ulonglong()"; 74 writeVal = defaultOstream+".write_ulonglong("; 75 break; 76 case PrimitiveKind.pk_longlong: 77 inRef = "long"; 78 outRef = stdPackage+"LongHolder"; 79 key = "longlong"; 80 defVal = "(long) 0"; 81 readVal = " = "+defaultIstream+".read_longlong()"; 82 writeVal = defaultOstream+".write_longlong("; 83 break; 84 case PrimitiveKind.pk_float: 85 inRef = "float"; 86 outRef = stdPackage+"FloatHolder"; 87 key = "float"; 88 defVal = "(float) 0"; 89 readVal = " = "+defaultIstream+".read_float()"; 90 writeVal = defaultOstream+".write_float("; 91 break; 92 case PrimitiveKind.pk_double: 93 inRef = "double"; 94 outRef = stdPackage+"DoubleHolder"; 95 key = "double"; 96 defVal = "(double) 0"; 97 readVal = " = "+defaultIstream+".read_double()"; 98 writeVal = defaultOstream+".write_double("; 99 break; 100 case PrimitiveKind.pk_longdouble: 101 key = "longdouble"; 102 inRef = "??? no mapping ???"; 103 outRef = "??? no mapping ???"; 104 break; case PrimitiveKind.pk_boolean: 106 inRef = "boolean"; 107 outRef = stdPackage+"BooleanHolder"; 108 key = "boolean"; 109 defVal = "false"; 110 readVal = " = "+defaultIstream+".read_boolean()"; 111 writeVal = defaultOstream+".write_boolean("; 112 break; 113 case PrimitiveKind.pk_wchar: 114 inRef = "char"; 115 outRef = stdPackage+"CharHolder"; 116 key = "wchar"; 117 defVal = "(char) 0"; 118 readVal = " = "+defaultIstream+".read_wchar()"; 119 writeVal = defaultOstream+".write_wchar("; 120 break; 121 case PrimitiveKind.pk_char: 122 inRef = "char"; 123 outRef = stdPackage+"CharHolder"; 124 key = "char"; 125 defVal = "(char) 0"; 126 readVal = " = "+defaultIstream+".read_char()"; 127 writeVal = defaultOstream+".write_char("; 128 break; 129 case PrimitiveKind.pk_octet: 130 inRef = "byte"; 131 outRef = stdPackage+"ByteHolder"; 132 key = "octet"; 133 defVal = "(byte) 0"; 134 readVal = " = "+defaultIstream+".read_octet()"; 135 writeVal = defaultOstream+".write_octet("; 136 break; 137 case PrimitiveKind.pk_wstring: 138 inRef = "java.lang.String"; 139 outRef = stdPackage+"StringHolder"; 140 key = "wstring"; 141 defVal = "null"; 142 readVal = " = "+defaultIstream+".read_wstring()"; 143 writeVal = defaultOstream+".write_wstring("; 144 break; 145 case PrimitiveKind.pk_string: 146 inRef = "java.lang.String"; 147 outRef = stdPackage+"StringHolder"; 148 key = "string"; 149 defVal = "null"; 150 readVal = " = "+defaultIstream+".read_string()"; 151 writeVal = defaultOstream+".write_string("; 152 break; 153 case PrimitiveKind.pk_any: 154 inRef = stdPackage+"Any"; 155 outRef = stdPackage+"AnyHolder"; 156 key = "any"; 157 defVal = "null"; 158 readVal = " = "+defaultIstream+".read_any()"; 159 writeVal = defaultOstream+".write_any("; 160 return; 161 case PrimitiveKind.pk_object: 162 inRef = stdPackage+"Object"; 163 outRef = stdPackage+"ObjectHolder"; 164 key = "object"; 165 defVal = "null"; 166 readVal = " = "+defaultIstream+".read_Object()"; 167 writeVal = defaultOstream+".write_Object("; 168 return; 169 } 170 } 171 172 public String genReference(int kind) { 174 switch (kind) { 175 case INREF: return inRef; 176 case OUTREF: return outRef; 177 default: return null; 178 } 179 } 180 181 public void genReference(CGFileWriter out, int kind) throws IOException { 183 switch (kind) { 184 case INREF: out.iwrite(inRef); break; 185 case OUTREF: out.iwrite(outRef); break; 186 default: ; 187 } 188 } 189 190 193 public static void createPrimGenerObjects(GenObjectList list) { 194 try { 195 for (int i=0; i<18; i++) { 196 list.addObject(new PrimitiveGeneratedObject(i)); 197 } 198 } catch (GenObjectList.ExistException e) { 199 Output.out.println("!!!!"); 200 } 201 } 202 203 public void defaultValue(CGFileWriter out) throws IOException { 204 out.iwriteln(defVal); 205 } 206 207 public String defaultValue() throws IOException { 208 return defVal; 209 } 210 211 public void genReadType(CGFileWriter out, String varName) throws IOException { 212 out.iwrite(varName+readVal); 213 } 214 215 public String genReadType(String varName) throws IOException { 216 return varName+readVal; 217 } 218 219 public void genWriteType(CGFileWriter out, String varName) throws IOException { 220 out.iwrite(writeVal + varName + ")"); 221 } 222 223 public String genWriteType(String varName) throws IOException { 224 return writeVal + varName + ")"; 225 } 226 227 public String toString() { 228 return inRef; 229 } 230 } 231 | Popular Tags |