Changeset 273 for trunk/idl-compiler
- Timestamp:
- Mar 25, 2007, 11:19:03 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/h-emitter_c/h_file_emitter.c
r272 r273 40 40 #include "parser.h" 41 41 42 43 42 extern GScanner *gScanner; 44 43 44 static void emitHFileHeader(PPARSEINFO pLocalPI, PINTERFACE pif) 45 { 46 FILE* fh=pLocalPI->outFile; 47 fprintf(fh, "/*\n * This file was generated by the NOM IDL compiler for Voyager - DO NOT EDIT!\n"); 48 fprintf(fh, " *\n *\n * And remember, phase 3 is near...\n */\n"); 49 fprintf(fh, "/*\n * %s\n */\n", pif->chrSourceFileName); 50 51 /* Protective #ifndef for whole file */ 52 fprintf(fh, "#ifndef %s_H\n#define %s_H\n\n", pif->chrName, pif->chrName); 53 54 fprintf(fh, "#include <glib.h>\n"); 55 fprintf(fh, "#include <nomcls.h> /* This is needed for _nomNew() */\n\n"); 56 57 fprintf(fh, "#ifdef __cplusplus\n"); 58 fprintf(fh, "extern \"C\" {\n"); 59 fprintf(fh, "#endif /* __cplusplus */\n\n"); 60 61 /* Define the name as an object */ 62 fprintf(fh, "#if !defined(_%s_defined)\n", pif->chrName); 63 fprintf(fh, "#define _%s_defined 1\n", pif->chrName); 64 fprintf(fh, "#ifndef %s\n", pif->chrName); 65 fprintf(fh, "#define %s NOMObject\n", pif->chrName); 66 fprintf(fh, "typedef %s *P%s;\n", pif->chrName, pif->chrName); 67 fprintf(fh, "#endif\n"); 68 fprintf(fh, "#endif\n\n"); 69 70 } 71 72 /** 73 Returns the interface structure (holding all the interface information) of the 74 parent of an interface. 75 76 \Param pif Pointer to an interface structure. 77 \Returns The interface data structure of the parent interface or NULL if the 78 interface has no parent. 79 80 */ 81 static PINTERFACE getParentInterface(PINTERFACE pif) 82 { 83 if(pif->chrParent==NULL) 84 return NULL; 85 86 return findInterfaceFromName(pif->chrParent); 87 } 88 89 static void emitParentHeader(PPARSEINFO pLocalPI, PINTERFACE pif) 90 { 91 FILE* fh=pLocalPI->outFile; 92 PINTERFACE pifParent=getParentInterface(pif); 93 94 /* Include header of parent */ 95 if(pifParent){ 96 char* chrTemp=strlwr(g_strdup(pifParent->chrName)); 97 fprintf(fh, "/* Include for the parent class */\n"); 98 fprintf(fh, "#include \"%s.h\"\n\n", chrTemp); 99 g_free(chrTemp); 100 } 101 } 102 103 static void emitClassVersion(PPARSEINFO pLocalPI, PINTERFACE pif) 104 { 105 FILE* fh=pLocalPI->outFile; 106 107 fprintf(fh, "#define %s_MajorVersion %ld\n", pif->chrName, pif->ulMajor); 108 fprintf(fh, "#define %s_MinorVersion %ld\n\n", pif->chrName, pif->ulMinor); 109 } 110 111 static void emitClassDataStruct(PPARSEINFO pLocalPI, PINTERFACE pif) 112 { 113 int a; 114 FILE* fh=pLocalPI->outFile; 115 116 fprintf(fh, "/* Class data structure */\n"); 117 fprintf(fh, "NOMEXTERN struct %sClassDataStructure {\n", pif->chrName); 118 119 fprintf(fh, " NOMClass *classObject;\n"); 120 /* Do introduced methods */ 121 for(a=0;a<pif->pMethodArray->len;a++) 122 { 123 PMETHOD pm=(PMETHOD)g_ptr_array_index(pif->pMethodArray, a); 124 fprintf(fh, " nomMToken %s;\n", pm->chrName); 125 } 126 fprintf(fh, "}%sClassData\n\n", pif->chrName); 127 } 128 129 130 static void emitObjectCheckFunction(PPARSEINFO pLocalPI, PINTERFACE pif) 131 { 132 FILE* fh=pLocalPI->outFile; 133 134 fprintf(fh, "/* This function is used to check if a given object is valid and the\n"); 135 fprintf(fh, " object supports the method */\n"); 136 fprintf(fh, "NOMEXTERN gboolean NOMLINK nomCheckObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev);\n\n"); 137 } 138 139 /* 140 \param pArray Pointer to the list of parameters. 141 */ 142 static void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray) 143 { 144 FILE* fh=pLocalPI->outFile; 145 int a; 146 147 for(a=0;a<pArray->len;a++) 148 { 149 int b; 150 PMETHODPARAM pm=(PMETHODPARAM)g_ptr_array_index(pArray, a); 151 152 switch(pm->uiDirection) 153 { 154 case PARM_DIRECTION_IN: 155 fprintf(fh, " const %s", pm->chrType); 156 break; 157 case PARM_DIRECTION_OUT: 158 fprintf(fh, " %s*", pm->chrType); 159 break; 160 case PARM_DIRECTION_INOUT: 161 162 break; 163 default: 164 fprintf(fh, " %s*", pm->chrType); 165 break; 166 } 167 for(b=0;b<pm->uiStar;b++) 168 fprintf(fh, "*"); 169 fprintf(fh, " %s,\n", pm->chrName); 170 } 171 } 172 173 /* 174 \param pArray Pointer to the list of parameters. 175 */ 176 static void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray) 177 { 178 FILE* fh=pLocalPI->outFile; 179 int a; 180 181 for(a=0;a<pArray->len;a++) 182 { 183 PMETHODPARAM pm=(PMETHODPARAM)g_ptr_array_index(pArray, a); 184 fprintf(fh, " %s,", pm->chrName); 185 } 186 } 187 188 static void emitNewMethods(PPARSEINFO pLocalPI, PINTERFACE pif) 189 { 190 int a; 191 GPtrArray *pArray; 192 FILE* fh=pLocalPI->outFile; 193 194 pArray=pif->pMethodArray; 195 196 for(a=0;a<pArray->len;a++) 197 { 198 int b; 199 PMETHOD pm=(PMETHOD)g_ptr_array_index(pArray, a); 200 201 fprintf(fh, "/*\n * New method: %s \n */\n", pm->chrName); 202 fprintf(fh, "#ifndef _decl_%s_%s_\n", pif->chrName, pm->chrName); 203 fprintf(fh, "#define _decl_%s_%s_\n\n", pif->chrName, pm->chrName); 204 205 /* Do return type */ 206 fprintf(fh, "typedef %s", pm->mpReturn.chrType); 207 for(b=0;b<pm->mpReturn.uiStar;b++) 208 fprintf(fh, "*"); 209 210 fprintf(fh, " NOMLINK nomTP_%s_%s(%s* nomSelf,\n", pif->chrName, pm->chrName, pif->chrName); 211 212 /* Do parameters */ 213 emitMethodParams(pLocalPI, pif, pm->pParamArray); 214 215 fprintf(fh, " Corba_Environment *ev);\n"); 216 fprintf(fh, "typedef nomTP_%s_%s *nomTD_%s_%s\n", pif->chrName, pm->chrName, 217 pif->chrName, pm->chrName); 218 fprintf(fh, "/* define the name for this method */\n"); 219 fprintf(fh, "#define nomMNDef_%s_%s \"%s\"\n", pif->chrName, pm->chrName, pm->chrName); 220 fprintf(fh, "#define nomMNFullDef_%s_%s \"%s:%s\"\n", 221 pif->chrName, pm->chrName, pif->chrName, pm->chrName); 222 223 fprintf(fh, "/* define method call as a macro */\n"); 224 fprintf(fh, "#ifndef NOM_NO_PARAM_CHECK /* Parameter check at all? */\n"); 225 fprintf(fh, "#ifdef %s_%s_ParmCheck_h /* Extended parameter check enabled */\n", 226 pif->chrName, pm->chrName); 227 fprintf(fh, "NOMEXTERN gboolean NOMLINK parmCheckFunc_%s_%s(%s *nomSelf,\n", 228 pif->chrName, pm->chrName, pif->chrName); 229 /* Do parameters */ 230 emitMethodParams(pLocalPI, pif, pm->pParamArray); 231 fprintf(fh, " Corba_Environment *ev);\n"); 232 233 fprintf(fh, "#define %s_%s(nomSelf,", pif->chrName, pm->chrName); 234 /* Do parameters */ 235 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 236 fprintf(fh, " ev) \\\n"); 237 fprintf(fh, " (parmCheckFunc_%s_%s(nomSelf,", pif->chrName, pm->chrName); 238 /* Do parameters */ 239 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 240 fprintf(fh, " ev) ? \\\n"); 241 fprintf(fh, " (NOM_Resolve(nomSelf, %s, %s) \\\n", pif->chrName, pm->chrName); 242 fprintf(fh, " (nomSelf,"); 243 /* Do parameters */ 244 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 245 fprintf(fh, " ev)) : %s_%s_retval)\n", pif->chrName, pm->chrName); 246 fprintf(fh, "#else /* Extended parameter check */\n"); 247 fprintf(fh, "#define %s_%s(nomSelf,", pif->chrName, pm->chrName); 248 /* Do parameters */ 249 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 250 fprintf(fh, " ev) \\\n"); 251 fprintf(fh, " (nomCheckObjectPtr((NOMObject*)nomSelf, %sClassData.classObject,",pif->chrName); 252 fprintf(fh, "\"%s_%s\", ev) ? \\\n", pif->chrName, pm->chrName); 253 254 fprintf(fh, " (NOM_Resolve(nomSelf, %s, %s) \\\n", pif->chrName, pm->chrName); 255 fprintf(fh, " (nomSelf,"); 256 /* Do parameters */ 257 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 258 fprintf(fh, " ev)) : (gpointer) NULL)\n"); 259 fprintf(fh, "#endif\n"); 260 fprintf(fh, "#else /* NOM_NO_PARAM_CHECK */\n"); 261 fprintf(fh, "#define %s_%s(nomSelf,", pif->chrName, pm->chrName); 262 /* Do parameters */ 263 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 264 fprintf(fh, " ev) \\\n"); 265 fprintf(fh, " (NOM_Resolve(nomSelf, %s, %s) \\\n", pif->chrName, pm->chrName); 266 fprintf(fh, " (nomSelf,"); 267 /* Do parameters */ 268 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 269 fprintf(fh, " ev))\n"); 270 fprintf(fh, "#endif\n"); 271 fprintf(fh, "#define _%s %s_%s\n", pm->chrName, pif->chrName, pm->chrName); 272 fprintf(fh, "#endif /* _decl_%s_%s_ */ \n\n", pif->chrName, pm->chrName); 273 } 274 }; 275 276 static void emitHFileFooter(PPARSEINFO pLocalPI, PINTERFACE pif) 277 { 278 FILE* fh=pLocalPI->outFile; 279 280 fprintf(fh, "#ifdef __cplusplus\n"); 281 fprintf(fh, "}\n"); 282 fprintf(fh, "#endif /* __cplusplus */\n\n"); 283 284 fprintf(fh, "\n#endif /* %s_H */\n", pif->chrName); 285 } 286 45 287 void emitHFile(GPtrArray* pInterfaceArray) 46 288 { 47 289 int a; 48 PPARSEINFO p ParseInfo=(PPARSEINFO)gScanner->user_data;290 PPARSEINFO pLocalPI=(PPARSEINFO)gScanner->user_data; 49 291 50 292 for(a=0;a<pInterfaceArray->len;a++) 51 293 { 52 PINTERFACE pif=g_ptr_array_index(pParseInfo->pInterfaceArray, a); 53 if(!strcmp(pif->chrSourceFileName, pParseInfo->chrRootSourceFile)) 54 printInterface(pif); 55 } 56 } 294 PINTERFACE pif=g_ptr_array_index(pLocalPI->pInterfaceArray, a); 295 if(!strcmp(pif->chrSourceFileName, pLocalPI->chrRootSourceFile)) 296 { 297 printInterface(pif); 298 299 emitHFileHeader(pLocalPI, pif); 300 emitParentHeader(pLocalPI, pif); 301 emitClassVersion(pLocalPI, pif); 302 emitClassDataStruct(pLocalPI, pif); 303 emitObjectCheckFunction(pLocalPI, pif); 304 emitNewMethods(pLocalPI, pif); 305 emitHFileFooter(pLocalPI, pif); 306 } 307 } 308 } 309 310
Note:
See TracChangeset
for help on using the changeset viewer.