2011-10-20 20:19 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbpp.h
  * harbour/include/hbcomp.h
  * harbour/include/hbcompdf.h
  * harbour/src/compiler/hbmain.c
  * harbour/src/compiler/hbcomp.c
  * harbour/src/compiler/hbgenerr.c
    + added support for redirecting compiler warning and error messages
      to user function.

  * harbour/src/compiler/hbcmplib.c
    + optional support for generating RTE in HB_COMPILE*() functions
      on compile errors.
This commit is contained in:
Przemyslaw Czerpak
2011-10-20 18:19:19 +00:00
parent f34b6c4190
commit 049e9da26f
8 changed files with 143 additions and 69 deletions

View File

@@ -16,6 +16,20 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-10-20 20:19 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbpp.h
* harbour/include/hbcomp.h
* harbour/include/hbcompdf.h
* harbour/src/compiler/hbmain.c
* harbour/src/compiler/hbcomp.c
* harbour/src/compiler/hbgenerr.c
+ added support for redirecting compiler warning and error messages
to user function.
* harbour/src/compiler/hbcmplib.c
+ optional support for generating RTE in HB_COMPILE*() functions
on compile errors.
2011-10-20 15:21 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbpgsql/hbpgsql.hbx
* contrib/hbpgsql/hbpgsql.hbp

View File

@@ -266,7 +266,7 @@ extern HB_BOOL hb_compCheckUnclosedStru( HB_COMP_DECL, PFUNCTION );
#define HB_GEN_FUNC4( func, p1,p2,p3,p4 ) hb_compGen##func( p1, p2, p3, p4, HB_COMP_PARAM )
extern int hb_compMain( int argc, const char * const argv[] );
extern int hb_compMainExt( int argc, const char * const argv[], HB_BYTE ** pBufPtr, HB_SIZE * pnSize, const char * szSource, void * cargo, PHB_PP_OPEN_FUNC pOpenFunc );
extern int hb_compMainExt( int argc, const char * const argv[], HB_BYTE ** pBufPtr, HB_SIZE * pnSize, const char * szSource, void * cargo, PHB_PP_OPEN_FUNC pOpenFunc, PHB_PP_MSG_FUNC pMsgFunc );
extern void hb_compOutStd( HB_COMP_DECL, const char * szMessage );
extern void hb_compOutErr( HB_COMP_DECL, const char * szMessage );

View File

@@ -775,6 +775,7 @@ typedef struct _HB_COMP
void ( * outStdFunc ) ( void *, const char* );
void ( * outErrFunc ) ( void *, const char* );
PHB_PP_MSG_FUNC outMsgFunc;
void * cargo;
HB_SIZE nOutBufSize; /* memory output buffer size */

View File

@@ -120,6 +120,10 @@ typedef HB_PP_SWITCH_FUNC_( ( * PHB_PP_SWITCH_FUNC ) );
#define HB_PP_INC_FUNC_( func ) void func( void *, const char * )
typedef HB_PP_INC_FUNC_( ( * PHB_PP_INC_FUNC ) );
/* function to generate errors */
#define HB_PP_MSG_FUNC_( func ) void func( void * cargo, int iErrorFmt, int iLine, const char * szModule, char cPrefix, int iValue, const char * szText, const char * szPar1, const char * szPar2 )
typedef HB_PP_MSG_FUNC_( ( * PHB_PP_MSG_FUNC ) );
/* preprocessor tokens */
#define HB_PP_TOKEN_NUL 0

View File

