2006-02-16 14:40 UTC+0100 Ryszard Glab <rglab//imid.med.pl>

* include/hbcomp.h
   * include/hbexpra.c
   * source/compiler/Makefile
   * source/compiler/expropta.c
   * source/compiler/genc.c
   * source/compiler/harbour.c
   * source/compiler/harbour.y
   * source/compiler/hbgenerr.c
      * all compiler structures are deallocated on exit now
This commit is contained in:
Ryszard Glab
2006-02-16 13:35:23 +00:00
parent 8cb8389d92
commit 2cd8284078
9 changed files with 244 additions and 112 deletions

View File

@@ -8,6 +8,18 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
* fixed <-x-> match marker
2006-02-17 10:10 UTC+0100 Ryszard Glab <rglab//imid.med.pl>
* include/hbcomp.h
* source/compiler/Makefile
* source/compiler/cmdcheck.c
* source/compiler/harbour.y
* source/compiler/hbident.c
* even more fixes to memory leaks in the compiler
(all compiler structures are deallocated on exit now, really :)
2006-02-16 14:40 UTC+0100 Ryszard Glab <rglab//imid.med.pl>
* include/hbcomp.h
* include/hbexpra.c

View File

@@ -302,6 +302,8 @@ int hb_compVariableScope( char * );
#define FUN_USES_LOCAL_PARAMS 16 /* parameters are declared using () */
#define FUN_WITH_RETURN 32 /* there was RETURN statement in previous line */
extern void hb_compMainExit( void ); /* main cleanup function */
extern void hb_compFunctionAdd( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ); /* starts a new Clipper language function definition */
extern PFUNCTION hb_compFunctionFind( char * szFunName ); /* locates a previously defined function */
extern PINLINE hb_compInlineFind( char * szFunName );
@@ -343,6 +345,10 @@ extern void hb_compExternAdd( char * szExternName ); /* defines a new extern nam
extern void hb_compAutoOpenAdd( char * szName );
extern void hb_compSwitchKill( void );
extern void hb_compLoopKill( void );
extern void hb_compRTVariableKill( void );
#ifdef HB_MACRO_SUPPORT
#define hb_compErrorType( p ) hb_macroError( EG_ARG, HB_MACRO_PARAM )

View File

@@ -740,7 +740,10 @@ HB_EXPR_PTR hb_compExprNewSend( HB_EXPR_PTR pObject, char * szMessage )
{
if( ! hb_compForEachVarError( pObject->value.asSymbol ) )
{
pExpr->value.asMessage.pObject = hb_compExprNewVarRef( pObject->value.asSymbol );
/* pExpr->value.asMessage.pObject = hb_compExprNewVarRef( pObject->value.asSymbol );*/
/* NOTE: direct type change */
pObject->ExprType = HB_ET_VARREF;
pExpr->value.asMessage.pObject = pObject;
}
}
}

View File

@@ -60,6 +60,8 @@ C_SOURCES=\
C_MAIN=harbour.c
LIBS=\
ccmalloc \
dl \
pp \
common \

View File

@@ -5,6 +5,6 @@
/* hbexpra.c is also included from ../macro/macro.c
* However it produces a slighty different code if used in
* macro compiler (there is an additional parameter passed to some functions)
* 1.19 - ignore this magic number - this is used to force compilation
* 1.20 - ignore this magic number - this is used to force compilation
*/
#include "hbexpra.c"

View File

@@ -54,8 +54,6 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou
char szModulname[ _POSIX_PATH_MAX + 1 ];
PFUNCTION pFunc = hb_comp_functions.pFirst;
PCOMSYMBOL pSym = hb_comp_symbols.pFirst;
PCOMDECLARED pDeclared;
PCOMCLASS pClass;
FILE * yyc; /* file handle for C output */
PINLINE pInline = hb_comp_inlines.pFirst;
@@ -300,63 +298,6 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou
fclose( yyc );
pFunc = hb_comp_functions.pFirst;
while( pFunc )
pFunc = hb_compFunctionKill( pFunc );
pFunc = hb_comp_funcalls.pFirst;
while( pFunc )
{
hb_comp_funcalls.pFirst = pFunc->pNext;
hb_xfree( ( void * ) pFunc ); /* NOTE: szName will be released by hb_compSymbolKill() */
pFunc = hb_comp_funcalls.pFirst;
}
pInline = hb_comp_inlines.pFirst;
while( pInline )
{
hb_comp_inlines.pFirst = pInline->pNext;
if( pInline->pCode )
{
hb_xfree( ( void * ) pInline->pCode );
}
hb_xfree( ( void * ) pInline->szFileName );
hb_xfree( ( void * ) pInline ); /* NOTE: szName will be released by hb_compSymbolKill() */
pInline = hb_comp_inlines.pFirst;
}
if ( hb_comp_iWarnings >= 3 )
{
pDeclared = hb_comp_pReleaseDeclared->pNext;
while( pDeclared )
{
hb_comp_pFirstDeclared = pDeclared->pNext;
hb_xfree( ( void * ) pDeclared );
pDeclared = hb_comp_pFirstDeclared;
}
pClass = hb_comp_pReleaseClass->pNext;
while( pClass )
{
hb_comp_pFirstClass = pClass->pNext;
pDeclared = pClass->pMethod;
while ( pDeclared )
{
hb_comp_pFirstDeclared = pDeclared->pNext;
hb_xfree( ( void * ) pDeclared );
pDeclared = hb_comp_pFirstDeclared;
}
hb_xfree( ( void * ) pClass );
pClass = hb_comp_pFirstClass;
}
}
pSym = hb_comp_symbols.pFirst;
while( pSym )
pSym = hb_compSymbolKill( pSym );
if( ! hb_comp_bQuiet )
printf( "Done.\n" );
}

