From db79a723045921bf5c1adf53d54f7edf74a12ce6 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Tue, 2 Jan 2001 18:10:43 +0000 Subject: [PATCH] 2000-01-02 10:00 UTC-0800 Ron Pinkas * source/compiler/harbour.l + Added support for inline C code. --- harbour/ChangeLog | 5 ++ harbour/source/compiler/harbour.l | 92 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aa0911ea98..c7615dec42 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +2000-01-02 10:00 UTC-0800 Ron Pinkas + + * source/compiler/harbour.l + + Added support for inline C code. + 2000-01-01 23:35 UTC-0800 Ron Pinkas * source/compiler/harbour.c diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 3b0a7d5acf..9a6b3306fc 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -755,6 +755,98 @@ Separator {SpaceTab} unput( yytext[ yyleng-1 ] ); hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_SYNTAX, ((yytext[ yyleng-1 ]=='\n')?"FUNCTION":yytext), NULL ); } + +%{ +/* ************************************************************************ */ +%} + +"hb_inline" { + char sBuffer[ YY_BUF_SIZE ], *pBuffer, sInlineSym[] = "HB_INLINE_0"; + int iSize, iBraces = 0; + extern BOOL hb_pp_bInline; + PINLINE pInline; + + hb_pp_bInline = TRUE; + + sInlineSym[10] = hb_comp_cInlineID++; + + switch( sInlineSym[10] ) + { + case '9' + 1 : + sInlineSym[10] = 'A'; + break; + + case 'Z' + 1 : + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_TOOMANY_INLINE, NULL, NULL ); + break; + } + + pInline = hb_compInlineAdd( hb_compIdentifierNew( sInlineSym, TRUE ) ); + + DigestInline : + + YY_INPUT( (char*) sBuffer, iSize, YY_BUF_SIZE ); + if( iSize == 0 ) + { + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_INVALID_INLINE, hb_comp_functions.pLast->szName, NULL ); + hb_pp_bInline = FALSE; + return '\n'; + } + pBuffer = (char*) sBuffer; + + while( *pBuffer && ( *pBuffer == ' ' || *pBuffer == '\t' ) ) + { + 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 ); + return IDENTIFIER; + } + + 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; + } + %{ /* ************************************************************************ */ %}