Changeset 261


Ignore:
Timestamp:
Mar 24, 2007, 12:51:37 AM (18 years ago)
Author:
cinc
Message:

More work on the IDL compiler

Location:
trunk/idl-compiler
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r260 r261  
    8585
    8686
     87PINTERFACE findInterfaceFromName(gchar* chrName)
     88{
     89  int a;
     90
     91  for(a=0;a<pInterfaceArray->len;a++)
     92    {
     93      PINTERFACE pif=g_ptr_array_index(pInterfaceArray, a);
     94      if(!strcmp(chrName, pif->chrName))
     95        return pif;
     96    }
     97
     98  return NULL;
     99}
     100
    87101
    88102gchar* getTypeSpecStringFromCurToken(void)
     
    111125}
    112126
    113 void parseIt()
    114 {
    115 
    116 }
    117 
    118 
    119 /*
    120   Main entry point. This function is called from the EMX wrapper. Be aware that gtk_init()
    121   is already called in the wrapper.
     127/**
     128   This is the root parse function. Here starts the fun...
    122129 */
    123 int main(int argc, char **argv)
    124 {
    125   int a;
    126   int fd;
    127  
    128   int idScope=0;
    129 
    130   if(argc<2)
    131     return 1;
    132 
    133   for(a=0; a<argc; a++)
    134     {
    135       g_message("arg %d: %s", a, argv[a]);
    136     }
    137 
    138   fd=open(argv[1], O_RDONLY);
    139  
    140   if(-1==fd)
    141     {
    142       g_message("Can't open input file %s", argv[1]);
    143       exit(1);
    144     }
    145  
    146   g_printf("\n");
    147 
    148   gScanner=g_scanner_new(NULL);
    149   gScanner->user_data=(gpointer)&curSymbol;
    150   curSymbol.pSymbols=idlSymbols;
    151 
    152   pInterfaceArray=g_ptr_array_new();
    153 
    154   g_scanner_input_file(gScanner, fd);
    155   /* No single line comments */
    156   gScanner->config->skip_comment_single=FALSE;
    157   gScanner->config->cpair_comment_single="";
    158   gScanner->input_name=IDL_COMPILER_STRING;
    159 
    160   g_scanner_set_scope(gScanner, idScope);
    161   /* Load our own symbols into the scanner. We use the defualt scope for now. */
    162   while(pSymbols->chrSymbolName)
    163     {
    164       g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, GINT_TO_POINTER(pSymbols->uiSymbolToken));
    165       pSymbols++;
    166     }
    167   gScanner->config->symbol_2_token=TRUE;
    168 
     130void parseIt(void)
     131{
    169132  while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) {
    170     /* get the next token */
    171133    GTokenType token;
     134
    172135    curToken=g_scanner_get_next_token(gScanner);
    173136    token=curToken;
     
    179142        parseInterface(token);
    180143        break;
     144
     145#if 0
    181146      case G_TOKEN_IDENTIFIER:
    182147        g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s", token, value.v_identifier);
     
    218183        g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token);
    219184        break;
     185#endif
    220186      default:
    221         g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));
     187        printToken(curToken);
     188        //  g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));
    222189        break;
    223190      }
    224191  }
    225   if(pCurInterface)
     192}
     193
     194
     195/*
     196
     197 */
     198int main(int argc, char **argv)
     199{
     200  int a;
     201  int fd;
     202 
     203  int idScope=0;
     204
     205  if(argc<2)
     206    return 1;
     207
     208  for(a=0; a<argc; a++)
     209    {
     210      g_message("arg %d: %s", a, argv[a]);
     211    }
     212
     213  fd=open(argv[1], O_RDONLY);
     214 
     215  if(-1==fd)
     216    {
     217      g_message("Can't open input file %s", argv[1]);
     218      exit(1);
     219    }
     220 
     221  g_printf("\n");
     222
     223  gScanner=g_scanner_new(NULL);
     224  gScanner->user_data=(gpointer)&curSymbol;
     225  curSymbol.pSymbols=idlSymbols;
     226
     227  pInterfaceArray=g_ptr_array_new();
     228
     229  g_scanner_input_file(gScanner, fd);
     230  /* No single line comments */
     231  gScanner->config->skip_comment_single=FALSE;
     232  gScanner->config->cpair_comment_single="";
     233  /* This string is used in error messages of the parser */
     234  gScanner->input_name=IDL_COMPILER_STRING;
     235
     236  g_scanner_set_scope(gScanner, idScope);
     237  /* Load our own symbols into the scanner. We use the default scope for now. */
     238  while(pSymbols->chrSymbolName)
     239    {
     240      g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, GINT_TO_POINTER(pSymbols->uiSymbolToken));
     241      pSymbols++;
     242    }
     243  gScanner->config->symbol_2_token=TRUE;
     244
     245  parseIt();
     246
     247  if(pInterfaceArray->len)
    226248    printInterface();
    227249
  • trunk/idl-compiler/c/printdata.c

    r259 r261  
    140140      g_printf("Found Interface:\n"); 
    141141      g_printf("\tName:\t\t%s\n", pif->chrName);
     142      g_printf("\tParent:\t\t%s\n", (pif->chrParent ? pif->chrParent : "No parent"));
    142143      g_printf("\tMajor:\t\t%ld\n", pif->ulMajor);
    143144      g_printf("\tMinor:\t\t%ld\n", pif->ulMinor);
  • trunk/idl-compiler/include/parser.h

    r260 r261  
    136136};
    137137
     138PINTERFACE findInterfaceFromName(gchar* chrName);
    138139
    139140void parseTypeSpec(PMETHODPARAM pMethodParam);
  • trunk/idl-compiler/parser_c/interface_parser.c

    r259 r261  
    3434#include <os2.h>
    3535#include <stdlib.h>
     36#include <string.h>
    3637
    3738#include <glib.h>
     
    6566     | OV                                             // Overriden method
    6667 */
    67 void parseIFaceBody(void)
     68void parseIBody(void)
    6869{
    6970  /* Current token is '{' */
     
    9798
    9899/*
     100  Parse the interface name.
     101  Note that the current token is the 'interface' keyword.
     102
    99103  I:= IDL_SYMBOL_INTERFACE G_TOKEN_INDENTIFIER
    100104 */
     
    114118  /* Save interface info */
    115119  GTokenValue value=gScanner->value;
    116   pCurInterface=createInterfaceStruct();
    117120  pCurInterface->chrName=g_strdup(value.v_identifier);
    118121}
    119122
    120123/*
     124  Current token is '{'.
     125
     126  IB2:= '{' IB '}'
     127      | '{' IB '}' ';'
     128
     129*/
     130static void parseIFaceBody(void)
     131{
     132  parseIBody();
     133  if(!matchNext('}'))
     134    {
     135      g_scanner_unexp_token(gScanner,
     136                            '}',
     137                            NULL,
     138                            NULL,
     139                            NULL,
     140                            "No closing of 'interface' section.",
     141                            TRUE); /* is_error */
     142      exit(1);
     143    }
     144  /* Remove a terminating ';' from the input if present. */
     145  matchNext(';');
     146}
     147
     148/*
     149  Parse an interface which is subclassed. This includes checking if the parent
     150  interface is already defined.
     151
     152  IS:= G_TOKEN_INDENTIFIER IB2
     153 */
     154static void parseSubclassedIFace()
     155{
     156
     157  /* Parent interface */
     158  if(!matchNext(G_TOKEN_IDENTIFIER))
     159    {
     160      g_scanner_unexp_token(gScanner,
     161                            G_TOKEN_IDENTIFIER,
     162                            NULL,
     163                            NULL,
     164                            NULL,
     165                            "Parent interface name is missing.",
     166                            TRUE); /* is_error */
     167      exit(1);
     168    }
     169  GTokenValue value=gScanner->value;
     170  pCurInterface->chrParent=g_strdup(value.v_identifier);
     171
     172  /* Check if the parent interface is known. */
     173  if(!findInterfaceFromName(pCurInterface->chrParent))
     174  {
     175    g_scanner_unexp_token(gScanner,
     176                          G_TOKEN_IDENTIFIER,
     177                          NULL,
     178                          NULL,
     179                          NULL,
     180                          "Parent interface in definition is unknown.",
     181                          TRUE); /* is_error */
     182    exit(1);
     183
     184  }
     185
     186  if(!matchNext('{'))
     187    {
     188      g_scanner_unexp_token(gScanner,
     189                            '{',
     190                            NULL,
     191                            NULL,
     192                            NULL,
     193                            "No opening brace in interface definition.",
     194                            TRUE); /* is_error */
     195      exit(1);
     196     
     197    }
     198  parseIFaceBody();
     199}
     200
     201/*
    121202  Parse an interface declaration. The current token is the 'interface' keyword.
     203
     204  interface:= I ';'                       // Forward declaration
     205            | I IB2
     206            | I ':' IS                    // Subclassed interface
     207
     208  This translates into:
    122209
    123210  interface:= I ';'                       // Forward declaration
    124211            | I '{' IB '}'
    125             | I ':' G_TOKEN_INDENTIFIER '{' ID '}'
    126 
    127  
     212            | I ':' G_TOKEN_INDENTIFIER '{' IB '}'
    128213 */
    129214void parseInterface(GTokenType token)
    130215{
     216  pCurInterface=createInterfaceStruct();
     217
     218  /* Get the interface name */
    131219  parseIFace(token);
    132   getNextToken();
    133   switch(curToken)
    134     {
    135     case ';':
    136       if(pCurInterface)
    137         {
    138           pCurInterface->fIsForwardDeclaration=TRUE;
    139           g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
    140           pCurInterface=NULL;
    141         }
    142       break;
    143     case ':':
    144       g_message("Line %d: Defining subclasses interfaces not supported yet",  g_scanner_cur_line(gScanner));
    145       exit(0);
    146     case '{':
     220
     221  if(matchNext(';'))
     222    {
     223      pCurInterface->fIsForwardDeclaration=TRUE;
     224      g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
     225
     226    }
     227  else if(matchNext(':'))
     228    {
     229      parseSubclassedIFace();
     230      g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
     231    }
     232  else if(matchNext('{'))
     233    {
    147234      parseIFaceBody();
    148235      g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
    149       break;
    150     default:
     236    }
     237  else
     238    {
    151239      g_message("Line %d: Error in interface declaration",  g_scanner_cur_line(gScanner));
    152240      exit(0);
    153       break;
    154     }
    155 }
     241    }
     242}
     243
Note: See TracChangeset for help on using the changeset viewer.