@@ -53,6 +53,34 @@
#include "hbapi.h"
#include "hbcomp.h"
static void s_pp_msg( void * cargo, int iErrorFmt, int iLine,
const char * szModule, char cPrefix, int iValue,
const char * szText,
const char * szPar1, const char * szPar2 )
{
HB_SYMBOL_UNUSED( cargo );
/* ignore all warning messages and errors when break or quit request */
if( cPrefix != 'W' && hb_vmRequestQuery() == 0 )
{
char szMsgBuf[ 512 ], szLine[ 512 ];
PHB_ITEM pError;
hb_snprintf( szMsgBuf, sizeof( szMsgBuf ), szText, szPar1, szPar2 );
if( !szModule || *szModule == 0 || strcmp( szModule, "{SOURCE}" ) == 0 )
hb_snprintf( szLine, sizeof( szLine ),
"line:%i", iLine );
else
hb_snprintf( szLine, sizeof( szLine ),
iErrorFmt == HB_ERRORFMT_CLIPPER ? "%s(%i)" : "%s:%i",
szModule, iLine );
pError = hb_errRT_New( ES_ERROR, "COMPILER", 1001, ( HB_ERRCODE ) iValue, szMsgBuf,
szLine, 0 /*OsCode*/, EF_NONE | EF_CANDEFAULT );
hb_errLaunch( pError );
hb_errRelease( pError );
}
}
static int s_pp_openFile( void * cargo, char * szFileName,
HB_BOOL fBefore, HB_BOOL fSysFile, HB_BOOL fBinary,
HB_PATHNAMES * pIncludePaths,
@@ -97,13 +125,25 @@ static int s_pp_openFile( void * cargo, char * szFileName,
static void hb_compGenArgList( int iFirst, int iLast,
int * pArgC, const char *** pArgV,
PHB_ITEM * pIncItem,
PHB_PP_OPEN_FUNC * pOpenFunc )
PHB_PP_OPEN_FUNC * pOpenFunc,
PHB_PP_MSG_FUNC * pMsgFunc )
{
PHB_ITEM pParam;
HB_SIZE ul, nLen;
int argc = 1, i;
const char ** argv;
if( pMsgFunc )
{
* pMsgFunc = NULL;
if( HB_ISLOG( iFirst ) )
{
if( hb_parl( iFirst ) )
* pMsgFunc = s_pp_msg;
++iFirst;
}
}
if( pIncItem && pOpenFunc )
{
*pOpenFunc = NULL;
@@ -167,10 +207,10 @@ HB_FUNC( HB_COMPILE )
const char ** argv;
PHB_ITEM pIncItem;
PHB_PP_OPEN_FUNC pOpenFunc;
PHB_PP_MSG_FUNC pMsgFunc;
hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc );
hb_retni( hb_compMainExt( argc, argv, NULL, NULL, NULL, pIncItem, pOpenFunc ) );
hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc );
hb_retni( hb_compMainExt( argc, argv, NULL, NULL, NULL, pIncItem, pOpenFunc, pMsgFunc ) );
hb_xfree( argv );
}
@@ -180,12 +220,14 @@ HB_FUNC( HB_COMPILEBUF )
const char ** argv;
PHB_ITEM pIncItem;
PHB_PP_OPEN_FUNC pOpenFunc;
PHB_PP_MSG_FUNC pMsgFunc;
HB_BYTE * pBuffer;
HB_SIZE nLen;
hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc );
iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, NULL, pIncItem, pOpenFunc );
hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc );
iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, NULL, pIncItem, pOpenFunc, pMsgFunc );
hb_xfree( argv );
if( iResult == EXIT_SUCCESS && pBuffer )
hb_retclen_buffer( ( char * ) pBuffer, nLen );
}
@@ -197,15 +239,17 @@ HB_FUNC( HB_COMPILEFROMBUF )
const char * szSource;
PHB_ITEM pIncItem;
PHB_PP_OPEN_FUNC pOpenFunc;
PHB_PP_MSG_FUNC pMsgFunc;
HB_BYTE * pBuffer;
HB_SIZE nLen;
szSource = hb_parc( 1 );
if( szSource )
{
hb_compGenArgList( 2, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc );
iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, szSource, pIncItem, pOpenFunc );
hb_compGenArgList( 2, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc );
iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, szSource, pIncItem, pOpenFunc, pMsgFunc );
hb_xfree( argv );
if( iResult == EXIT_SUCCESS && pBuffer )
hb_retclen_buffer( ( char * ) pBuffer, nLen );
}

View File

@@ -165,6 +165,67 @@ static void hb_compErrorDuplVar( HB_COMP_DECL, const char * szVarName )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_VAR_DUPL, szVarName, NULL );
}
static void hb_compOutMsg( void * cargo, int iErrorFmt, int iLine,
const char * szModule, char cPrefix, int iValue,
const char * szText,
const char * szPar1, const char * szPar2 )
{
char buffer[ 512 ];
if( szModule )
{
if( iErrorFmt == HB_ERRORFMT_CLIPPER )
hb_snprintf( buffer, sizeof( buffer ), "\r%s(%i) ", szModule, iLine );
else if( iLine )
hb_snprintf( buffer, sizeof( buffer ), "\n%s:%i: ", szModule, iLine );
else
hb_snprintf( buffer, sizeof( buffer ), "\n%s:%s ", szModule, szPar2 );
hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer );
}
if( iErrorFmt == HB_ERRORFMT_CLIPPER )
hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ",
cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue );
else
hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ",
cPrefix == 'W' ? "warning" : "error", cPrefix, iValue );
hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer );
hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 );
hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer );
hb_compOutErr( ( HB_COMP_PTR ) cargo, "\n" );
}
void hb_compOutStd( HB_COMP_DECL, const char * szMessage )
{
if( ! HB_COMP_PARAM->fFullQuiet )
{
if( HB_COMP_PARAM->outStdFunc )
HB_COMP_PARAM->outStdFunc( HB_COMP_PARAM, szMessage );
else
#if defined( HB_OS_DOS )
fprintf( stderr, "%s", szMessage ); fflush( stderr );
#else
fprintf( stdout, "%s", szMessage ); fflush( stdout );
#endif
}
}
void hb_compOutErr( HB_COMP_DECL, const char * szMessage )
{
if( ! HB_COMP_PARAM->fFullQuiet )
{
if( HB_COMP_PARAM->outErrFunc )
HB_COMP_PARAM->outErrFunc( HB_COMP_PARAM, szMessage );
else
#if defined( HB_OS_DOS )
fprintf( stdout, "%s", szMessage ); fflush( stdout );
#else
fprintf( stderr, "%s", szMessage ); fflush( stderr );
#endif
}
}
static const HB_COMP_FUNCS s_comp_funcs =
{
hb_compExprNew,
@@ -227,6 +288,8 @@ HB_COMP_PTR hb_comp_new( void )
pComp->iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */
pComp->iLanguage = HB_LANG_C; /* default Harbour generated output language */
pComp->iErrorFmt = HB_ERRORFMT_CLIPPER; /* default Harbour generated output language */
pComp->outMsgFunc = hb_compOutMsg;
}
return pComp;
@@ -299,33 +362,3 @@ void hb_comp_free( HB_COMP_PTR pComp )
hb_xfree( pComp );
}
void hb_compOutStd( HB_COMP_DECL, const char * szMessage )
{
if( ! HB_COMP_PARAM->fFullQuiet )
{
if( HB_COMP_PARAM->outStdFunc )
HB_COMP_PARAM->outStdFunc( HB_COMP_PARAM->cargo, szMessage );
else
#if defined( HB_OS_DOS )
fprintf( stderr, "%s", szMessage ); fflush( stderr );
#else
fprintf( stdout, "%s", szMessage ); fflush( stdout );
#endif
}
}
void hb_compOutErr( HB_COMP_DECL, const char * szMessage )
{
if( ! HB_COMP_PARAM->fFullQuiet )
{
if( HB_COMP_PARAM->outErrFunc )
HB_COMP_PARAM->outErrFunc( HB_COMP_PARAM->cargo, szMessage );
else
#if defined( HB_OS_DOS )
fprintf( stdout, "%s", szMessage ); fflush( stdout );
#else
fprintf( stderr, "%s", szMessage ); fflush( stderr );
#endif
}
}

