* harbour/common.mak
* harbour/source/compiler/Makefile
* harbour/include/hbcomp.h
* harbour/include/hbexprb.c
* harbour/include/hbexprc.c
* harbour/source/compiler/cmdcheck.c
* harbour/source/compiler/genc.c
* harbour/source/compiler/harbour.c
* harbour/source/compiler/harbour.l
* harbour/source/compiler/harbour.slx
* harbour/source/compiler/harbour.y
* harbour/source/compiler/hbgenerr.c
* harbour/source/compiler/hbident.c
* harbour/source/compiler/ppcomp.c
+ harbour/source/compiler/complex.c
+ added new PP based compiler lexer - it's smaller, MT safe and a
little bit faster then then the FLEX version.
+ added HB_COMP structure to hold compiler data in future MT version
+ added global variable HB_COMP_PTR hb_comp_data to make conversion
to MT easier - now it holds only PP and lexer data.
* update PP related code in compiler to be MT safe
+ added %pure-parser, %parse-param and %lex-param for bison to generate
MT safe grammar parser.
* updated FLEX to work with recent compiler modifications and pure-parser
bison API
* harbour/makefile.bc
* harbour/makefile.vc
* harbour/source/macro/Makefile
* harbour/source/macro/macro.l
* harbour/source/macro/macro.y
* harbour/source/macro/macrolex.c
* use hb_macro prefix instead of hb_comp in bison/flex parser/lexer
used in macro compiler to avoid possible conflicts in the future
* separated lexer data
* harbour/include/hbapi.h
* harbour/include/hbpp.h
* harbour/source/pp/ppcore.c
* harbour/source/pp/ppgen.c
* harbour/source/pp/pplib.c
* harbour/source/vm/macro.c
* removed not used members from HB_MACRO structure to make it
cleaner before creating common to compiler and macro compiler
structure
+ added new token HB_PP_TOKEN_EPSILON
+ added void * cargo parameters passed to executed user functions
+ hb_pp_tokenGet(), hb_pp_tokenToString(), hb_pp_tokenBlockString()
functions for new PP based compiler lexer
* harbour/utils/hbpp/hbpp.c
* harbour/utils/hbpp/hbpp.h
* harbour/utils/hbpp/hbppcomp.c
* harbour/utils/hbpp/hbppcore.c
* harbour/utils/hbpp/hbpplib.c
* harbour/utils/hbpp/pragma.c
* updated to compile with recent compiler header file modifications
PP, new lexer and most of grammar parser should be MT safe. Now we should
update all compiler functions to pass pointer to HB_COMP data structure
where we should all current global variables. This structure as first
member should have HB_CMPCOMMON structure which will hold common to
compiler and macro compiler data. Ryszard I think you are the best person
to define this structure.
We have new lexer which is MT safe but please note that it has to be
extensively tested so I would like to ask everybody to compile as much
as possible different code and check if the final programs work as
expected. Working on new code I removed some limitations existing in
FLEX though not all. At the beginning I tried to replicate the exact
FLEX behavior but I've found that in few places it does not work as
it should so I begin to encode rules in a way which remove some
limitations. In fact now it's much easier to control some things.
I kept the FLEX code working and made all necessary modifications
so it still can be used but keeping FLEX working cost us IMHO too
much. It's not possible to introduce some improvements to grammar
parser. All identifiers, keyword and macros returned by new lexer
are converted to upper letters, do not have to be freed by hb_xfree()
and is guarantied that will be always accessible. So from grammar file
we can remove all hb_compIdentifierNew( hb_strupr($1), TRUE ) what
should give noticeable speed improvement but will break the FLEX code.
Ryszard and other you will have to decide if we will support FLEX in
the future. We can also clean the code and remove most of other
redundant hb_strupr() and hb_strdup() used in many places. BTW only
one terminal symbol can be returned with lower letters: DOIDENT
and I make it intentionally so it's possible to use:
DO prog1 WITH "sth"
on case sensitive file systems so this symbol should be cloned in
upper cases as function symbol but used without modification as
file name. It's current behavior but I'm not sure you will want
to keep it. Maybe compiler switch to always convert file names
created from
DO <id> [WITH <params,...>]
to lower cases will be better. Please think about it.
258 lines
6.8 KiB
C
258 lines
6.8 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* Compiler C source with real code generation
|
|
*
|
|
* Copyright 2006 Przemyslaw Czerpak < druzus /at/ priv.onet.pl >
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
|
|
* their web site at http://www.gnu.org/).
|
|
*
|
|
*/
|
|
|
|
|
|
#include "hbcomp.h"
|
|
#include <errno.h>
|
|
|
|
BOOL hb_pp_NestedLiteralString = FALSE;
|
|
BOOL hb_pp_LiteralEscSeq = FALSE;
|
|
int hb_pp_StreamBlock = 0;
|
|
unsigned int hb_pp_MaxTranslateCycles = 1024;
|
|
char *hb_pp_STD_CH = NULL;
|
|
|
|
|
|
|
|
static void hb_pp_ErrorGen( void * cargo,
|
|
char * szMsgTable[], char cPrefix, int iErrorCode,
|
|
const char * szParam1, const char * szParam2 )
|
|
{
|
|
int iLine = hb_comp_iLine;
|
|
|
|
HB_SYMBOL_UNUSED( cargo );
|
|
|
|
/* I do not know why but compiler expect line number 1 bigger then
|
|
real line number */
|
|
hb_comp_iLine = hb_pp_line( hb_comp_data->pLex->pPP ) + 1;
|
|
if( cPrefix == 'W' )
|
|
hb_compGenWarning( szMsgTable, cPrefix, iErrorCode, szParam1, szParam2 );
|
|
else
|
|
hb_compGenError( szMsgTable, cPrefix, iErrorCode, szParam1, szParam2 );
|
|
hb_comp_iLine = iLine;
|
|
}
|
|
|
|
static void hb_pp_PragmaDump( void * cargo, char * pBuffer, ULONG ulSize,
|
|
int iLine )
|
|
{
|
|
PINLINE pInline;
|
|
|
|
HB_SYMBOL_UNUSED( cargo );
|
|
|
|
pInline = hb_compInlineAdd( ( HB_COMP_PTR ) cargo, NULL, iLine );
|
|
pInline->pCode = ( BYTE * ) hb_xgrab( ulSize + 1 );
|
|
memcpy( pInline->pCode, pBuffer, ulSize );
|
|
pInline->pCode[ ulSize ] = '\0';
|
|
pInline->lPCodeSize = ulSize;
|
|
}
|
|
|
|
static void hb_pp_hb_inLine( void * cargo, char * szFunc,
|
|
char * pBuffer, ULONG ulSize, int iLine )
|
|
{
|
|
if( hb_comp_iLanguage != LANG_C && hb_comp_iLanguage != LANG_OBJ_MODULE )
|
|
{
|
|
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_REQUIRES_C, NULL, NULL );
|
|
}
|
|
else
|
|
{
|
|
PINLINE pInline = hb_compInlineAdd( ( HB_COMP_PTR ) cargo,
|
|
hb_compIdentifierNew( szFunc, TRUE ), iLine );
|
|
pInline->pCode = ( BYTE * ) hb_xgrab( ulSize + 1 );
|
|
memcpy( pInline->pCode, pBuffer, ulSize );
|
|
pInline->pCode[ ulSize ] = '\0';
|
|
pInline->lPCodeSize = ulSize;
|
|
}
|
|
}
|
|
|
|
static BOOL hb_pp_CompilerSwitch( void * cargo, const char * szSwitch,
|
|
int iValue )
|
|
{
|
|
BOOL fError = FALSE;
|
|
int i = strlen( szSwitch );
|
|
|
|
HB_SYMBOL_UNUSED( cargo );
|
|
|
|
if( i > 1 && szSwitch[ i - 1 ] - '0' == iValue )
|
|
--i;
|
|
|
|
if( i == 1 )
|
|
{
|
|
switch( szSwitch[ 0 ] )
|
|
{
|
|
case 'a':
|
|
case 'A':
|
|
hb_comp_bAutoMemvarAssume = iValue != 0;
|
|
break;
|
|
|
|
case 'b':
|
|
case 'B':
|
|
hb_comp_bDebugInfo = iValue != 0;
|
|
break;
|
|
|
|
case 'l':
|
|
case 'L':
|
|
hb_comp_bLineNumbers = iValue != 0;
|
|
break;
|
|
|
|
case 'n':
|
|
case 'N':
|
|
hb_comp_bStartProc = iValue != 0;
|
|
break;
|
|
|
|
case 'p':
|
|
case 'P':
|
|
hb_comp_bPPO = iValue != 0;
|
|
break;
|
|
|
|
case 'q':
|
|
case 'Q':
|
|
hb_comp_bQuiet = iValue != 0;
|
|
break;
|
|
|
|
case 'v':
|
|
case 'V':
|
|
hb_comp_bForceMemvars = iValue != 0;
|
|
break;
|
|
|
|
case 'w':
|
|
case 'W':
|
|
if( iValue >= 0 && iValue <= 3 )
|
|
hb_comp_iWarnings = iValue;
|
|
else
|
|
fError = TRUE;
|
|
break;
|
|
|
|
case 'z':
|
|
case 'Z':
|
|
hb_comp_bShortCuts = iValue != 0;
|
|
break;
|
|
|
|
default:
|
|
fError = TRUE;
|
|
}
|
|
}
|
|
else if( i == 2 )
|
|
{
|
|
if( hb_strnicmp( szSwitch, "es", 2 ) == 0 &&
|
|
( iValue == HB_EXITLEVEL_DEFAULT ||
|
|
iValue == HB_EXITLEVEL_SETEXIT ||
|
|
iValue == HB_EXITLEVEL_DELTARGET ) )
|
|
hb_comp_iExitLevel = iValue;
|
|
else
|
|
fError = TRUE;
|
|
}
|
|
/* xHarbour extension */
|
|
else if( i >= 4 && hb_strnicmp( szSwitch, "TEXTHIDDEN", i ) == 0 &&
|
|
iValue >= 0 && iValue <= 1 )
|
|
hb_comp_iHidden = iValue;
|
|
else
|
|
fError = TRUE;
|
|
|
|
return fError;
|
|
}
|
|
|
|
|
|
void hb_pp_SetRules( BOOL fQuiet, int argc, char * argv[] )
|
|
{
|
|
char * szStdCh = hb_pp_STD_CH;
|
|
|
|
HB_TRACE( HB_TR_DEBUG, ( "hb_pp_SetRules()" ) );
|
|
|
|
if( szStdCh && * szStdCh <= ' ' )
|
|
szStdCh = "";
|
|
|
|
if( hb_comp_data->pLex->pPP )
|
|
{
|
|
hb_pp_init( hb_comp_data->pLex->pPP, fQuiet, hb_comp_data, NULL, NULL,
|
|
hb_pp_ErrorGen, NULL, hb_pp_PragmaDump,
|
|
HB_COMP_ISSUPPORTED( HB_COMPFLAG_HB_INLINE_PP ) ?
|
|
hb_pp_hb_inLine : NULL, hb_pp_CompilerSwitch );
|
|
|
|
if( !szStdCh )
|
|
hb_pp_setStdRules( hb_comp_data->pLex->pPP );
|
|
else if( *szStdCh )
|
|
hb_pp_readRules( hb_comp_data->pLex->pPP, szStdCh );
|
|
else
|
|
{
|
|
printf( "Standard command definitions excluded.\n" );
|
|
fflush( stdout );
|
|
}
|
|
|
|
hb_pp_initDynDefines( hb_comp_data->pLex->pPP );
|
|
|
|
/* Add /D and /undef: command line or envvar defines */
|
|
hb_compChkDefines( argc, argv );
|
|
|
|
/* mark current rules as standard ones */
|
|
hb_pp_setStdBase( hb_comp_data->pLex->pPP );
|
|
}
|
|
|
|
if( hb_comp_pFileName )
|
|
{
|
|
hb_xfree( ( void * ) hb_comp_pFileName );
|
|
hb_comp_pFileName = NULL;
|
|
}
|
|
if( hb_pp_STD_CH )
|
|
{
|
|
hb_xfree( hb_pp_STD_CH );
|
|
hb_pp_STD_CH = NULL;
|
|
}
|
|
}
|
|
|
|
int hb_pp_Internal( char * sOut )
|
|
{
|
|
char * szLine;
|
|
ULONG ulLen = 0;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_pp_Internal(%p, %s)", handl_o, sOut));
|
|
|
|
hb_pp_NestedLiteralString = FALSE;
|
|
hb_pp_LiteralEscSeq = FALSE;
|
|
|
|
if( hb_pp_StreamBlock == HB_PP_STREAM_DUMP_C )
|
|
hb_pp_setStream( hb_comp_data->pLex->pPP, HB_PP_STREAM_INLINE_C );
|
|
|
|
szLine = hb_pp_nextLine( hb_comp_data->pLex->pPP, &ulLen );
|
|
/* I do not know why but compiler expect line number 1 bigger then
|
|
real line number */
|
|
hb_comp_iLine = hb_pp_line( hb_comp_data->pLex->pPP ) + 1;
|
|
|
|
if( ulLen >= HB_PP_STR_SIZE )
|
|
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_BUFFER_OVERFLOW, NULL, NULL );
|
|
else if( szLine )
|
|
memcpy( sOut, szLine, ulLen + 1 );
|
|
else
|
|
* sOut = '\0';
|
|
|
|
if( hb_comp_iLineINLINE && hb_pp_StreamBlock == 0 )
|
|
{
|
|
hb_comp_iLineINLINE = 0;
|
|
}
|
|
|
|
return ulLen;
|
|
}
|