From 6054f2132d0b2b8aa37c5e201c5472d382e438df Mon Sep 17 00:00:00 2001 From: Mindaugas Kavaliauskas Date: Thu, 22 Jan 2009 16:21:57 +0000 Subject: [PATCH] 2009-01-22 18:20 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * harbour/source/compiler/hbmain.c * harbour/source/pp/hbpp.c * harbour/source/pp/ppcore.c + added __FILE__ define for .prg code ; Please, look if this is implemented the right and optimal way. I'm a little confused about PP initialization order, and how __DATE__, etc, survive after hb_pp_reset in compiler. --- harbour/ChangeLog | 9 +++++++++ harbour/source/compiler/hbmain.c | 20 ++++++++++++++++++++ harbour/source/pp/hbpp.c | 1 + harbour/source/pp/ppcore.c | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ee88ebc719..90651272c3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,15 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-01-22 18:20 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * harbour/source/compiler/hbmain.c + * harbour/source/pp/hbpp.c + * harbour/source/pp/ppcore.c + + added __FILE__ define for .prg code + ; Please, look if this is implemented the right and optimal way. + I'm a little confused about PP initialization order, and how + __DATE__, etc, survive after hb_pp_reset in compiler. + 2009-01-22 10:15 UTC+0100 Lorenzo Fiorini (lorenzo.fiorini/at/gmail.com) * bin/hb-func.sh * fix darwin detection diff --git a/harbour/source/compiler/hbmain.c b/harbour/source/compiler/hbmain.c index a1ecda9147..13dad80d17 100644 --- a/harbour/source/compiler/hbmain.c +++ b/harbour/source/compiler/hbmain.c @@ -3921,6 +3921,26 @@ static int hb_compCompile( HB_COMP_DECL, const char * szPrg, int iFileType ) { BOOL bSkipGen = FALSE ; + /* Add __FILE__ define */ + hb_pp_delDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__" ); + if( iFileType == HB_COMP_SINGLEFILE ) + { + char* pBuf; + ULONG ulLen = strlen( szFileName ); + + pBuf = ( char* ) hb_xgrab( ulLen + 3 ); + pBuf[ 0 ] = '"'; + memcpy( pBuf + 1, szFileName, ulLen ); + pBuf[ ulLen + 1 ] = '"'; + pBuf[ ulLen + 2 ] = '\0'; + hb_pp_addDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__", pBuf ); + hb_xfree( pBuf ); + } + else + { + hb_pp_addDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__", "\"\"" ); + } + HB_COMP_PARAM->szFile = HB_COMP_PARAM->currModule = hb_compIdentifierNew( HB_COMP_PARAM, szFileName, HB_IDENT_COPY ); HB_COMP_PARAM->currLine = 1; diff --git a/harbour/source/pp/hbpp.c b/harbour/source/pp/hbpp.c index 08c1a317c4..f8c4185042 100644 --- a/harbour/source/pp/hbpp.c +++ b/harbour/source/pp/hbpp.c @@ -243,6 +243,7 @@ static void hb_pp_undefCompilerRules( PHB_PP_STATE pState ) const char * szRules[] = { "__HARBOUR__", "__DATE__", "__TIME__", + "__FILE__", "__HB_MAIN__", "__ARCH16BIT__", "__ARCH32BIT__", diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index ce5bc436f5..855e64af92 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -5296,6 +5296,28 @@ void hb_pp_initDynDefines( PHB_PP_STATE pState ) szResult[ 10 ] = '\0'; hb_pp_addDefine( pState, "__TIME__", szResult ); + /* __FILE__ */ + if( pState->pFile ) + { + char* pBuf; + ULONG ulLen = strlen( pState->pFile->szFileName ); + + pBuf = ( char* ) hb_xgrab( ulLen + 3 ); + pBuf[ 0 ] = '"'; + memcpy( pBuf + 1, pState->pFile->szFileName, ulLen ); + pBuf[ ulLen + 1 ] = '"'; + pBuf[ ulLen + 2 ] = '\0'; + hb_pp_addDefine( pState, "__FILE__", pBuf ); + hb_xfree( pBuf ); + } + else + { + szResult[ 0 ] = '"'; + szResult[ 1 ] = '"'; + szResult[ 2 ] = '\0'; + hb_pp_addDefine( pState, "__FILE__", szResult ); + } + hb_snprintf( szResult, sizeof( szResult ), "%d", ( int ) sizeof( void * ) ); #if defined( HB_ARCH_16BIT ) hb_pp_addDefine( pState, "__ARCH16BIT__", szResult );