Changeset 278 for trunk/idl-compiler


Ignore:
Timestamp:
Mar 27, 2007, 10:22:54 PM (18 years ago)
Author:
cinc
Message:

Work on IH file emitter.

Location:
trunk/idl-compiler
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/Makefile

    r277 r278  
    2828PGOBJECTS       =       $(OBJDIR)/nom-idl-compiler.o \
    2929                        $(OBJDIR)/token.o \
     30                        $(OBJDIR)/util.o \
     31                        $(OBJDIR)/emitter.o \
    3032                        $(OBJDIR)/open_outfile.o \
    3133                        $(OBJDIR)/typespec_parser.o \
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r277 r278  
    114114PPARSEINFO pParseInfo=&parseInfo; /* This pointer will go away, don't use */
    115115
    116 /**
    117    Helper function which scans the array of known interfaces and returns the interface
    118    structure for the given name.
    119 
    120    \PARAM chrName Name of the interface.
    121    \Returns If no interface with that name can be found NULL is returned otherwise a
    122    pointer to the interface structure..
    123  */
    124 PINTERFACE findInterfaceFromName(gchar* chrName)
    125 {
    126   int a;
    127 
    128   for(a=0;a<parseInfo.pInterfaceArray->len;a++)
    129     {
    130       PINTERFACE pif=g_ptr_array_index(parseInfo.pInterfaceArray, a);
    131       if(!strcmp(chrName, pif->chrName))
    132         return pif;
    133     }
    134 
    135   return NULL;
    136 }
    137116
    138117/**
  • trunk/idl-compiler/h-emitter_c/h_file_emitter.c

    r277 r278  
    7272}
    7373
    74 /**
    75    Returns the interface structure (holding all the interface information) of the
    76    parent of an interface.
    77 
    78    \Param pif Pointer to an interface structure.
    79    \Returns The interface data structure of the parent interface or NULL if the
    80    interface has no parent.
    81 
    82  */
    83 static PINTERFACE getParentInterface(PINTERFACE pif)
    84 {
    85   if(pif->chrParent==NULL)
    86     return NULL;
    87 
    88   return findInterfaceFromName(pif->chrParent);
    89 }
    9074
    9175static void emitParentHeader(PPARSEINFO pLocalPI, PINTERFACE pif)
     
    145129}
    146130
    147 /*
    148   \param pArray Pointer to the list of parameters.
    149  */
    150 static void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray)
    151 {
    152   FILE* fh=pLocalPI->outFile;
    153   int a;
    154 
    155   for(a=0;a<pArray->len;a++)
    156     {
    157       int b;
    158       PMETHODPARAM pm=(PMETHODPARAM)g_ptr_array_index(pArray, a);
    159 
    160       switch(pm->uiDirection)
    161         {
    162         case PARM_DIRECTION_IN:
    163           fprintf(fh, "    const %s", pm->chrType);
    164           break;
    165         case PARM_DIRECTION_OUT:
    166           fprintf(fh, "    %s*", pm->chrType);
    167           break;
    168         case PARM_DIRECTION_INOUT:
    169 
    170           break;
    171         default:
    172           fprintf(fh, "    %s*", pm->chrType);
    173           break;
    174         }
    175       for(b=0;b<pm->uiStar;b++)
    176         fprintf(fh, "*");
    177       fprintf(fh, " %s,\n", pm->chrName);     
    178     }
    179 }
    180 
    181 /*
    182   \param pArray Pointer to the list of parameters.
    183  */
    184 static void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray)
    185 {
    186   FILE* fh=pLocalPI->outFile;
    187   int a;
    188 
    189   for(a=0;a<pArray->len;a++)
    190     {
    191       PMETHODPARAM pm=(PMETHODPARAM)g_ptr_array_index(pArray, a);
    192       fprintf(fh, " %s,", pm->chrName);     
    193     }
    194 }
    195131
    196132static void emitNewMethods(PPARSEINFO pLocalPI, PINTERFACE pif)
  • trunk/idl-compiler/ih-emitter_c/ih_file_emitter.c

    r277 r278  
    3838#include <glib.h>
    3939#include <glib/gprintf.h>
     40
     41#define INCL_FILE
    4042#include "parser.h"
    4143
     
    4446static void emitIHFileHeader(PPARSEINFO pLocalPI, PINTERFACE pif)
    4547{
    46   FILE* fh=pLocalPI->outFile;
     48  gchar *chrTemp;
     49  FILE* fh=pLocalPI->outFile;
     50
    4751  fprintf(fh, "/*\n * This file was generated by the NOM IDL compiler for Voyager - DO NOT EDIT!\n");
    4852  fprintf(fh, " *\n *\n * And remember, phase 3 is near...\n */\n");
     
    5155  /* Protective #ifndef for whole file */
    5256  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
     65static 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
     87static 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
     113static 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 */
     128NOMEXTERN gboolean NOMLINK objectCheckFunc_WPRootFolder(WPRootFolder *nomSelf, gchar* chrMethodName)
     129{
     130if(!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
     141static 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
     194static 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}
    59224
    60225static void emitIHFileFooter(PPARSEINFO pLocalPI, PINTERFACE pif)
     
    62227  FILE* fh=pLocalPI->outFile;
    63228
    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);
    66231}
    67232
     
    76241      if(!strcmp(pif->chrSourceFileName, pLocalPI->chrRootSourceFile))
    77242        {
    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);
    81260        }
    82261    }
  • trunk/idl-compiler/include/parser.h

    r277 r278  
    180180void emitIHFile(GPtrArray* pInterfaceArray);
    181181
     182/* Emitter support function */
     183void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
     184void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
     185
    182186/* In printdata.c */
    183187void printInterface(PINTERFACE pif);
    184188void printAllInterfacec(void);
     189
     190PINTERFACE getParentInterface(PINTERFACE pif);
     191PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName);
     192PINTERFACE findInterfaceFromName(gchar* chrName);
     193PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName);
    185194
    186195#ifdef INCL_FILE
Note: See TracChangeset for help on using the changeset viewer.