Changeset 278 for trunk/idl-compiler/ih-emitter_c
- Timestamp:
- Mar 27, 2007, 10:22:54 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/ih-emitter_c/ih_file_emitter.c
r277 r278 38 38 #include <glib.h> 39 39 #include <glib/gprintf.h> 40 41 #define INCL_FILE 40 42 #include "parser.h" 41 43 … … 44 46 static void emitIHFileHeader(PPARSEINFO pLocalPI, PINTERFACE pif) 45 47 { 46 FILE* fh=pLocalPI->outFile; 48 gchar *chrTemp; 49 FILE* fh=pLocalPI->outFile; 50 47 51 fprintf(fh, "/*\n * This file was generated by the NOM IDL compiler for Voyager - DO NOT EDIT!\n"); 48 52 fprintf(fh, " *\n *\n * And remember, phase 3 is near...\n */\n"); … … 51 55 /* Protective #ifndef for whole file */ 52 56 fprintf(fh, "#ifndef %s_IH\n#define %s_IH\n\n", pif->chrName, pif->chrName); 53 /* The *.h of this class conatins some declarations we need */ 54 fprintf(fh, "#include \"%s.h\"\n", pif->chrName); 55 56 } 57 58 57 58 /* The *.h of this class contains some declarations we need */ 59 chrTemp=strlwr(g_strdup(pif->chrName)); 60 fprintf(fh, "#include \"%s.h\"\n\n", chrTemp); 61 g_free(chrTemp); 62 } 63 64 65 static void emitInstanceVariables(PPARSEINFO pLocalPI, PINTERFACE pif) 66 { 67 int a; 68 FILE* fh=pLocalPI->outFile; 69 GPtrArray *pArray=pif->pInstanceVarArray;; 70 71 fprintf(fh, "/*\n * Instance variables for %s\n */\n", pif->chrName); 72 fprintf(fh, "typedef struct {\n"); 73 74 for(a=0;a<pArray->len;a++) 75 { 76 int b; 77 PMETHODPARAM piv=(PMETHODPARAM)g_ptr_array_index(pArray, a); 78 79 fprintf(fh, " %s", piv->chrType); 80 for(b=0;b<piv->uiStar;b++) 81 fprintf(fh, "*"); 82 fprintf(fh, " %s;\n", piv->chrName); 83 } 84 fprintf(fh, "}%sData;\n\n", pif->chrName); 85 } 86 87 static void emitGetDataMacros(PPARSEINFO pLocalPI, PINTERFACE pif) 88 { 89 FILE* fh=pLocalPI->outFile; 90 GPtrArray *pArray=pif->pInstanceVarArray;; 91 int a; 92 93 fprintf(fh, "/*\n * Get data macros for %s\n */\n", pif->chrName); 94 fprintf(fh, "typedef %sData* NOMLINK nomTP_%s_DataThunk(void*);\n", 95 pif->chrName , pif->chrName); 96 fprintf(fh, "typedef nomTP_%s_DataThunk *nomTD_%s_DataThunk;\n", 97 pif->chrName , pif->chrName); 98 99 fprintf(fh, "#define %sGetData(nomSelf) \\\n", pif->chrName); 100 fprintf(fh, " (((nomTD_%s_DataThunk)(%sCClassData.instanceDataToken))(nomSelf))\n", 101 pif->chrName , pif->chrName); 102 103 for(a=0;a<pArray->len;a++) 104 { 105 PMETHODPARAM piv=(PMETHODPARAM)g_ptr_array_index(pArray, a); 106 107 fprintf(fh, "#define _%s (nomThis->%s);\n", piv->chrName, piv->chrName); 108 } 109 fprintf(fh, "\n"); 110 } 111 112 113 static void emitIHClassDataStructs(PPARSEINFO pLocalPI, PINTERFACE pif) 114 { 115 FILE* fh=pLocalPI->outFile; 116 117 fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n\n", pif->chrName); 118 119 fprintf(fh, "/*** Class data structures ***/\n"); 120 fprintf(fh, "struct %sClassDataStructure %sClassData = {0};\n", pif->chrName, pif->chrName ); 121 fprintf(fh, "static struct %sCClassDataStructure %sCClassData = {0};\n\n", 122 pif->chrName, pif->chrName); 123 } 124 125 #if 0 126 /* Function to check if an object is valid before calling a method on it */ 127 #ifdef NOM_NO_PARAM_CHECK /* Disabled by now because not working */ 128 NOMEXTERN gboolean NOMLINK objectCheckFunc_WPRootFolder(WPRootFolder *nomSelf, gchar* chrMethodName) 129 { 130 if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf , WPRootFolderClassData.classObject, NULLHANDLE)) 131 { 132 nomPrintObjectPointerError(nomSelf, "WPRootFolder", chrMethodName); 133 g_message("Note that NULL is returned for the call (if the method returns a value). This may not be correct. Use the NOMPARMCHECK() macro to specify default return values for methods."); 134 return FALSE; 135 } 136 return TRUE; 137 } 138 #endif 139 #endif 140 141 static void emitOverridenMethods(PPARSEINFO pLocalPI, PINTERFACE pif) 142 { 143 FILE* fh=pLocalPI->outFile; 144 GPtrArray *pArray; 145 int a; 146 147 pArray=pif->pOverrideArray; 148 149 for(a=0;a<pArray->len;a++) 150 { 151 int b; 152 POVERMETHOD pom=(POVERMETHOD)g_ptr_array_index(pArray, a); 153 /* Method information */ 154 PMETHOD pm=findMethodInfoFromMethodName(pif, pom->chrName); 155 /* Pointer to interface which introduced the method */ 156 PINTERFACE pifIntroduced=findInterfaceFromMethodName(pif, pom->chrName); 157 158 fprintf(fh, "/*\n * Overriden method: %s \n */\n", pom->chrName); 159 fprintf(fh, "#ifndef _decl_impl_%s_%s_\n", pif->chrName, pom->chrName); 160 fprintf(fh, "#define _decl_impl_%s_%s_\n", pif->chrName, pom->chrName); 161 162 if(!pm || !pifIntroduced) 163 { 164 g_message("Can't get information about method \"%s\" from parent classes while overriding.", pom->chrName); 165 exit(1); 166 } 167 168 fprintf(fh, "NOM_Scope %s", pm->mpReturn.chrType); 169 for(b=0;b<pm->mpReturn.uiStar;b++) 170 fprintf(fh, "*"); 171 172 fprintf(fh, " NOMLINK impl_%s_%s(%s* nomSelf,\n", pif->chrName, pom->chrName, pif->chrName); 173 /* Do parameters */ 174 emitMethodParams(pLocalPI, pif, pm->pParamArray); 175 fprintf(fh, " CORBA_Environment *ev);\n"); 176 fprintf(fh, "static char* nomIdString_%s_%s = \"%s:%s\";\n", 177 pif->chrName, pom->chrName, pifIntroduced->chrName, pom->chrName); 178 fprintf(fh, "static nomMethodProc* %s_%s_parent_resolved;\n", 179 pif->chrName, pom->chrName); 180 fprintf(fh, "#define %s_%s_parent(nomSelf,", 181 pif->chrName, pom->chrName); 182 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 183 fprintf(fh, " ev) \\\n"); 184 fprintf(fh, " (((nomTD_%s_%s) \\\n", pif->chrName, pom->chrName); 185 186 fprintf(fh, " %s_%s_parent_resolved)((%s*)nomSelf,", 187 pif->chrName, pom->chrName, pifIntroduced->chrName); 188 emitMethodParamsNoTypes(pLocalPI, pif, pm->pParamArray); 189 fprintf(fh, " ev))\n"); 190 fprintf(fh, "#endif /* _decl_impl_%s_%s_ */\n\n", pif->chrName, pom->chrName); 191 } 192 }; 193 194 static void emitOverridenMethodTable(PPARSEINFO pLocalPI, PINTERFACE pif) 195 { 196 FILE* fh=pLocalPI->outFile; 197 GPtrArray *pArray; 198 int a; 199 200 fprintf(fh, "/*** Overriden method table ***/\n"); 201 fprintf(fh, "static nomOverridenMethodDesc nomOverridenMethodsWPRootFolder[] = {\n"); 202 203 for(a=0;a<pArray->len;a++) 204 { 205 POVERMETHOD pom=(POVERMETHOD)g_ptr_array_index(pArray, a); 206 /* Method information */ 207 PMETHOD pm=findMethodInfoFromMethodName(pif, pom->chrName); 208 209 if(!pm) 210 { 211 g_message("Can't get information about method \"%s\" from parent classes while overriding.", pom->chrName); 212 exit(1); 213 } 214 215 fprintf(fh, " {\n"); 216 fprintf(fh, " &nomIdString_%s_%s,\n", pif->chrName, pom->chrName); 217 fprintf(fh, " (nomMethodProc*) impl_%s_%s,\n", pif->chrName, pom->chrName); 218 fprintf(fh, " &%s_%s_parent_resolved\n", pif->chrName, pom->chrName); 219 fprintf(fh, " },\n"); 220 } 221 fprintf(fh, "};\n\n"); 222 223 } 59 224 60 225 static void emitIHFileFooter(PPARSEINFO pLocalPI, PINTERFACE pif) … … 62 227 FILE* fh=pLocalPI->outFile; 63 228 64 65 fprintf(fh, " \n#endif/* %s_IH */\n", pif->chrName);229 fprintf(fh, "\n#endif /* NOM_%s_IMPLEMENTATION_FILE */\n", pif->chrName); 230 fprintf(fh, "#endif/* %s_IH */\n", pif->chrName); 66 231 } 67 232 … … 76 241 if(!strcmp(pif->chrSourceFileName, pLocalPI->chrRootSourceFile)) 77 242 { 78 emitIHFileHeader(pLocalPI, pif); 79 80 emitIHFileFooter(pLocalPI, pif); 243 gchar* chrTemp; 244 245 printInterface(pif); 246 247 chrTemp=g_strconcat(pif->chrFileStem, ".ih", NULL); 248 if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULLHANDLE) 249 { 250 emitIHFileHeader(pLocalPI, pif); 251 emitInstanceVariables(pLocalPI, pif); 252 emitGetDataMacros(pLocalPI, pif); 253 emitIHClassDataStructs(pLocalPI, pif); 254 emitOverridenMethods(pLocalPI, pif); 255 emitOverridenMethodTable(pLocalPI, pif); 256 257 emitIHFileFooter(pLocalPI, pif); 258 } 259 g_free(chrTemp); 81 260 } 82 261 }
Note:
See TracChangeset
for help on using the changeset viewer.