Ignore:
Timestamp:
Mar 25, 2007, 1:07:25 AM (18 years ago)
Author:
cinc
Message:

Getting along with parsing

Location:
trunk/idl-compiler/parser_c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/parser_c/interface_parser.c

    r265 r266  
    4545/* The pointer array holding the interfaces we found */
    4646extern GPtrArray* pInterfaceArray;
    47 
     47extern PARSEINFO parseInfo;
     48
     49static void registerInterface(void)
     50{
     51  PSYMBOL pNewSymbol=g_malloc0(sizeof(SYMBOL));
     52
     53  g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
     54
     55  /* Any found interface is registered as a new type so it can be
     56     used in other classes. */
     57  pNewSymbol->chrSymbolName=g_strdup(pCurInterface->chrName); /* We create a copy here because
     58                                                                 when cleaning up the symbol space
     59                                                                 the string will be freed. */
     60  pNewSymbol->uiKind=KIND_TYPESPEC;
     61  pNewSymbol->uiSymbolToken=IDL_SYMBOL_REGINTERFACE;
     62  g_tree_insert(parseInfo.pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName);
     63  g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pNewSymbol->chrSymbolName,
     64                             pNewSymbol);
     65}
    4866
    4967static PINTERFACE createInterfaceStruct()
     
    178196  interface is already defined.
    179197
    180   IS:= G_TOKEN_INDENTIFIER IB2
     198  IS:= G_TOKEN_SYMBOL IB2
     199
     200  It's G_TOKEN_SYMBOL here because every found interface is registered
     201  as a new symbol with GScanner.
    181202 */
    182203static void parseSubclassedIFace()
    183204{
     205  PSYMBOL pCurSymbol;
    184206
    185207  /* Parent interface */
    186   if(!matchNext(G_TOKEN_IDENTIFIER))
    187     {
    188       g_scanner_unexp_token(gScanner,
    189                             G_TOKEN_IDENTIFIER,
    190                             NULL,
    191                             NULL,
    192                             NULL,
    193                             "Parent interface name is missing.",
     208  if(!matchNext(G_TOKEN_SYMBOL))
     209    {
     210      g_scanner_unexp_token(gScanner,
     211                            G_TOKEN_SYMBOL,
     212                            NULL,
     213                            NULL,
     214                            NULL,
     215                            "Parent interface name is missing or unknown.",
    194216                            TRUE); /* is_error */
    195217      exit(1);
    196218    }
    197219  GTokenValue value=gScanner->value;
    198   pCurInterface->chrParent=g_strdup(value.v_identifier);
     220  /* Make sure it's the correct symbol */
     221  pCurSymbol=value.v_symbol;
     222
     223  if(IDL_SYMBOL_REGINTERFACE!=pCurSymbol->uiSymbolToken)
     224    {
     225      g_scanner_unexp_token(gScanner,
     226                            G_TOKEN_SYMBOL,
     227                            NULL,
     228                            NULL,
     229                            NULL,
     230                            "Parent interface name is unknown.",
     231                            TRUE); /* is_error */
     232      exit(1);
     233    }
     234  pCurInterface->chrParent=g_strdup(pCurSymbol->chrSymbolName);
    199235
    200236  /* Check if the parent interface is known. */
     
    209245                          TRUE); /* is_error */
    210246    exit(1);
    211 
    212247  }
    213248
     
    238273  interface:= I ';'                       // Forward declaration
    239274            | I '{' IB '}'
    240             | I ':' G_TOKEN_INDENTIFIER '{' IB '}'
     275            | I ':' G_TOKEN_SYMBOL '{' IB '}'
     276
     277            It's G_TOKEN_SYMBOL here because every found interface is registered
     278            as a new symbol with GScanner.
    241279 */
    242280void parseInterface(GTokenType token)
     
    246284  /* Get the interface name */
    247285  parseIFace(token);
     286  /* It's save to register the interface right here even if the struct is almost empty.
     287     If anything goes wrong later we will exit anyway. */
     288  registerInterface(); 
    248289
    249290  if(matchNext(';'))
    250291    {
    251292      pCurInterface->fIsForwardDeclaration=TRUE;
    252       g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
    253 
    254293    }
    255294  else if(matchNext(':'))
    256295    {
    257296      parseSubclassedIFace();
    258       g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
    259297    }
    260298  else if(matchNext('{'))
    261299    {
    262300      parseIFaceBody();
    263       g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
    264301    }
    265302  else
  • trunk/idl-compiler/parser_c/lineinfo_parser.c

    r264 r266  
    4040
    4141extern GScanner *gScanner;
    42  
     42extern PARSEINFO parseInfo;
    4343
    4444/*
     
    5050{
    5151  GTokenValue value;
    52   PSYMBOLINFO psi=(PSYMBOLINFO)gScanner->user_data;
    5352
    5453  /* Line number */
    5554  value=gScanner->value;
    56   psi->uiLineCorrection=value.v_int;
     55  parseInfo.uiLineCorrection=g_scanner_cur_line(gScanner)-value.v_int+1;
    5756
    5857  if(!matchNext(G_TOKEN_STRING))
     
    7069
    7170  /* Current source file */
    72   if(psi->chrCurrentSourceFile)
    73     g_free(psi->chrCurrentSourceFile);
     71  if(parseInfo.chrCurrentSourceFile)
     72    g_free(parseInfo.chrCurrentSourceFile);
    7473
    7574  value=gScanner->value;
    76   psi->chrCurrentSourceFile=g_strdup(value.v_string);
     75  parseInfo.chrCurrentSourceFile=g_strdup(value.v_string);
    7776
    7877  /* Trailing file include level info isn't used for now. Note that for the root
Note: See TracChangeset for help on using the changeset viewer.