From 7c6bd0b33b62d251bd4ef9327650bbc99468c404 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Thu, 11 Jan 2001 02:31:36 +0000 Subject: [PATCH] 2001-01-10 18:20 UTC-0800 Ron Pinkas * include/hbcomp.h * source/compiler/harbour.c + Added members szFileName and iLine to structure INLINE, set to originating PRG name and line number. * source/compiler/genc.c + Added #line directive to INLINE generations, so C compile warnings/errors will report source file and line number in PRG. * source/compiler/harbour.l * source/compiler/harbour.slx + Added Error message if inline C is used with non C output. + Added support for {} on same line * Minor optimization * include/hberrors.h * source/compiler/hbgenerr.c + Added: "Inline C requires C output generartion, use -gc[n]" --- harbour/ChangeLog | 18 ++++++ harbour/include/hbcomp.h | 2 + harbour/include/hberrors.h | 1 + harbour/source/compiler/genc.c | 2 + harbour/source/compiler/harbour.c | 2 + harbour/source/compiler/harbour.l | 86 ++++++++++++++--------------- harbour/source/compiler/harbour.slx | 70 +++++++++++------------ harbour/source/compiler/hbgenerr.c | 3 +- 8 files changed, 101 insertions(+), 83 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7f04e35534..3f7b56f33e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,21 @@ +2001-01-10 18:20 UTC-0800 Ron Pinkas + * include/hbcomp.h + * source/compiler/harbour.c + + Added members szFileName and iLine to structure INLINE, set to originating PRG name and line number. + + * source/compiler/genc.c + + Added #line directive to INLINE generations, so C compile warnings/errors will report source file and line number in PRG. + + * source/compiler/harbour.l + * source/compiler/harbour.slx + + Added Error message if inline C is used with non C output. + + Added support for {} on same line + * Minor optimization + + * include/hberrors.h + * source/compiler/hbgenerr.c + + Added: "Inline C requires C output generartion, use -gc[n]" + 2001-01-10 22:30 GMT -3 Luiz Rafael Culik *utils/hbmake/hbmake.prg *Fixed an typo on an fwh lib name diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 95dd3ff7aa..10df13fba5 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -162,6 +162,8 @@ typedef struct __INLINE char * szName; /* name of a inline function */ BYTE * pCode; /* pointer to a memory block where pcode is stored */ ULONG lPCodeSize; /* total memory size for pcode */ + char * szFileName; /* Source file name */ + int iLine; /* Source line number */ struct __INLINE * pNext; /* pointer to the next defined inline */ } _INLINE, * PINLINE; diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index 45a967ceb3..ef0c38b7db 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -95,6 +95,7 @@ extern "C" { #define HB_COMP_ERR_GET_COMPLEX_MACRO 48 #define HB_COMP_ERR_INVALID_INLINE 49 #define HB_COMP_ERR_TOOMANY_INLINE 50 +#define HB_COMP_ERR_REQUIRES_C 51 #define HB_COMP_WARN_AMBIGUOUS_VAR 1 #define HB_COMP_WARN_MEMVAR_ASSUMED 2 diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index d8b484799e..1e975f0b8d 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -237,6 +237,7 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou pInline = hb_comp_inlines.pFirst; while( pInline ) { + 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; @@ -265,6 +266,7 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou { hb_comp_inlines.pFirst = pInline->pNext; 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 0c72815014..92b1c8adbc 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -990,6 +990,8 @@ static PINLINE hb_compInlineNew( char * szName ) pInline->pCode = NULL; pInline->lPCodeSize = 0; pInline->pNext = NULL; + pInline->szFileName = hb_strdup( hb_comp_files.pLast->szFileName ); + pInline->iLine = hb_comp_iLine - 1; return pInline; } diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 1bb1e843e5..eafc2bbed0 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -794,57 +794,53 @@ Separator {SpaceTab} } pBuffer = (char*) sBuffer; - while( *pBuffer && ( *pBuffer == ' ' || *pBuffer == '\t' ) ) - { + while( *pBuffer /* && ( *pBuffer == ' ' || *pBuffer == '\t' ) */ ) + { + if( *pBuffer == '{' ) + { + iBraces++; + } + else if( *pBuffer == '}' && iBraces > 1 ) + { + iBraces--; + } + else if( *pBuffer == '}' ) + { + hb_pp_bInline = FALSE; + } + pBuffer++; - } + } - if( *pBuffer == '\0' ) - { - goto DigestInline; - } - else if( *pBuffer == '{' ) - { - iBraces++; - } - else if( *pBuffer == '}' && iBraces > 1 ) - { - iBraces--; - } - else if( *pBuffer == '}' ) - { - if( pInline->pCode == NULL ) - { - pInline->pCode = (unsigned char *) hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 ); - strcpy( (char *) pInline->pCode, (char *) sBuffer ); - } - else - { - pInline->pCode = (unsigned char *) hb_xrealloc( pInline->pCode, pInline->lPCodeSize + ( iSize = strlen( (char*) sBuffer ) ) + 1 ); - strcpy( (char *) (pInline->pCode + pInline->lPCodeSize), (char *) sBuffer ); - } + 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; - pInline->lPCodeSize += iSize; + if( hb_pp_bInline ) + { + goto DigestInline; + } + else + { + if( hb_comp_iLanguage != LANG_C ) + { + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_REQUIRES_C, NULL, NULL ); + hb_xfree( ( void * ) pInline->pCode ); + hb_xfree( ( void * ) pInline->szFileName ); + hb_xfree( ( void * ) pInline ); /* NOTE: szName will be released by hb_compSymbolKill() */ + } - hb_pp_bInline = FALSE; yylval.string = hb_compIdentifierNew( sInlineSym, TRUE ); return IDENTIFIER; - } - - if( pInline->pCode == NULL ) - { - pInline->pCode = (unsigned char *) hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 ); - strcpy( (char *) pInline->pCode, (char *) sBuffer ); - } - else - { - pInline->pCode = (unsigned char *) hb_xrealloc( pInline->pCode, pInline->lPCodeSize + ( iSize = strlen( (char*) sBuffer ) ) + 1 ); - strcpy( (char *) (pInline->pCode + pInline->lPCodeSize), (char *) sBuffer ); - } - - pInline->lPCodeSize += iSize; - - goto DigestInline; + } } %{ diff --git a/harbour/source/compiler/harbour.slx b/harbour/source/compiler/harbour.slx index 2b241261bb..102fefc8e1 100644 --- a/harbour/source/compiler/harbour.slx +++ b/harbour/source/compiler/harbour.slx @@ -1035,45 +1035,24 @@ int hb_comp_SLX_CustomAction( int x, int aiHold[], int *ptr_iHold, BOOL *ptr_bIg } pBuffer = (char*) sBuffer; - while( *pBuffer && ( *pBuffer == ' ' || *pBuffer == '\t' ) ) + while( *pBuffer /* && ( *pBuffer == ' ' || *pBuffer == '\t' ) */ ) { + if( *pBuffer == '{' ) + { + iBraces++; + } + else if( *pBuffer == '}' && iBraces > 1 ) + { + iBraces--; + } + else if( *pBuffer == '}' ) + { + hb_pp_bInline = FALSE; + } + pBuffer++; } - if( *pBuffer == '\0' ) - { - goto DigestInline; - } - else if( *pBuffer == '{' ) - { - iBraces++; - } - else if( *pBuffer == '}' && iBraces > 1 ) - { - iBraces--; - } - else if( *pBuffer == '}' ) - { - 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; - - hb_pp_bInline = FALSE; - yylval.string = hb_compIdentifierNew( sInlineSym, TRUE ); - iIdentifier++; - DEBUG_INFO( printf( "INLINE, Primary Identifier %s Increased to: %i\n", "INLINE", iIdentifier ) ); - return IDENTIFIER + DONT_REDUCE; - } - if( pInline->pCode == NULL ) { pInline->pCode = hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 ); @@ -1084,10 +1063,27 @@ int hb_comp_SLX_CustomAction( int x, int aiHold[], int *ptr_iHold, BOOL *ptr_bIg 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; + if( hb_pp_bInline ) + { + goto DigestInline; + } + else + { + if( hb_comp_iLanguage != LANG_C ) + { + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_REQUIRES_C, NULL, NULL ); + hb_xfree( ( void * ) pInline->pCode ); + hb_xfree( ( void * ) pInline->szFileName ); + hb_xfree( ( void * ) pInline ); /* NOTE: szName will be released by hb_compSymbolKill() */ + } + + yylval.string = hb_compIdentifierNew( sInlineSym, TRUE ); + iIdentifier++; + DEBUG_INFO( printf( "INLINE, Primary Identifier %s Increased to: %i\n", "INLINE", iIdentifier ) ); + return IDENTIFIER + DONT_REDUCE; + } } default: diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index 97672fdb7e..e05ed90027 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -89,7 +89,8 @@ char * hb_comp_szErrors[] = "Code block contains both macro and declared symbol references", "GET contains complex macro", "Unterminated inline block in function: \'%s\'", - "Too many inline blocks" + "Too many inline blocks", + "Inline C requires C output generartion, use -gc[n]" }; /* Table with parse warnings */