View File

@@ -153,34 +153,9 @@ static void hb_compDispMessage( HB_COMP_DECL, char cPrefix, int iValue,
const char * szText,
const char * szPar1, const char * szPar2 )
{
char buffer[ 512 ];
if( HB_COMP_PARAM->currModule )
{
if( HB_COMP_PARAM->iErrorFmt == HB_ERRORFMT_CLIPPER )
hb_snprintf( buffer, sizeof( buffer ), "\r%s(%i) ",
HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine );
else if( HB_COMP_PARAM->currLine )
hb_snprintf( buffer, sizeof( buffer ), "\n%s:%i: ",
HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine );
else
hb_snprintf( buffer, sizeof( buffer ), "\n%s:%s ",
HB_COMP_PARAM->currModule, szPar2 );
hb_compOutErr( HB_COMP_PARAM, buffer );
}
if( HB_COMP_PARAM->iErrorFmt == HB_ERRORFMT_CLIPPER )
hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ",
cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue );
else
hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ",
cPrefix == 'W' ? "warning" : "error", cPrefix, iValue );
hb_compOutErr( HB_COMP_PARAM, buffer );
hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 );
hb_compOutErr( HB_COMP_PARAM, buffer );
hb_compOutErr( HB_COMP_PARAM, "\n" );
HB_COMP_PARAM->outMsgFunc( HB_COMP_PARAM, HB_COMP_PARAM->iErrorFmt,
HB_COMP_PARAM->currLine, HB_COMP_PARAM->currModule,
cPrefix, iValue, szText, szPar1, szPar2 );
}
void hb_compGenError( HB_COMP_DECL, const char * const szErrors[],

View File

@@ -62,7 +62,8 @@ static HB_BOOL hb_compRegisterFunc( HB_COMP_DECL, PFUNCTION pFunc, HB_BOOL fErro
int hb_compMainExt( int argc, const char * const argv[],
HB_BYTE ** pBufPtr, HB_SIZE * pnSize,
const char * szSource,
void * cargo, PHB_PP_OPEN_FUNC pOpenFunc )
void * cargo, PHB_PP_OPEN_FUNC pOpenFunc,
PHB_PP_MSG_FUNC pMsgFunc )
{
HB_COMP_DECL;
int iStatus = EXIT_SUCCESS;
@@ -79,6 +80,8 @@ int hb_compMainExt( int argc, const char * const argv[],
HB_COMP_PARAM = hb_comp_new();
HB_COMP_PARAM->cargo = cargo;
if( pMsgFunc )
HB_COMP_PARAM->outMsgFunc = pMsgFunc;
HB_COMP_PARAM->pOutPath = NULL;
@@ -180,7 +183,7 @@ int hb_compMainExt( int argc, const char * const argv[],
int hb_compMain( int argc, const char * const argv[] )
{
return hb_compMainExt( argc, argv, NULL, NULL, NULL, NULL, NULL );
return hb_compMainExt( argc, argv, NULL, NULL, NULL, NULL, NULL, NULL );
}
static int hb_compReadClpFile( HB_COMP_DECL, const char * szClpFile )