View File

@@ -72,6 +72,8 @@ static void hb_compInitVars( void );
static void hb_compGenOutput( int );
static void hb_compOutputFile( void );
static void hb_compPpoFile( void );
static void hb_compCompileEnd( void );
int hb_compLocalGetPos( char * szVarName ); /* returns the order + 1 of a local variable */
int hb_compStaticGetPos( char *, PFUNCTION ); /* return if passed name is a static variable */
@@ -283,6 +285,23 @@ int main( int argc, char * argv[] )
}
}
if( (! bAnyFiles ) && (! hb_comp_bQuiet) )
{
hb_compPrintUsage( argv[ 0 ] );
iStatus = EXIT_FAILURE;
}
if( hb_comp_iErrorCount > 0 )
iStatus = EXIT_FAILURE;
hb_compMainExit();
return iStatus;
}
void hb_compMainExit( void )
{
hb_compCompileEnd();
hb_pp_Free();
hb_compIdentifierClose();
@@ -292,12 +311,6 @@ int main( int argc, char * argv[] )
hb_comp_pIncludePath = NULL;
}
if( (! bAnyFiles ) && (! hb_comp_bQuiet) )
{
hb_compPrintUsage( argv[ 0 ] );
iStatus = EXIT_FAILURE;
}
if( hb_comp_pOutPath )
{
hb_xfree( hb_comp_pOutPath );
@@ -312,12 +325,7 @@ int main( int argc, char * argv[] )
hb_compParserStop();
if( hb_comp_iErrorCount > 0 )
iStatus = EXIT_FAILURE;
hb_xexit();
return iStatus;
}
static int hb_compProcessRSPFile( char * szRspName, int argc, char * argv[] )
@@ -1240,7 +1248,12 @@ PCOMCLASS hb_compClassAdd( char * szClassName )
pDeclared = hb_compDeclaredAdd( szClassName );
pDeclared->cType = 'S';
pDeclared->pClass = pClass;
if( ! hb_comp_pReleaseClass )
{
hb_comp_pReleaseClass = pClass;
}
return pClass;
}
@@ -1744,11 +1757,11 @@ void hb_compDeclaredInit( void )
hb_comp_pFirstDeclared = &s_267; /* Change to BOTTOM Function. */
hb_comp_pLastDeclared = &s_001;
hb_comp_pReleaseDeclared = &s_001;
hb_comp_pReleaseDeclared = NULL;
hb_comp_pFirstClass = &s_TBROWSE;
hb_comp_pLastClass = &s_ERROR;
hb_comp_pReleaseClass = &s_ERROR;
hb_comp_pReleaseClass = NULL;
}
PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName )
@@ -1784,6 +1797,10 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName )
hb_comp_pLastDeclared->pNext = pDeclared;
hb_comp_pLastDeclared = pDeclared;
if( ! hb_comp_pReleaseDeclared )
{
hb_comp_pReleaseDeclared = pDeclared;
}
return pDeclared;
}
@@ -2070,6 +2087,7 @@ PFUNCTION hb_compFunctionKill( PFUNCTION pFunc )
{
PFUNCTION pNext = pFunc->pNext;
PVAR pVar;
HB_ENUMERATOR_PTR pEVar;
while( pFunc->pLocals )
{
@@ -2111,6 +2129,13 @@ PFUNCTION hb_compFunctionKill( PFUNCTION pFunc )
hb_xfree( ( void * ) pVar );
}
while( pFunc->pEnum )
{
pEVar = pFunc->pEnum;
pFunc->pEnum = pEVar->pNext;
hb_xfree( pEVar );
}
/* Release the NOOP array. */
if( pFunc->pNOOPs )
hb_xfree( ( void * ) pFunc->pNOOPs );
@@ -2123,6 +2148,9 @@ PFUNCTION hb_compFunctionKill( PFUNCTION pFunc )
/* hb_xfree( ( void * ) pFunc->szName ); The name will be released in hb_compSymbolKill() */
hb_xfree( ( void * ) pFunc );
hb_compLoopKill();
hb_compSwitchKill();
return pNext;
}
@@ -4826,20 +4854,6 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] )
yyparse();
/* Close processed file (it is opened in hb_compInclude() function ) */
/* fclose( yyin ); */
while( hb_comp_files.pLast )
{
PFILE pFile = hb_comp_files.pLast;
fclose( pFile->handle );
if( pFile->pBuffer )
hb_xfree( (void *) pFile->pBuffer );
hb_comp_files.pLast = pFile->pPrev;
hb_xfree( pFile );
}
hb_comp_files.pLast = NULL;
if( hb_comp_bPPO && hb_comp_yyppo )
{
fclose( hb_comp_yyppo );
@@ -4961,6 +4975,7 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] )
hb_compGenOutput( hb_comp_iLanguage );
}
hb_compCompileEnd();
hb_compParserStop();
}
else
@@ -4971,27 +4986,6 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] )
iStatus = EXIT_FAILURE;
}
{
PFILE pFile = hb_comp_files.pLast;
while( pFile )
{
fclose( pFile->handle );
pFile = ( PFILE ) pFile->pPrev;
}
}
/*
while( hb_comp_pExterns )
{
PEXTERN pExtern = hb_comp_pExterns;
hb_comp_pExterns = hb_comp_pExterns->pNext;
hb_xfree( pExtern->szName );
hb_xfree( pExtern );
}
*/
hb_comp_bExternal = FALSE;
}
}
@@ -5000,11 +4994,124 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] )
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_BADFILENAME, szPrg, NULL );
iStatus = EXIT_FAILURE;
}
hb_xfree( hb_comp_pFileName );
return iStatus;
}
static void hb_compCompileEnd( void )
{
hb_compRTVariableKill();
if( hb_comp_pFileName )
{
hb_xfree( hb_comp_pFileName );
hb_comp_pFileName = NULL;
}
while( hb_comp_files.pLast )
{
PFILE pFile = hb_comp_files.pLast;
fclose( pFile->handle );
if( pFile->pBuffer )
hb_xfree( (void *) pFile->pBuffer );
hb_comp_files.pLast = pFile->pPrev;
hb_xfree( pFile );
}
hb_comp_files.pLast = NULL;
if( hb_comp_functions.pFirst )
{
PFUNCTION pFunc = hb_comp_functions.pFirst;
while( pFunc )
pFunc = hb_compFunctionKill( pFunc );
hb_comp_functions.pFirst = NULL;
}
if( hb_comp_funcalls.pFirst )
{
PFUNCTION pFunc = hb_comp_funcalls.pFirst;
while( pFunc )
{
hb_comp_funcalls.pFirst = pFunc->pNext;
hb_xfree( ( void * ) pFunc ); /* NOTE: szName will be released by hb_compSymbolKill() */
pFunc = hb_comp_funcalls.pFirst;
}
hb_comp_funcalls.pFirst = NULL;
}
while( hb_comp_pExterns )
{
PEXTERN pExtern = hb_comp_pExterns;
hb_comp_pExterns = hb_comp_pExterns->pNext;
hb_xfree( pExtern );
}
if( hb_comp_inlines.pFirst )
{
PINLINE pInline = hb_comp_inlines.pFirst;
while( pInline )
{
hb_comp_inlines.pFirst = pInline->pNext;
if( pInline->pCode )
{
hb_xfree( ( void * ) pInline->pCode );
}
hb_xfree( ( void * ) pInline->szFileName );
hb_xfree( ( void * ) pInline ); /* NOTE: szName will be released by hb_compSymbolKill() */
pInline = hb_comp_inlines.pFirst;
}
hb_comp_inlines.pFirst = NULL;
}
if( hb_comp_pReleaseDeclared )
{
PCOMDECLARED pDeclared = hb_comp_pReleaseDeclared;
while( pDeclared )
{
hb_comp_pFirstDeclared = pDeclared->pNext;
hb_xfree( ( void * ) pDeclared );
pDeclared = hb_comp_pFirstDeclared;
}
hb_comp_pFirstDeclared = NULL;
}
if( hb_comp_pReleaseClass )
{
PCOMCLASS pClass = hb_comp_pReleaseClass;
PCOMDECLARED pDeclared;
while( pClass )
{
hb_comp_pFirstClass = pClass->pNext;
pDeclared = pClass->pMethod;
while ( pDeclared )
{
hb_comp_pFirstDeclared = pDeclared->pNext;
hb_xfree( ( void * ) pDeclared );
pDeclared = hb_comp_pFirstDeclared;
}
hb_xfree( ( void * ) pClass );
pClass = hb_comp_pFirstClass;
}
hb_comp_pReleaseClass = NULL;
}
if( hb_comp_symbols.pFirst )
{
PCOMSYMBOL pSym = hb_comp_symbols.pFirst;
while( pSym )
pSym = hb_compSymbolKill( pSym );
hb_comp_symbols.pFirst = NULL;
}
}
void hb_compAutoOpenAdd( char * szName )
{
HB_TRACE(HB_TR_DEBUG, ("hb_pp_compAutoOpenAdd(%s)", szName));

View File

@@ -2152,13 +2152,14 @@ static void hb_compLoopExit( void )
*/
static void hb_compLoopHere( void )
{
PTR_LOOPEXIT pLoop = hb_comp_pLoops, pFree;
PTR_LOOPEXIT pLoop = hb_comp_pLoops, pFree, pLast;
if( pLoop )
{
while( pLoop->pNext )
pLoop = pLoop->pNext;
pLast = pLoop;
pLoop = pLoop->pLoopList;
while( pLoop )
{
@@ -2167,6 +2168,7 @@ static void hb_compLoopHere( void )
pLoop = pLoop->pLoopList;
hb_xfree( ( void * ) pFree );
}
pLast->pLoopList = NULL;
}
}
@@ -2201,6 +2203,25 @@ static void hb_compLoopEnd( void )
}
}
void hb_compLoopKill( void )
{
PTR_LOOPEXIT pLoop;
PTR_LOOPEXIT pExit;
while( hb_comp_pLoops )
{
pLoop = hb_comp_pLoops;
while( pLoop->pExitList )
{
pExit = pLoop->pExitList;
pLoop->pExitList = pExit->pExitList;
hb_xfree( ( void * ) pExit );
}
hb_comp_pLoops = pLoop->pNext;
hb_xfree( ( void * ) pLoop );
}
}
static void * hb_compElseIfGen( void * pFirst, ULONG ulOffset )
{
PELSEIF pElseIf = ( PELSEIF ) hb_xgrab( sizeof( _ELSEIF ) ), pLast;
@@ -2296,6 +2317,21 @@ static void hb_compRTVariableGen( char * szCreateFun )
hb_comp_rtvars = NULL;
}
void hb_compRTVariableKill( void )
{
HB_RTVAR_PTR pVar;
while( hb_comp_rtvars )
{
pVar = hb_comp_rtvars;
hb_compExprDelete( pVar->pVar );
hb_comp_rtvars = pVar->pPrev;
hb_xfree( pVar );
}
hb_comp_rtvars = NULL;
}
static void hb_compVariableDim( char * szName, HB_EXPR_PTR pInitValue )
{
if( hb_comp_iVarScope == VS_PUBLIC || hb_comp_iVarScope == VS_PRIVATE )
@@ -2610,3 +2646,25 @@ static void hb_compSwitchEnd( void )
hb_comp_pSwitch = hb_comp_pSwitch->pPrev;
hb_xfree( pTmpSw );
}
/* Release all switch statements
*/
void hb_compSwitchKill( )
{
SWITCHCASE_PTR pCase;
SWITCHCMD_PTR pSwitch;
while( hb_comp_pSwitch )
{
while( hb_comp_pSwitch->pCases )
{
pCase = hb_comp_pSwitch->pCases;
hb_compExprDelete( pCase->pExpr );
hb_comp_pSwitch->pCases = pCase->pNext;
hb_xfree( (void *) pCase );
}
pSwitch = hb_comp_pSwitch;
hb_comp_pSwitch = pSwitch->pPrev;
hb_xfree( (void *) pSwitch );
}
}

View File

@@ -150,7 +150,10 @@ void hb_compGenError( char * szErrors[], char cPrefix, int iError, const char *
/* fatal error - exit immediately */
if( cPrefix == 'F' )
{
hb_compMainExit();
exit( EXIT_FAILURE );
}
}
void hb_compGenWarning( char * szWarnings[], char cPrefix, int iWarning, const char * szWarning1, const char * szWarning2)