Changeset 271 for trunk/idl-compiler


Ignore:
Timestamp:
Mar 25, 2007, 8:32:59 PM (18 years ago)
Author:
cinc
Message:

Code cleanups.

Location:
trunk/idl-compiler
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/Makefile

    r269 r271  
    1212
    1313PARSERDIR       =       ./parser_c
     14HEMITTERDIR     =       ./h-emitter_c
    1415
    1516CFLAGS          =       -Zmt -Zcrtdll -D__OS2__ -D__ST_MT_ERRNO__ -c -Wall
     
    3536                        $(OBJDIR)/lineinfo_parser.o \
    3637                        $(OBJDIR)/metaclass_parser.o \
     38                        $(OBJDIR)/h_file_emitter.o \
    3739                        $(OBJDIR)/printdata.o
    3840
     
    6668        $(CC) -I $(INC) $(CFLAGS)  -o$@ $<
    6769
     70$(OBJDIR)/%.o:  $(HEMITTERDIR)/%.c $(INCDIR)/parser.h
     71        $(CC) -I $(INC) $(CFLAGS)  -o$@ $<
    6872
    6973# Create the directories for temp files
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r269 r271  
    109109
    110110GScanner *gScanner;
    111 GTokenType curToken=G_TOKEN_EOF;
    112 PINTERFACE pCurInterface=NULL;
    113111
    114112/* Holding info about current token. Referenced by gScanner. */
    115 SYMBOLINFO curSymbol;
     113//SYMBOLINFO curSymbol;
    116114
    117115/* Holding the current state of parsing and pointers to necessary lists. */
    118116PARSEINFO parseInfo={0};
     117PPARSEINFO pParseInfo=&parseInfo;
    119118
    120119/**
     
    151150  value=gScanner->value;
    152151
    153   switch(curToken)
     152  switch(gScanner->token)
    154153    {
    155154    case G_TOKEN_IDENTIFIER:
     
    395394    GTokenType token;
    396395
    397     curToken=g_scanner_get_next_token(gScanner);
    398     token=curToken;
     396    g_scanner_get_next_token(gScanner);
     397    token=gScanner->token;
    399398    GTokenValue value=gScanner->value;
    400399   
    401     switch(curToken)
     400    switch(token)
    402401      {
    403402      case '#':
     
    465464#endif
    466465      default:
    467         printToken(curToken);
     466        printToken(token);
    468467        break;
    469468      }
     
    535534  /* Vars for filename building */
    536535  char* chrOutputFileName="";
     536  char* chrTemp;
    537537
    538538  GError *gError = NULL;
     
    557557    a++;
    558558
    559 #if 0
    560559  if(!a){
    561560    g_printf("An emitter must be specified.\n\n");
     
    566565    outputCompilerHelp(gContext, argv[0]);
    567566  }
    568 #endif
    569567
    570568  if(strlen(chrOutputName)==0)
     
    602600    chrOutputFileName=chrOutputName;
    603601
    604   //g_message("Output file: %s", chrOutputFileName);
     602  /* Add emitter extension */
     603  if(fOptionEmitH)
     604    chrTemp=g_strconcat(chrOutputFileName, ".h", NULL);
     605  else if(fOptionEmitIH)
     606    chrTemp=g_strconcat(chrOutputFileName, ".ih", NULL);
     607  else if(fOptionEmitC)
     608    chrTemp=g_strconcat(chrOutputFileName, ".c", NULL);
     609  g_free(chrOutputFileName);
     610  chrOutputFileName=chrTemp;
     611
     612  g_message("Output file: %s", chrOutputFileName);
    605613
    606614  /* Open input */
     
    622630
    623631  gScanner=g_scanner_new(NULL);
    624   gScanner->user_data=(gpointer)&curSymbol;
    625   curSymbol.pSymbols=idlSymbols;
     632  //gScanner->user_data=(gpointer)&curSymbol;
    626633
    627634  gScanner->msg_handler=funcMsgHandler;
     
    650657  parseIt();
    651658
     659  /* Write the output file */
     660  if(fOptionEmitH)
     661    emitHFile(pInterfaceArray);
     662
     663#if 0
     664  else if(fOptionEmitIH)
     665
     666  else if(fOptionEmitC)
     667    a++;
     668
    652669  if(pInterfaceArray->len)
    653670    printInterface();
     671#endif
    654672
    655673  g_scanner_destroy(gScanner);
  • trunk/idl-compiler/c/printdata.c

    r270 r271  
    144144      g_printf("\tMinor:\t\t%ld\n", pif->ulMinor);
    145145      g_printf("\tForward decl.:\t%s\n", (pif->fIsForwardDeclaration ? "Yes" : "No"));
    146       g_printf("\tMetaclass::\t%s\n", (pif->chrMetaClass ? pif->chrMetaClass : "None"));
     146      g_printf("\tMetaclass:\t%s\n", (pif->chrMetaClass ? pif->chrMetaClass : "None"));
     147      g_printf("\tSource file:\t%s\n", pif->chrSourceFileName);
    147148      /* Print instance vars */
    148149      g_printf("\tInstance vars:\t%d\n", pif->pInstanceVarArray->len);
  • trunk/idl-compiler/c/token.c

    r265 r271  
    4040
    4141extern GScanner *gScanner;
    42 extern GTokenType curToken;
     42extern PPARSEINFO pParseInfo;
    4343
    4444/*
     
    4848void setCurSymbolInfo(void)
    4949{
    50   PSYMBOLINFO psi;
    51 
    52   psi=(PSYMBOLINFO)gScanner->user_data;
    53 
    54   switch(curToken)
     50  switch(gScanner->token)
    5551    {
    5652    case G_TOKEN_IDENTIFIER:
     
    5854      break;
    5955    default:
    60       psi->uiCurSymbolKind=KIND_UNKNOWN;
    61       break;
    62     }
    63   if(curToken==G_TOKEN_SYMBOL)
     56      pParseInfo->uiCurSymbolKind=KIND_UNKNOWN;
     57      break;
     58    }
     59  if(gScanner->token==G_TOKEN_SYMBOL)
    6460    {
    6561      GTokenValue value;
     
    6965      pCurSymbol=value.v_symbol;
    7066
    71       psi->uiCurSymbolKind=pCurSymbol->uiKind;
     67      pParseInfo->uiCurSymbolKind=pCurSymbol->uiKind;
    7268    }
    7369}
     
    7571guint queryCurTokensKind(void)
    7672{
    77   PSYMBOLINFO psi;
    78 
    79   psi=(PSYMBOLINFO)gScanner->user_data;
    80   return psi->uiCurSymbolKind;
     73  return pParseInfo->uiCurSymbolKind;
    8174}
    8275
     
    121114void getNextToken(void)
    122115{
    123   curToken = g_scanner_get_next_token(gScanner);
     116  g_scanner_get_next_token(gScanner);
    124117  setCurSymbolInfo();
    125118}
     
    138131gboolean matchCur(GTokenType token)
    139132{
    140   if(token==curToken)
     133  if(token==gScanner->token)
    141134    {
    142135      return TRUE;
     
    190183          default:
    191184            {
    192               PSYMBOLINFO psi;
    193               psi=(PSYMBOLINFO)gScanner->user_data;         
    194            
    195185              g_message("Token: %d (%s)\t\t\t (LINE %d)", pCurSymbol->uiSymbolToken,
    196186                        pCurSymbol->chrSymbolName, g_scanner_cur_line(gScanner));
  • trunk/idl-compiler/include/parser.h

    r269 r271  
    8484  gulong ulMinor;    /* Class version            */
    8585  gboolean fIsForwardDeclaration;
     86  gboolean fIsInRootFile;
    8687  gchar* chrMetaClass; /* Pointer to metaclass name or NULL*/
     88  char*  chrSourceFileName; /* The preprocessor includes files for us. This is the info
     89                               about the file this interface is defined in. */
    8790  GPtrArray *pMethodArray;
    8891  GPtrArray *pOverrideArray;
     
    101104typedef struct
    102105{
    103   const SYMBOL    *pSymbols;     /* List of our introduced symbols */
    104   guint     uiCurSymbolKind;
    105   guint     uiLineCorrection;    /* This is the line number put by the preprocessor into
    106                                     the source file. It's used to calculate proper line numbers
    107                                     for errors. */
    108   char*     chrCurrentSourceFile;/* The preprocessor includes files for us. This is the info
    109                                     about their name. */
     106  guint     _uiCurSymbolKind;
    110107}SYMBOLINFO,*PSYMBOLINFO;
    111108
    112109typedef struct
    113110{
     111  PINTERFACE pCurInterface;      /* The interface we are currently parsing. This is a working pointer. */
     112  guint     uiCurSymbolKind;     /* This may be e.g. KIND_TYPESPEC */
    114113  GTree*    pSymbolTree;         /* Our introduced symbols */
    115114  guint     uiLineCorrection;    /* This is the line number put by the preprocessor into
    116115                                    the source file. It's used to calculate proper line numbers
    117116                                    for errors. */
     117  char*     chrRootSourceFile;   /* File we are intending to parse. Others may get included. */
    118118  char*     chrCurrentSourceFile;/* The preprocessor includes files for us. This is the info
    119119                                    about their name. */
     
    179179void parsePreprocLineInfo(void);
    180180void parseMetaClass(void);
     181
     182void emitHFile(GPtrArray* pInterfaceArray);
  • trunk/idl-compiler/parser_c/classversion_parser.c

    r267 r271  
    4040
    4141extern GScanner *gScanner;
    42 extern PINTERFACE pCurInterface;
     42extern PPARSEINFO pParseInfo;
     43
    4344/*
    4445  Parse the class version. Note that the identifier is the current symbol..
     
    7677    }
    7778  value=gScanner->value;
    78   pCurInterface->ulMajor=value.v_int;
     79  pParseInfo->pCurInterface->ulMajor=value.v_int;
    7980
    8081  if(!matchNext(','))
     
    103104    }
    104105  value=gScanner->value;
    105   pCurInterface->ulMinor=value.v_int;
     106  pParseInfo->pCurInterface->ulMinor=value.v_int;
    106107
    107108  if(!matchNext(')'))
  • trunk/idl-compiler/parser_c/instancevar_parser.c

    r267 r271  
    4040
    4141extern GScanner *gScanner;
    42 extern PINTERFACE pCurInterface;
     42extern PPARSEINFO pParseInfo;
    4343
    4444/*
     
    122122      exit(1);
    123123    }
    124   if(!pCurInterface)
     124  if(!pParseInfo->pCurInterface)
    125125    {
    126126      g_message("Error: no interface for some reason");
    127127    }
    128128
    129   g_ptr_array_add(pCurInterface->pInstanceVarArray , (gpointer) pInstanceVar);
     129  g_ptr_array_add(pParseInfo->pCurInterface->pInstanceVarArray , (gpointer) pInstanceVar);
    130130}
  • trunk/idl-compiler/parser_c/interface_parser.c

    r270 r271  
    4141
    4242extern GScanner *gScanner;
    43 extern GTokenType curToken;
    44 extern PINTERFACE pCurInterface;
    4543/* The pointer array holding the interfaces we found */
    4644extern GPtrArray* pInterfaceArray;
    47 extern PARSEINFO parseInfo;
     45extern PPARSEINFO pParseInfo;
    4846
    4947static void registerInterface(void)
     
    5149  PSYMBOL pNewSymbol=g_malloc0(sizeof(SYMBOL));
    5250
    53   g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);
     51  if(!strcmp(pParseInfo->chrRootSourceFile, pParseInfo->pCurInterface->chrSourceFileName))
     52    pParseInfo->pCurInterface->fIsInRootFile=TRUE;
     53
     54  g_ptr_array_add(pInterfaceArray, (gpointer) pParseInfo->pCurInterface);
    5455
    5556  /* Any found interface is registered as a new type so it can be
    5657     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. */
     58  pNewSymbol->chrSymbolName=g_strdup(pParseInfo->pCurInterface->chrName); /* We create a copy here because
     59                                                                             when cleaning up the symbol space
     60                                                                             the string will be freed. */
    6061  pNewSymbol->uiKind=KIND_TYPESPEC;
    6162  pNewSymbol->uiSymbolToken=IDL_SYMBOL_REGINTERFACE;
    62   g_tree_insert(parseInfo.pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName);
     63  g_tree_insert(pParseInfo->pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName);
    6364  g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pNewSymbol->chrSymbolName,
    6465                             pNewSymbol);
     
    6869  pNewSymbol->uiKind=KIND_TYPESPEC;
    6970  pNewSymbol->uiSymbolToken=IDL_SYMBOL_REGINTERFACE;
    70   pNewSymbol->chrSymbolName=g_strconcat("P", pCurInterface->chrName, NULL);
    71   g_message("%s: %s", __FUNCTION__, pNewSymbol->chrSymbolName);
    72   g_tree_insert(parseInfo.pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName);
     71  pNewSymbol->chrSymbolName=g_strconcat("P", pParseInfo->pCurInterface->chrName, NULL);
     72  g_tree_insert(pParseInfo->pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName);
    7373  g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pNewSymbol->chrSymbolName,
    7474                             pNewSymbol);
     75  //g_message("%s: %s", __FUNCTION__, pNewSymbol->chrSymbolName);
    7576}
    7677
     
    179180  /* Save interface info */
    180181  GTokenValue value=gScanner->value;
    181   pCurInterface->chrName=g_strdup(value.v_identifier);
     182  pParseInfo->pCurInterface->chrName=g_strdup(value.v_identifier);
    182183}
    183184
     
    247248      exit(1);
    248249    }
    249   pCurInterface->chrParent=g_strdup(pCurSymbol->chrSymbolName);
     250  pParseInfo->pCurInterface->chrParent=g_strdup(pCurSymbol->chrSymbolName);
    250251
    251252  /* Check if the parent interface is known. */
    252   if(!findInterfaceFromName(pCurInterface->chrParent))
     253  if(!findInterfaceFromName(pParseInfo->pCurInterface->chrParent))
    253254  {
    254255    g_scanner_unexp_token(gScanner,
     
    295296void parseInterface(GTokenType token)
    296297{
    297   pCurInterface=createInterfaceStruct();
     298  pParseInfo->pCurInterface=createInterfaceStruct();
    298299
    299300  /* Get the interface name */
    300301  parseIFace(token);
     302  pParseInfo->pCurInterface->chrSourceFileName=g_strdup(pParseInfo->chrCurrentSourceFile);
     303
    301304  /* It's save to register the interface right here even if the struct is almost empty.
    302305     If anything goes wrong later we will exit anyway. */
     
    305308  if(matchNext(';'))
    306309    {
    307       pCurInterface->fIsForwardDeclaration=TRUE;
     310      pParseInfo->pCurInterface->fIsForwardDeclaration=TRUE;
    308311    }
    309312  else if(matchNext(':'))
  • trunk/idl-compiler/parser_c/lineinfo_parser.c

    r267 r271  
    4141
    4242extern GScanner *gScanner;
    43 extern PARSEINFO parseInfo;
     43extern PPARSEINFO pParseInfo;
    4444
    4545/*
     
    5454  /* Line number */
    5555  value=gScanner->value;
    56   parseInfo.uiLineCorrection=g_scanner_cur_line(gScanner)-value.v_int+1;
     56  pParseInfo->uiLineCorrection=g_scanner_cur_line(gScanner)-value.v_int+1;
    5757
    5858  if(!matchNext(G_TOKEN_STRING))
     
    6969    }
    7070
     71  value=gScanner->value;
     72
     73  /* Root source file? */
     74  if(!pParseInfo->chrRootSourceFile)
     75    pParseInfo->chrRootSourceFile=g_strdup(value.v_string);
     76
    7177  /* Current source file */
    72   if(parseInfo.chrCurrentSourceFile)
    73     g_free(parseInfo.chrCurrentSourceFile);
     78  if(pParseInfo->chrCurrentSourceFile)
     79    g_free(pParseInfo->chrCurrentSourceFile);
    7480
    75   value=gScanner->value;
    76   parseInfo.chrCurrentSourceFile=g_strdup(value.v_string);
     81  pParseInfo->chrCurrentSourceFile=g_strdup(value.v_string);
    7782
    7883  /* Trailing file include level info isn't used for now. Note that for the root
  • trunk/idl-compiler/parser_c/method_parser.c

    r269 r271  
    4141extern GScanner *gScanner;
    4242extern GTokenType curToken;
    43 extern PINTERFACE pCurInterface;
     43extern PPARSEINFO pParseInfo;
    4444
    4545/* In override_parser.c */
     
    180180  pMethod->chrName=g_strdup(value.v_identifier);
    181181
    182   /* Now check if the method was introduced by some parent */
    183   if((pif=findInterfaceForMethod(pCurInterface, pMethod->chrName))!=NULL)
     182  /* Now check if the method was introduced by some parent. The interface struct contains
     183     the parent name if any and the function will follow the chain of parents. */
     184  if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pMethod->chrName))!=NULL)
    184185    {
    185186      gchar* chrMessage;
     
    226227          exit(1);
    227228        }
    228       g_ptr_array_add( pCurInterface->pMethodArray, (gpointer) pMethod);
     229      g_ptr_array_add( pParseInfo->pCurInterface->pMethodArray, (gpointer) pMethod);
    229230      return;
    230231    }
     
    259260    }
    260261
    261   g_ptr_array_add( pCurInterface->pMethodArray, (gpointer) pMethod);
     262  g_ptr_array_add( pParseInfo->pCurInterface->pMethodArray, (gpointer) pMethod);
    262263}
  • trunk/idl-compiler/parser_c/override_parser.c

    r267 r271  
    4242
    4343extern GScanner *gScanner;
    44 extern PINTERFACE pCurInterface;
     44//extern PINTERFACE pCurInterface;
     45extern PPARSEINFO pParseInfo;
    4546
    4647PINTERFACE findInterfaceForMethod(PINTERFACE pStartInterface, gchar* chrMethodName)
     
    105106
    106107  /* Now check if the method was introduced by some parent */
    107   if((pif=findInterfaceForMethod(pCurInterface, pOMethod->chrName))==NULL)
     108  if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pOMethod->chrName))==NULL)
    108109    {
    109110
     
    139140      exit(1);
    140141    }
    141   g_ptr_array_add(pCurInterface->pOverrideArray, (gpointer) pOMethod);
     142  g_ptr_array_add(pParseInfo->pCurInterface->pOverrideArray, (gpointer) pOMethod);
    142143}
Note: See TracChangeset for help on using the changeset viewer.