1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.io.IOException ; 5 import java.rmi.RemoteException ; 6 7 import SOFA.SOFAnode.Made.TIR.Contained; 8 import SOFA.SOFAnode.Made.TIR.Identification; 9 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 10 import SOFA.SOFAnode.Made.TIR.PrimitiveKind; 11 import SOFA.SOFAnode.Made.TIR.TIRObject; 12 13 17 abstract public class GeneratedObject { 18 19 public static final String stdPackage = "cz.cuni.sofa.lib."; 20 21 public static final String defaultOstream = "ostream"; 22 23 public static final String defaultIstream = "istream"; 24 25 26 public static final int INREF = 1; 27 28 public static final int OUTREF = 2; 29 30 31 public String key; 32 33 34 39 public boolean compareKey(String key) { 40 return this.key.compareTo(key) == 0; 41 } 42 43 47 public abstract String genReference(int kind); 48 49 55 public abstract void genReference(CGFileWriter out, int kind) throws IOException ; 56 57 62 public String genSpecReference(int kind, int specType) { return ""; } 63 64 71 public void genSpecReference(CGFileWriter out, int kind, int specType) throws IOException {;} 72 73 74 79 public abstract void defaultValue(CGFileWriter out) throws IOException ; 80 81 86 public abstract String defaultValue() throws IOException ; 87 88 94 public abstract void genReadType(CGFileWriter out, String varName) throws IOException ; 95 96 101 public abstract String genReadType(String varName) throws IOException ; 102 103 109 public abstract void genWriteType(CGFileWriter out, String varName) throws IOException ; 110 111 116 public abstract String genWriteType(String varName) throws IOException ; 117 118 123 public static String createKey(TIRObject obj) throws RemoteException { 124 if (obj instanceof Contained) { 125 Identification idl = ((Contained) obj).get_identification(); 126 return idl.absolute_name().name()+"?"+idl.version(); 127 } 128 if (obj instanceof PrimitiveDef) { 129 switch (((PrimitiveDef) obj).kind().value()) { 130 case PrimitiveKind.pk_void: 131 return "void"; 132 case PrimitiveKind.pk_ushort: 133 return "ushort"; 134 case PrimitiveKind.pk_short: 135 return "short"; 136 case PrimitiveKind.pk_ulong: 137 return "ulong"; 138 case PrimitiveKind.pk_long: 139 return "long"; 140 case PrimitiveKind.pk_ulonglong: 141 return "ulonglong"; 142 case PrimitiveKind.pk_longlong: 143 return "longlong"; 144 case PrimitiveKind.pk_float: 145 return "float"; 146 case PrimitiveKind.pk_double: 147 return "double"; 148 case PrimitiveKind.pk_longdouble: 149 return null; case PrimitiveKind.pk_boolean: 151 return "boolean"; 152 case PrimitiveKind.pk_wchar: 153 return "wchar"; 154 case PrimitiveKind.pk_char: 155 return "char"; 156 case PrimitiveKind.pk_octet: 157 return "octet"; 158 case PrimitiveKind.pk_wstring: 159 return "wstring"; 160 case PrimitiveKind.pk_string: 161 return "string"; 162 case PrimitiveKind.pk_any: 163 return "any"; 164 case PrimitiveKind.pk_object: 165 return "object"; 166 } 167 } 168 return null; 169 } 170 171 172 static String [] reservedWords = { 173 "abstract", "default", "if", "private", "throw", 174 "boolean", "do", "implements", "protected", "throws", 175 "break", "double", "import", "public", "transient", 176 "byte", "else", "instanceof", "return", "try", 177 "case", "extends", "int", "short", "void", 178 "catch", "final", "interface", "static", "volatile", 179 "char", "finally", "long", "super", "while", 180 "class", "float", "native", "switch", 181 "const", "for", "new", "synchronized", 182 "continue", "goto", "package", "this", 183 "true", "false", "null", 184 "clone", "equals", "finalize", "getClass", "hashCode", 185 "notify", "notifyAll", "toString", "wait", 186 }; 187 188 189 192 public static boolean isReservedName(String name) { 193 for (int i=0;i<reservedWords.length;i++) { 194 if (reservedWords[i].compareToIgnoreCase(name)==0) 195 return true; 196 } 197 String lname = name.toLowerCase(); 198 if (lname.endsWith("helper")) 199 return true; 200 if (lname.endsWith("holder")) 201 return true; 202 if (lname.endsWith("operations")) 203 return true; 204 if (lname.endsWith("package")) 205 return true; 206 return false; 207 } 208 } 209 | Popular Tags |