Ignore:
Timestamp:
Sep 30, 2007, 8:45:15 PM (18 years ago)
Author:
cinc
Message:

Allow 'foo:override;' for method overriding

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

Legend:

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

    r290 r309  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
     34
     35/*
     36  Main file containing the interface parser. Whenever a valid keyword is found
     37  a specialized parser function in another source file is called from here.
     38 */
    3439#include <os2.h>
    3540#include <stdlib.h>
     
    113118/*
    114119  Function to parse the body of an interface declaration.
     120  Current token is '{'.
    115121
    116122  IB:= CV                                             // NOMCLASSVERSION()
     
    134140    else if(matchNext('#'))
    135141      parseHash();
     142    else if(matchNext(G_TOKEN_IDENTIFIER))
     143      {
     144        /* This may be an override statement */
     145        parseOverrideMethodFromIdentifier();
     146      }
    136147    else if(matchNext(G_TOKEN_SYMBOL))
    137148      {
     
    143154        switch(pCurSymbol->uiSymbolToken)
    144155          {
     156          case IDL_SYMBOL_OVERRIDE: /* This one is deprecated */
     157            parseOverrideMethod();
     158            break;
    145159          case IDL_SYMBOL_CLSVERSION:
    146160            parseClassVersion();
    147             break;
    148           case IDL_SYMBOL_OVERRIDE:
    149             parseOverrideMethod();
    150161            break;
    151162          case IDL_SYMBOL_INSTANCEVAR:
     
    159170            break;
    160171          default:
    161             g_scanner_unexp_token(gScanner,
    162                                   G_TOKEN_SYMBOL,
    163                                   NULL,
    164                                   NULL,
    165                                   NULL,
    166                                   "Trying to parse interface body.",
    167                                   TRUE); /* is_error */
    168             exit(1);
     172            {
     173              g_scanner_unexp_token(gScanner,
     174                                    G_TOKEN_SYMBOL,
     175                                    NULL,
     176                                    NULL,
     177                                    NULL,
     178                                    "Trying to parse interface body.",
     179                                    TRUE); /* is_error */
     180              exit(1);
     181            }
    169182          }/* switch */
    170183      }
  • trunk/idl-compiler/parser_c/override_parser.c

    r271 r309  
    3838
    3939#include <glib.h>
     40#include <glib/gprintf.h>
    4041#include "parser.h"
    4142
     
    6768
    6869/*
    69   Parse the class version. Note that the identifier is the current symbol..
     70  Parse override. Note that 'NOMOVERRIDE' is the current symbol..
    7071
    7172  OM:= IDL_SYMBOL_OVERRIDE '(' IDENT ')' ';'
     
    9091    }
    9192
     93  /* This is the method we actually try to override */
    9294  if(!matchNext(G_TOKEN_IDENTIFIER))
    9395    {
     
    98100                            NULL,
    99101                            NULL,
    100                             "Error in NOMOVERRIDE()",
     102                            "Error in NOMOVERRIDE(). Identifier expected.",
    101103                            TRUE); /* is_error */
    102104      exit(1);
     
    108110  if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pOMethod->chrName))==NULL)
    109111    {
    110 
    111       g_message("%s:%d: Method '%s' was not introduced by some parent interface.", gScanner->input_name,
    112                 g_scanner_cur_line(gScanner), pOMethod->chrName);
     112      g_printf("%s:%d: error: Method '%s' was not introduced by some parent interface.\n",
     113               pParseInfo->chrCurrentSourceFile, g_scanner_cur_line(gScanner)-pParseInfo->uiLineCorrection,
     114               pOMethod->chrName);
    113115      exit(1);
    114116    }
     
    124126                            NULL,
    125127                            NULL,
    126                             "Error in NOMOVERRIDE()",
     128                            "Error in NOMOVERRIDE(). Closing ')' is missing.",
    127129                            TRUE); /* is_error */
    128130      exit(1);
     
    136138                            NULL,
    137139                            NULL,
    138                             "Error in NOMOVERRIDE()",
     140                            "Error in NOMOVERRIDE(). Missing ';' at end of statement.",
    139141                            TRUE); /* is_error */
    140142      exit(1);
     
    142144  g_ptr_array_add(pParseInfo->pCurInterface->pOverrideArray, (gpointer) pOMethod);
    143145}
     146
     147
     148/*
     149  Parse override. Note that the identifier is the current symbol.
     150
     151  OM:= IDENT ':' IDL_SYMBOL_OVERRIDE2 ';'
     152 */
     153void parseOverrideMethodFromIdentifier(void)
     154{
     155  GTokenValue value;
     156  POVERMETHOD pOMethod=g_malloc0(sizeof(OVERMETHOD));
     157  PINTERFACE pif;
     158
     159  /* Keep the current identifier. We need to check for existance later if we find
     160     we are in an override statement. */
     161  value=gScanner->value;
     162  pOMethod->chrName=g_strdup(value.v_identifier);
     163
     164  if(!matchNext(':'))
     165    {
     166      getNextToken(); /* Make sure error references the correct token */
     167      g_scanner_unexp_token(gScanner,
     168                            ':',
     169                            NULL,
     170                            NULL,
     171                            NULL,
     172                            "",
     173                            TRUE); /* is_error */
     174      exit(1);
     175    }
     176
     177  /* Check for 'override' */
     178  if(!matchNext(G_TOKEN_SYMBOL))
     179    {
     180      getNextToken(); /* Make sure error references the correct token */
     181      g_scanner_unexp_token(gScanner,
     182                            G_TOKEN_SYMBOL,
     183                            NULL,
     184                            NULL,
     185                            NULL,
     186                            "'override' keyword expected.",
     187                            TRUE); /* is_error */
     188      exit(1);
     189    }
     190  else
     191    {
     192      /* Check if symbol is 'override' */
     193      PSYMBOL pCurSymbol;
     194
     195      value=gScanner->value;
     196      pCurSymbol=value.v_symbol;
     197
     198      if(pCurSymbol->uiSymbolToken != IDL_SYMBOL_OVERRIDE2)
     199        {
     200          g_scanner_unexp_token(gScanner,
     201                                G_TOKEN_SYMBOL,
     202                                NULL,
     203                                NULL,
     204                                NULL,
     205                                "'override' keyword expected after ':'.",
     206                                TRUE); /* is_error */
     207          exit(1);
     208        }
     209    }
     210 
     211  /* Now check if the method was introduced by some parent */
     212  if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pOMethod->chrName))==NULL)
     213    {
     214      g_printf("%s:%d: error: Method '%s' was not introduced by some parent interface.\n",
     215               pParseInfo->chrCurrentSourceFile, g_scanner_cur_line(gScanner)-pParseInfo->uiLineCorrection,
     216               pOMethod->chrName);
     217      exit(1);
     218    }
     219
     220
     221  pOMethod->chrIntroducingIFace=pif->chrName; /* No copy of string here. Nobody should free the
     222                                                 interface info under our feet. */
     223
     224  /* Check for trailing ';' */ 
     225  if(!matchNext(';'))
     226    {
     227      getNextToken(); /* Make sure error references the correct token */
     228      g_scanner_unexp_token(gScanner,
     229                            ';',
     230                            NULL,
     231                            NULL,
     232                            NULL,
     233                            "Error in override statement. Trailing ';' is missing.",
     234                            TRUE); /* is_error */
     235      exit(1);
     236    }
     237  g_ptr_array_add(pParseInfo->pCurInterface->pOverrideArray, (gpointer) pOMethod);
     238}
Note: See TracChangeset for help on using the changeset viewer.