diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f2058b46b1..dffc92469b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,17 @@ +2001-01-13 02:25 UTC-0800 Ron Pinkas + * source/compiler/genc.c + * source/compiler/harbour.c + * source/pp/pragma.c + + Added support for #pragma BEGINDUMP ... [#pragma STOPDUMP] or EOF. + /* BEGINDUMP & STOPDUMP are just a suggestion. */ + + * utils/hbpp/hbpp.c + * source/pp/pplib.c + + Added empty stub hb_compInlineAdd() (needed by pragma.c) + + * tests/inline_c.prg + + Added code to demonstrate #pragam BEGINDUMP + 2001-01-11 20:10 UTC-0800 Ron Pinkas * source/compiler/harbour.l * source/compiler/harbour.slx diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index 1e975f0b8d..ae13cf80a1 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -103,7 +103,8 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou /* write functions prototypes for inline blocks */ while( pInline ) { - fprintf( yyc, "static HB_FUNC( %s );\n", pInline->szName ); + if( pInline->szName ) + fprintf( yyc, "static HB_FUNC( %s );\n", pInline->szName ); pInline = pInline->pNext; } @@ -231,21 +232,28 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou /* Generate codeblocks data */ - if( hb_comp_inlines.iCount ) + if( hb_comp_cInlineID ) { fprintf( yyc, "#include \"hbapi.h\"\n" ); - pInline = hb_comp_inlines.pFirst; - while( pInline ) + } + + pInline = hb_comp_inlines.pFirst; + while( pInline ) + { + fprintf( yyc, "#line %i \"%s\"\n", pInline->iLine, pInline->szFileName ); + + if( pInline->szName ) { - fprintf( yyc, "#line %i \"%s\"\n", pInline->iLine, pInline->szFileName ); fprintf( yyc, "static HB_FUNC( %s )\n", pInline->szName ); - fprintf( yyc, "%s", pInline->pCode ); - pInline = pInline->pNext; } + fprintf( yyc, "%s", pInline->pCode ); + pInline = pInline->pNext; } } else + { fprintf( yyc, "/* Empty source file */\n\n" ); + } fclose( yyc ); @@ -265,7 +273,10 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou while( pInline ) { hb_comp_inlines.pFirst = pInline->pNext; - hb_xfree( ( void * ) pInline->pCode ); + 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; diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 92b1c8adbc..58cd73dcda 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -1084,16 +1084,18 @@ PINLINE hb_compInlineAdd( char * szFunName ) PINLINE pInline; PCOMSYMBOL pSym; - pSym = hb_compSymbolFind( szFunName, NULL ); - if( ! pSym ) + if( szFunName ) { - pSym = hb_compSymbolAdd( szFunName, NULL ); + pSym = hb_compSymbolFind( szFunName, NULL ); + if( ! pSym ) + { + pSym = hb_compSymbolAdd( szFunName, NULL ); + } + if( pSym ) + { + pSym->cScope |= HB_FS_STATIC; + } } - if( pSym ) - { - pSym->cScope |= HB_FS_STATIC; - } - pInline = hb_compInlineNew( szFunName ); if( hb_comp_inlines.iCount == 0 ) @@ -1304,7 +1306,7 @@ PINLINE hb_compInlineFind( char * szFunctionName ) while( pInline ) { - if( ! strcmp( pInline->szName, szFunctionName ) ) + if( pInline->szName && strcmp( pInline->szName, szFunctionName ) == 0 ) return pInline; else { diff --git a/harbour/source/pp/pplib.c b/harbour/source/pp/pplib.c index 8996806ff7..f0f3aff23d 100644 --- a/harbour/source/pp/pplib.c +++ b/harbour/source/pp/pplib.c @@ -61,14 +61,17 @@ int hb_comp_iLine; /* currently parsed file line number */ BOOL hb_comp_bPPO = FALSE; /* flag indicating, is ppo output needed */ BOOL hb_comp_bStartProc = TRUE; /* holds if we need to create the starting procedure */ BOOL hb_comp_bLineNumbers = TRUE; /* holds if we need pcodes with line numbers */ + #if 0 BOOL hb_comp_bShortCuts = TRUE; /* .and. & .or. expressions shortcuts */ #endif + int hb_comp_iWarnings = 0; /* enable parse warnings */ BOOL hb_comp_bAutoMemvarAssume = FALSE; /* holds if undeclared variables are automatically assumed MEMVAR (-a)*/ BOOL hb_comp_bForceMemvars = FALSE; /* holds if memvars are assumed when accesing undeclared variable (-v)*/ BOOL hb_comp_bDebugInfo = FALSE; /* holds if generate debugger required info */ int hb_comp_iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */ +FILE *hb_comp_yyppo = NULL; static jmp_buf s_env; @@ -154,5 +157,11 @@ void hb_compGenWarning( char * szWarnings[], char cPrefix, int iWarning, const c HB_SYMBOL_UNUSED( szWarning2 ); } +PINLINE hb_compInlineAdd( char * szFunName ) +{ + HB_SYMBOL_UNUSED( szFunName ); + return NULL; +} + #endif diff --git a/harbour/source/pp/pragma.c b/harbour/source/pp/pragma.c index 6910434384..1f7a9827fe 100644 --- a/harbour/source/pp/pragma.c +++ b/harbour/source/pp/pragma.c @@ -169,6 +169,70 @@ void hb_pp_ParsePragma( char * szLine ) hb_comp_bAutoMemvarAssume = StringToBool( szLine, hb_comp_bAutoMemvarAssume ); DebugPragma( szLine, -1, hb_comp_bAutoMemvarAssume ); } + else if( memcmp( szLine, "BEGINDUMP", PRAGMAS_LEN ) == 0 ) + { + char sBuffer[ HB_PP_STR_SIZE ], *pBuffer, sDirective[9] ; + int iSize; + extern BOOL hb_pp_bInline; + PINLINE pInline; + + hb_pp_bInline = TRUE; + + pInline = hb_compInlineAdd( NULL ); + + DigestInline : + + iSize = hb_pp_Internal( hb_comp_bPPO ? hb_comp_yyppo : NULL, sBuffer ); + if( iSize == 0 ) + { + hb_pp_bInline = FALSE; + return; + } + + pBuffer = (char*) sBuffer; + + while( *pBuffer == ' ' || *pBuffer == '\t' ) + { + pBuffer++; + } + if( *pBuffer == '#' ) + { + pBuffer++; + while( *pBuffer == ' ' || *pBuffer == '\t' ) + { + pBuffer++; + } + hb_strupr( strncpy( sDirective, pBuffer, 6 ) ); + if( memcmp( sDirective, "PRAGMA", 6 ) == 0 ) + { + pBuffer += 6; + } + while( *pBuffer == ' ' || *pBuffer == '\t' ) + { + pBuffer++; + } + hb_strupr( strncpy( sDirective, pBuffer, 8 ) ); + if( memcmp( sDirective, "STOPDUMP", 8 ) == 0 ) + { + hb_pp_bInline = FALSE; + return; + } + } + + if( pInline->pCode == NULL ) + { + pInline->pCode = hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 ); + strcpy( pInline->pCode, (char*) sBuffer ); + } + else + { + pInline->pCode = hb_xrealloc( pInline->pCode, pInline->lPCodeSize + ( iSize = strlen( (char*) sBuffer ) ) + 1 ); + strcpy( pInline->pCode + pInline->lPCodeSize, (char*) sBuffer ); + } + pInline->lPCodeSize += iSize; + + goto DigestInline; + } else if( memcmp( szLine, "DEBUGINFO", PRAGMAS_LEN ) == 0 ) { hb_comp_bDebugInfo = StringToBool( szLine, hb_comp_bDebugInfo ); diff --git a/harbour/tests/inline_c.prg b/harbour/tests/inline_c.prg index c63d1f3cbb..89bbb0646d 100644 --- a/harbour/tests/inline_c.prg +++ b/harbour/tests/inline_c.prg @@ -15,7 +15,11 @@ PROCEDURE MAIN( cLine, cDelim ) NEXT i QOut( HB_INLINE() ) - { hb_retc( "\na C String, including { and \" \n" ); } + { hb_retc( "\na C String, including { and \" { \n" ); } + + QOut( C_Func() ) + + QOut( PostDumpTest() ) RETURN @@ -75,3 +79,13 @@ FUNCTION aTokens( cLine, cDelimiter ) #endif RETURN aTokens + +#pragma BEGINDUMP +HB_FUNC( C_FUNC ) +{ + hb_retc( "returned from C_FUN\n" ); +} +#pragma STOPDUMP + +Function PostDumpTest() +RETURN "Post Dump Test" diff --git a/harbour/utils/hbpp/hbpp.c b/harbour/utils/hbpp/hbpp.c index d3f7ccfc4c..fc03a24dd6 100644 --- a/harbour/utils/hbpp/hbpp.c +++ b/harbour/utils/hbpp/hbpp.c @@ -78,6 +78,7 @@ BOOL hb_comp_bAutoMemvarAssume = FALSE; /* holds if undeclared variables BOOL hb_comp_bForceMemvars = FALSE; /* holds if memvars are assumed when accesing undeclared variable (-v)*/ BOOL hb_comp_bDebugInfo = FALSE; /* holds if generate debugger required info */ int hb_comp_iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */ +FILE *hb_comp_yyppo = NULL; int main( int argc, char * argv[] ) { @@ -514,3 +515,9 @@ BOOL hb_pp_fopen( char * szFileName ) return TRUE; } + +PINLINE hb_compInlineAdd( char * szFunName ) +{ + HB_SYMBOL_UNUSED( szFunName ); + return NULL; +}