1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import SOFA.SOFAnode.Made.TIR.ArrayDef; 5 import SOFA.SOFAnode.Made.TIR.CDLRepository; 6 import SOFA.SOFAnode.Made.TIR.CDLType; 7 import SOFA.SOFAnode.Made.TIR.Contained; 8 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 9 import SOFA.SOFAnode.Made.TIR.Identification; 10 import SOFA.SOFAnode.Made.TIR.ModuleDef; 11 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 12 import SOFA.SOFAnode.Made.TIR.PrimitiveKind; 13 import SOFA.SOFAnode.Made.TIR.SequenceDef; 14 import SOFA.SOFAnode.Made.TIR.TypedefDef; 15 16 17 21 public class JavaMapping implements Mapping { 22 23 24 28 public String getImplTypeName(CDLType type) { 29 try { 30 if (type instanceof PrimitiveDef) { 31 int primKind = ((PrimitiveDef) type).kind().value(); 32 switch (primKind) { 33 case PrimitiveKind.pk_void: 34 return "void"; 35 case PrimitiveKind.pk_ushort: 36 return "short"; 37 case PrimitiveKind.pk_short: 38 return "short"; 39 case PrimitiveKind.pk_ulong: 40 return "int"; 41 case PrimitiveKind.pk_long: 42 return "int"; 43 case PrimitiveKind.pk_ulonglong: 44 return "long"; 45 case PrimitiveKind.pk_longlong: 46 return "long"; 47 case PrimitiveKind.pk_float: 48 return "float"; 49 case PrimitiveKind.pk_double: 50 return "double"; 51 case PrimitiveKind.pk_longdouble: 52 return null; 53 case PrimitiveKind.pk_boolean: 54 return "boolean"; 55 case PrimitiveKind.pk_wchar: 56 return "char"; 57 case PrimitiveKind.pk_char: 58 return "char"; 59 case PrimitiveKind.pk_octet: 60 return "byte"; 61 case PrimitiveKind.pk_wstring: 62 return "java.lang.String"; 63 case PrimitiveKind.pk_string: 64 return "java.lang.String"; 65 case PrimitiveKind.pk_any: 66 return GeneratedObject.stdPackage+"Any"; 67 case PrimitiveKind.pk_object: 68 return GeneratedObject.stdPackage+"Object"; 69 } 70 } else { 71 if (type instanceof TypedefDef) { 72 int arr = 0; 73 boolean ok = false; 74 CDLType lastType = ((TypedefDef) type).original_type(); 75 while (!ok) { 76 int dk = lastType.get_def_kind().value(); 77 switch (dk) { 78 case DefinitionKind.dk_Array: 79 arr++; 80 lastType = ((ArrayDef) lastType).element_type(); 81 break; 82 case DefinitionKind.dk_Sequence: 83 arr++; 84 lastType = ((SequenceDef) lastType).element_type(); 85 break; 86 default: 87 ok = true; 88 break; 89 } 90 } 91 if (arr == 0) { 92 return getImplTypeName(lastType); 93 } else { 94 StringBuffer sb = new StringBuffer ( getImplTypeName(lastType)); 95 sb.append(JavaGenerator.genBrackets(arr)); 96 return sb.toString(); 97 } 98 } else { 99 StringBuffer sb = new StringBuffer (); 100 Contained cnt = (Contained) type; 101 while (! (cnt instanceof CDLRepository)) { 102 Identification id = cnt.get_identification(); 103 String version = id.version(); 104 String name = id.name(); 105 if (GeneratedObject.isReservedName(name)) 106 name = "_"+name; 107 if (sb.length() == 0) { 108 sb.append(name); 109 } else { 110 sb.insert(0,"."); 111 if (cnt instanceof ModuleDef) 112 sb.insert(0,name); 113 else 114 sb.insert(0,name+"Package"); 115 } 116 cnt = (Contained) cnt.get_defined_in(); 117 } 118 return sb.toString(); 119 } 120 } 121 } catch (java.rmi.RemoteException e) { 122 return null; 123 } 124 return null; 125 } 126 127 128 132 public String getImplTypeHolderName(CDLType type) { 133 try { 134 if (type instanceof PrimitiveDef) { 135 int primKind = ((PrimitiveDef) type).kind().value(); 136 switch (primKind) { 137 case PrimitiveKind.pk_void: 138 return "null"; 139 case PrimitiveKind.pk_ushort: 140 return GeneratedObject.stdPackage+"ShortHolder"; 141 case PrimitiveKind.pk_short: 142 return GeneratedObject.stdPackage+"ShortHolder"; 143 case PrimitiveKind.pk_ulong: 144 return GeneratedObject.stdPackage+"IntHolder"; 145 case PrimitiveKind.pk_long: 146 return GeneratedObject.stdPackage+"IntHolder"; 147 case PrimitiveKind.pk_ulonglong: 148 return GeneratedObject.stdPackage+"LongHolder"; 149 case PrimitiveKind.pk_longlong: 150 return GeneratedObject.stdPackage+"LongHolder"; 151 case PrimitiveKind.pk_float: 152 return GeneratedObject.stdPackage+"FloatHolder"; 153 case PrimitiveKind.pk_double: 154 return GeneratedObject.stdPackage+"DoubleHolder"; 155 case PrimitiveKind.pk_longdouble: 156 return null; 157 case PrimitiveKind.pk_boolean: 158 return GeneratedObject.stdPackage+"BooleanHolder"; 159 case PrimitiveKind.pk_wchar: 160 return GeneratedObject.stdPackage+"CharHolder"; 161 case PrimitiveKind.pk_char: 162 return GeneratedObject.stdPackage+"CharHolder"; 163 case PrimitiveKind.pk_octet: 164 return GeneratedObject.stdPackage+"ByteHolder"; 165 case PrimitiveKind.pk_wstring: 166 return GeneratedObject.stdPackage+"StringHolder"; 167 case PrimitiveKind.pk_string: 168 return GeneratedObject.stdPackage+"StringHolder"; 169 case PrimitiveKind.pk_any: 170 return GeneratedObject.stdPackage+"AnyHolder"; 171 case PrimitiveKind.pk_object: 172 return GeneratedObject.stdPackage+"ObjectHolder"; 173 } 174 } else { 175 StringBuffer sb = new StringBuffer (); 176 Contained cnt = (Contained) type; 177 while (! (cnt instanceof CDLRepository)) { 178 Identification id = cnt.get_identification(); 179 String version = id.version(); 180 String name = id.name(); 181 if (GeneratedObject.isReservedName(name)) 182 name = "_"+name; 183 if (sb.length() == 0) { 184 sb.append(name); 185 } else { 186 sb.insert(0,"."); 187 if (cnt instanceof ModuleDef) 188 sb.insert(0,name); 189 else 190 sb.insert(0,name+"Package"); 191 } 192 cnt = (Contained) cnt.get_defined_in(); 193 } 194 sb.append("Holder"); 195 return sb.toString(); 196 197 } 198 } catch (java.rmi.RemoteException e) { 199 return null; 200 } 201 return null; 202 } 203 204 } 205 | Popular Tags |