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

More work on the IDL compiler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.