diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0dd38d8dff..15fc5cad44 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,41 @@ +19991120-14:35 GMT+1 Ryszard Glab + + *source/compiler/harbour.y + * fixed NOT operator precedence + * fixed the infinite loop when a duplicated variable error + was reported + * fixed '=' operator use (there was conflict between a compare + and assignment context) + * added new warning "Unreachable code' + * fatal errors (errors for which the compilation process should + terminate immediately should use 'F' prefix) + * corrected logic of handling errors (the compilation can be continued + with no GPF or core dump) + + *source/compiler/expropt.c + * corrected to support 'DO procname' statement + + *include/compiler.h + *source/compiler/harbour.y + *source/compiler/harbour.c + *source/compiler/expropt.c + *source/compiler/genc.c + *source/compiler/genhrb.c + *source/compiler/genjava.c + *source/compiler/genobj32.c + * finished uniform naming scheme hb_comp* + * cleared up declarations and visibility of functions and variables + + *include/hberrors.h + * added new warning "Unreachable code' + + *source/debug/debugger.prg + * removed one unreachable RETURN statement + + *source/pp/hbpp.c + * all errors reported by the preprocesor are promoted to fatal + errors ('F' prefix) + 19991119-16:59 GMT+1 Antonio Linares * updated makefile.b32 * updated hbpp.b32 diff --git a/harbour/include/compiler.h b/harbour/include/compiler.h index b5d574fa02..2e9422b813 100644 --- a/harbour/include/compiler.h +++ b/harbour/include/compiler.h @@ -50,7 +50,6 @@ #include "hberrors.h" #include "hbpp.h" #include "hbver.h" -#include "hbfsapi.h" /* compiler related declarations */ @@ -183,10 +182,6 @@ typedef struct HB_EXPR_ } HB_EXPR, *HB_EXPR_PTR; - -extern PFUNCTION GetFunction( char * szFunName ); /* locates a previously defined function */ -extern USHORT GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */ - extern void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failure */ extern void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */ extern void hb_xfree( void * pMem ); /* frees memory */ @@ -194,13 +189,6 @@ extern void hb_xfree( void * pMem ); /* frees memory */ char * yy_strdup( char * p ); /* this will exit if there is not enough memory */ char * yy_strupr( char * p ); -extern USHORT FixSymbolPos( USHORT ); /* converts symbol's compile-time position into generation-time position */ -extern PFUNCTION GetFuncall( char * szFunName ); /* locates a previously defined called function */ -extern PVAR GetVar( PVAR pVars, USHORT wOrder ); /* returns a variable if defined or zero */ -extern PCOMSYMBOL hb_compGetSymbol( char *, USHORT * ); /* returns a symbol pointer from the symbol table */ -extern PCOMSYMBOL hb_compGetSymbolOrd( USHORT ); /* returns a symbol based on its index on the symbol table */ -extern PFUNCTION KillFunction( PFUNCTION ); /* releases all memory allocated by function and returns the next one */ -extern PCOMSYMBOL KillSymbol( PCOMSYMBOL ); /* releases all memory allocated by symbol and returns the next one */ #define VS_LOCAL 1 #define VS_STATIC 2 @@ -216,71 +204,45 @@ extern PCOMSYMBOL KillSymbol( PCOMSYMBOL ); /* releases all memory allocated #define FUN_STATEMENTS 1 /* Function have at least one executable statement */ #define FUN_USES_STATICS 2 /* Function uses static variables */ #define FUN_PROCEDURE 4 /* This is a procedure that shouldn't return value */ -#define FUN_ILLEGAL_INIT 8 /* Attempt to initialize static variable with a function call */ +#define FUN_BREAK_CODE 8 /* last statement breaks execution flow */ #define FUN_USES_LOCAL_PARAMS 16 /* parameters are declared using () */ #define FUN_WITH_RETURN 32 /* there was RETURN statement in previous line */ -typedef struct __EXTERN -{ - char * szName; - struct __EXTERN * pNext; -} _EXTERN, * PEXTERN; /* support structure for extern symbols */ -/* as they have to be placed on the symbol table later than the first public symbol */ -typedef struct _LOOPEXIT -{ - ULONG ulOffset; - int iLine; - USHORT wSeqCounter; - struct _LOOPEXIT * pLoopList; - struct _LOOPEXIT * pExitList; - struct _LOOPEXIT * pNext; -} LOOPEXIT, * PTR_LOOPEXIT; /* support structure for EXIT and LOOP statements */ +void hb_compFunctionAdd( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ); /* starts a new Clipper language function definition */ +PFUNCTION hb_compFunctionFind( char * szFunName ); /* locates a previously defined function */ +USHORT hb_compFunctionGetPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */ +PFUNCTION hb_compFunctionKill( PFUNCTION ); /* releases all memory allocated by function and returns the next one */ +PFUNCTION hb_compFunCallAdd( char * szFuntionName ); +PFUNCTION hb_compFunCallFind( char * szFunName ); /* locates a previously defined called function */ +void hb_compFunCallCheck( char *, int ); -typedef struct __ELSEIF -{ - ULONG ulOffset; - struct __ELSEIF * pNext; -} _ELSEIF, * PELSEIF; /* support structure for else if pcode fixups */ +void hb_compVariableAdd( char * szVarName, char cType ); /* add a new param, local, static variable to a function definition or a public or private */ +PVAR hb_compVariableFind( PVAR pVars, USHORT wOrder ); /* returns a variable if defined or zero */ + +PCOMSYMBOL hb_compSymbolAdd( char *, USHORT * ); +PCOMSYMBOL hb_compSymbolKill( PCOMSYMBOL ); /* releases all memory allocated by symbol and returns the next one */ +PCOMSYMBOL hb_compSymbolFind( char *, USHORT * ); /* returns a symbol pointer from the symbol table */ +PCOMSYMBOL hb_compSymbolGetPos( USHORT ); /* returns a symbol based on its index on the symbol table */ +USHORT hb_compSymbolFixPos( USHORT ); /* converts symbol's compile-time position into generation-time position */ -/* TODO: clear the functions name space - */ -PFUNCTION hb_compAddFunCall( char * szFuntionName ); -void hb_compAddExtern( char * szExternName ); /* defines a new extern name */ -void hb_compAddVar( char * szVarName, char cType ); /* add a new param, local, static variable to a function definition or a public or private */ -PCOMSYMBOL hb_compAddSymbol( char *, USHORT * ); -void CheckDuplVars( PVAR pVars, char * szVarName, int iVarScope ); /*checks for duplicate variables definitions */ -void Dec( void ); /* generates the pcode to decrement the latest value on the virtual machine stack */ -void hb_compGenDoProc( BYTE bParams ); /* generates the pcode to execute a Clipper function discarding its result */ -void Duplicate( void ); /* duplicates the virtual machine latest stack latest value and places it on the stack */ -void DupPCode( ULONG ulStart ); /* duplicates the current generated pcode from an offset */ -void FieldPCode( BYTE , char * ); /* generates the pcode for database field */ -void FixElseIfs( void * pIfElseIfs ); /* implements the ElseIfs pcode fixups */ -void FixReturns( void ); /* fixes all last defined function returns jumps offsets */ -void Function( BYTE bParams ); /* generates the pcode to execute a Clipper function pushing its result */ -PFUNCTION FunctionNew( char *, char ); /* creates and initialises the _FUNC structure */ -void hb_compFunDef( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ); /* starts a new Clipper language function definition */ -void GenArray( int iElements ); /* instructs the virtual machine to build an array and load elemnst from the stack */ void hb_compGenBreak( void ); /* generate code for BREAK statement */ -void * GenElseIf( void * pFirstElseIf, ULONG ulOffset ); /* generates a support structure for elseifs pcode fixups */ -void hb_compGenExterns( void ); /* generates the symbols for the EXTERN names */ -void GenIfInline( void ); /* generates pcodes for IIF( expr1, expr2, expr3 ) */ -int GetFieldVarPos( char *, PFUNCTION ); /* return if passed name is a field variable */ -int GetMemvarPos( char *, PFUNCTION ); /* return if passed name is a memvar variable */ -USHORT GetVarPos( PVAR pVars, char * szVarName ); /* returns the order + 1 of a variable if defined or zero */ -int GetLocalVarPos( char * szVarName ); /* returns the order + 1 of a local variable */ -void Inc( void ); /* generates the pcode to increment the latest value on the virtual machine stack */ + +void hb_compExternGen( void ); /* generates the symbols for the EXTERN names */ +void hb_compExternAdd( char * szExternName ); /* defines a new extern name */ + ULONG hb_compGenJump( LONG lOffset ); /* generates the pcode to jump to a specific offset */ ULONG hb_compGenJumpFalse( LONG lOffset ); /* generates the pcode to jump if false */ +ULONG hb_compGenJumpTrue( LONG lOffset ); /* generates the pcode to jump if true */ void hb_compGenJumpHere( ULONG ulOffset ); /* returns the pcode pos where to set a jump offset */ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo ); /* sets a jump offset */ -ULONG hb_compGenJumpTrue( LONG lOffset ); /* generates the pcode to jump if true */ -void Line( void ); /* generates the pcode with the currently compiled source code line */ -void LineDebug( void ); /* generates the pcode with the currently compiled source code line */ -void LineBody( void ); /* generates the pcode with the currently compiled source code line */ -void VariablePCode( BYTE , char * ); /* generates the pcode for undeclared variable */ -void MemvarPCode( BYTE , char * ); /* generates the pcode for memvar variable */ + + +void hb_compLinePush( void ); /* generates the pcode with the currently compiled source code line */ +void hb_compLinePushIfDebugger( void ); /* generates the pcode with the currently compiled source code line */ +void hb_compLinePushIfInside( void ); /* generates the pcode with the currently compiled source code line */ + void hb_compGenMessage( char * szMsgName ); /* sends a message to an object */ void hb_compGenMessageData( char * szMsg ); /* generates an underscore-symbol name for a data assignment */ void hb_compGenPopVar( char * szVarName ); /* generates the pcode to pop a value from the virtual machine stack onto a variable */ @@ -293,40 +255,25 @@ void hb_compGenPushLogical( int iTrueFalse ); /* pushes a logical value on t void hb_compGenPushLong( long lNumber ); /* Pushes a long number on the virtual machine stack */ void hb_compGenPushNil( void ); /* Pushes nil on the virtual machine stack */ void hb_compGenPushString( char * szText, ULONG ulLen ); /* Pushes a string on the virtual machine stack */ -void hb_compPushSymbol( char * szSymbolName, int iIsFunction ); /* Pushes a symbol on to the Virtual machine stack */ +void hb_compGenPushSymbol( char * szSymbolName, int iIsFunction ); /* Pushes a symbol on to the Virtual machine stack */ void hb_compGenPushAliasedVar( char *, BOOL, char *, long ); void hb_compGenPopAliasedVar( char *, BOOL, char *, long ); +void hb_compGenPushFunRef( char * ); +void hb_compGenPCode1( BYTE ); /* generates 1 byte of pcode */ +void hb_compGenPCode3( BYTE, BYTE, BYTE ); /* generates 3 bytes of pcode */ +void hb_compGenPCodeN( BYTE * pBuffer, ULONG ulSize ); /* copy bytes to a pcode buffer */ /* Codeblocks */ void hb_compCodeBlockStart( void ); /* starts a codeblock creation */ void hb_compCodeBlockEnd( void ); /* end of codeblock creation */ - -void hb_compGenPushFunRef( char * ); - -void hb_compGenPCode1( BYTE ); /* generates 1 byte of pcode */ -void hb_compGenPCode3( BYTE, BYTE, BYTE ); /* generates 3 bytes of pcode */ -void hb_compGenPCodeN( BYTE * pBuffer, ULONG ulSize ); /* copy bytes to a pcode buffer */ - -ULONG SequenceBegin( void ); -ULONG SequenceEnd( void ); -void SequenceFinish( ULONG, int ); - -/* Managing value type */ -extern void ValTypePush( char cType ); /* Pushes the type of expression (used with -w3 option */ -extern void ValTypePop( int ); -extern void ValTypePlus( void ); -extern void ValTypeRelational( void ); -extern void ValTypeCheck( char, int, int ); -extern void ValTypeCheck2( char, int, int ); -extern char ValTypeGet( void ); -extern void ValTypePut( char ); -extern void ValTypeAssign( char * ); -extern void ValTypeReset( void ); +ULONG hb_compSequenceBegin( void ); +ULONG hb_compSequenceEnd( void ); +void hb_compSequenceFinish( ULONG, int ); /* support for FIELD declaration */ -void FieldsSetAlias( char *, int ); -int FieldsCount( void ); +void hb_compFieldSetAlias( char *, int ); +int hb_compFieldsCount( void ); /* Static variables */ void hb_compStaticDefStart( void ); @@ -342,13 +289,12 @@ HB_EXPR_PTR hb_compErrorAlias( HB_EXPR_PTR ); void hb_compErrorDuplVar( char * ); HB_EXPR_PTR hb_compWarnMeaningless( HB_EXPR_PTR ); -void hb_compCheckArgs( char *, int ); - void hb_compGenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ); void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2); /* variable used by compiler */ +extern int hb_comp_iLine; extern FUNCTIONS hb_comp_functions, hb_comp_funcalls; extern SYMBOLS hb_comp_symbols; extern PATHNAMES * hb_comp_pIncludePath; @@ -368,14 +314,12 @@ extern char hb_comp_szPrefix[ 20 ]; extern BOOL hb_comp_bGenCVerbose; extern int hb_comp_iExitLevel; extern int hb_comp_iFunctionCnt; -extern BOOL hb_comp_bExternal; extern char hb_comp_cVarType; extern int hb_comp_iVarScope; extern BOOL hb_comp_bDontGenLineNum; extern FILES hb_comp_files; extern int hb_comp_iStaticCnt; extern int hb_comp_iErrorCount; -extern PTR_LOOPEXIT hb_comp_pLoops; extern USHORT hb_comp_wSeqCounter; extern USHORT hb_comp_wForCounter; @@ -445,6 +389,7 @@ HB_EXPR_PTR hb_compExprAddListExpr( HB_EXPR_PTR, HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprNewIIF( HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprReduce( HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprAssign( HB_EXPR_PTR, HB_EXPR_PTR ); +HB_EXPR_PTR hb_compExprEqual( HB_EXPR_PTR, HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprAssignStatic( HB_EXPR_PTR, HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprGenPop( HB_EXPR_PTR ); HB_EXPR_PTR hb_compExprGenPush( HB_EXPR_PTR ); diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index 3e29ea41a4..a44d7b7032 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -97,6 +97,7 @@ #define WARN_LOGICAL_SUSPECT 14 #define WARN_NUMERIC_SUSPECT 15 #define WARN_MEANINGLESS 16 +#define WARN_UNREACHABLE 17 /* * Errors generated by Harbour preprocessor diff --git a/harbour/source/compiler/expropt.c b/harbour/source/compiler/expropt.c index e34275ed92..a8801c6c93 100644 --- a/harbour/source/compiler/expropt.c +++ b/harbour/source/compiler/expropt.c @@ -577,14 +577,21 @@ HB_EXPR_PTR hb_compExprNewFunCall( char *szFunName, HB_EXPR_PTR pParms ) HB_EXPR_PTR pExpr = NULL; int iCount; - iCount = hb_compExprListLen( pParms ); - /* Check the special case when no parameters are passed - in this case - * pParms is an expression of type HB_ET_NONE and we shouldn't - * replace it with NIL value - */ - if( iCount == 1 && pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) - --iCount; - hb_compCheckArgs( szFunName, iCount ); + if( pParms ) + { + iCount = hb_compExprListLen( pParms ); + /* Check the special case when no parameters are passed - in this case + * pParms is an expression of type HB_ET_NONE and we shouldn't + * replace it with NIL value + */ + if( iCount == 1 && pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) + --iCount; + } + else + iCount = 0; + + hb_compFunCallCheck( szFunName, iCount ); + if( ( strcmp( "CHR", szFunName ) == 0 ) && iCount ) { /* try to change it into a string */ @@ -604,6 +611,7 @@ HB_EXPR_PTR hb_compExprNewFunCall( char *szFunName, HB_EXPR_PTR pParms ) hb_compExprDelete( pParms ); } } + if( pExpr == NULL ) { pExpr = hb_compExprNew( HB_ET_FUNCALL ); @@ -1123,7 +1131,7 @@ HB_EXPR_PTR hb_compExprSetOperand( HB_EXPR_PTR pExpr, HB_EXPR_PTR pItem ) /* the right side of an operator is an expression with other operator * e.g. a := 2 + b * 3 * We have to set the proper order of evaluation using - * precedennce rules + * precedence rules */ unsigned char ucLeft = s_PrecedTable[ pExpr->ExprType ]; if( ucLeft >= ucRight ) @@ -1366,7 +1374,7 @@ static HB_EXPR_FUNC( hb_compExprUseCodeblock ) pVar = ( HB_CBVAR_PTR ) pSelf->value.asList.pIndex; while( pVar ) { - hb_compAddVar( pVar->szName, pVar->bType ); + hb_compVariableAdd( pVar->szName, pVar->bType ); pVar =pVar->pNext; } pExpr = pSelf->value.asList.pExprList; @@ -2015,7 +2023,8 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) { /* Reduce the expressions on the list of arguments */ - pSelf->value.asFunCall.pParms = HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_REDUCE ); + if( pSelf->value.asFunCall.pParms ) + pSelf->value.asFunCall.pParms = HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_REDUCE ); } break; @@ -2034,11 +2043,19 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) hb_compGenPushFunCall( pSelf->value.asFunCall.szFunName ); hb_compGenPCode1( HB_P_PUSHNIL ); - usCount = hb_compExprListLen( pSelf->value.asFunCall.pParms ); - if( usCount == 1 && pSelf->value.asFunCall.pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) - --usCount; - if( usCount ) - HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); + if( pSelf->value.asFunCall.pParms ) + { + /* NOTE: pParms will be NULL in 'DO procname' (if there is + * no WITH keyword) + */ + usCount = hb_compExprListLen( pSelf->value.asFunCall.pParms ); + if( usCount == 1 && pSelf->value.asFunCall.pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) + --usCount; + if( usCount ) + HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); + } + else + usCount = 0; hb_compGenPCode3( HB_P_FUNCTION, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); } break; @@ -2054,11 +2071,16 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) hb_compGenPushFunCall( pSelf->value.asFunCall.szFunName ); hb_compGenPCode1( HB_P_PUSHNIL ); - usCount = hb_compExprListLen( pSelf->value.asFunCall.pParms ); - if( usCount == 1 && pSelf->value.asFunCall.pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) - --usCount; - if( usCount ) - HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); + if( pSelf->value.asFunCall.pParms ) + { + usCount = hb_compExprListLen( pSelf->value.asFunCall.pParms ); + if( usCount == 1 && pSelf->value.asFunCall.pParms->value.asList.pExprList->ExprType == HB_ET_NONE ) + --usCount; + if( usCount ) + HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); + } + else + usCount = 0; hb_compGenPCode3( HB_P_DO, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); } break; diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index ef1e753ada..d4c755c5aa 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -96,7 +96,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ pFunc = hb_comp_funcalls.pFirst; while( pFunc ) { - pFTemp = GetFunction( pFunc->szName ); + pFTemp = hb_compFunctionFind( pFunc->szName ); if( ! pFTemp || pFTemp == hb_comp_functions.pFirst ) fprintf( yyc, "extern HARBOUR HB_%s( void );\n", pFunc->szName ); pFunc = pFunc->pNext; @@ -146,9 +146,9 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ /* specify the function address if it is a defined function or an external called function */ - if( GetFunction( pSym->szName ) ) /* is it a function defined in this module */ + if( hb_compFunctionFind( pSym->szName ) ) /* is it a function defined in this module */ fprintf( yyc, ", HB_%s, 0 }", pSym->szName ); - else if( GetFuncall( pSym->szName ) ) /* is it a function called from this module */ + else if( hb_compFunCallFind( pSym->szName ) ) /* is it a function called from this module */ fprintf( yyc, ", HB_%s, 0 }", pSym->szName ); else fprintf( yyc, ", 0, 0 }" ); /* memvar */ @@ -421,11 +421,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wSym = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wSym ); + wFixPos = hb_compSymbolFixPos( wSym ); fprintf( yyc, "\tHB_P_MESSAGE, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wSym )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wSym )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -440,7 +440,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ fprintf( yyc, "\tHB_P_MODULENAME," ); if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", ( char * ) pFunc->pCode + lPCodePos++ + 1 ); fprintf( yyc, "\n" ); - lPCodePos++; + lPCodePos++; while( pFunc->pCode[ lPCodePos ] ) { chr = pFunc->pCode[ lPCodePos++ ]; @@ -488,12 +488,12 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PARAMETER, %i, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ), pFunc->pCode[ lPCodePos + 3 ] ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 4; } @@ -519,11 +519,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_POPALIASEDFIELD, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -534,11 +534,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_POPFIELD, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -576,7 +576,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ fprintf( yyc, "\tHB_P_POPLOCAL, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", GetVar( pFunc->pLocals, wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName ); fprintf( yyc, "\n" ); } lPCodePos += 3; @@ -588,11 +588,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_POPMEMVAR, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -606,7 +606,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; while( pTmp->pNext && pTmp->pNext->iStaticsBase < wVar ) pTmp = pTmp->pNext; - pVar = GetVar( pTmp->pStatics, wVar - pTmp->iStaticsBase ); + pVar = hb_compVariableFind( pTmp->pStatics, wVar - pTmp->iStaticsBase ); fprintf( yyc, "\tHB_P_POPSTATIC, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); @@ -621,11 +621,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ USHORT wFixPos; wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_POPVARIABLE, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -647,11 +647,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PUSHALIASEDFIELD, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -690,7 +690,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ fprintf( yyc, "\t%i, %i,", pFunc->pCode[ lPCodePos ], pFunc->pCode[ lPCodePos + 1 ] ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", GetVar( pFunc->pLocals, w )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, w )->szName ); fprintf( yyc, "\n" ); lPCodePos +=2; } @@ -718,11 +718,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PUSHFIELD, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -771,7 +771,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ fprintf( yyc, "\tHB_P_PUSHLOCAL, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", GetVar( pFunc->pLocals, wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName ); fprintf( yyc, "\n" ); } lPCodePos += 3; @@ -810,7 +810,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ fprintf( yyc, "\tHB_P_PUSHLOCALREF, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", GetVar( pFunc->pLocals, wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName ); fprintf( yyc, "\n" ); } lPCodePos += 3; @@ -834,11 +834,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PUSHMEMVAR, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -850,11 +850,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PUSHMEMVARREF, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -878,7 +878,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; while( pTmp->pNext && pTmp->pNext->iStaticsBase < wVar ) pTmp = pTmp->pNext; - pVar = GetVar( pTmp->pStatics, wVar - pTmp->iStaticsBase ); + pVar = hb_compVariableFind( pTmp->pStatics, wVar - pTmp->iStaticsBase ); fprintf( yyc, "\tHB_P_PUSHSTATIC, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); @@ -896,7 +896,7 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; while( pTmp->pNext && pTmp->pNext->iStaticsBase < wVar ) pTmp = pTmp->pNext; - pVar = GetVar( pTmp->pStatics, wVar - pTmp->iStaticsBase ); + pVar = hb_compVariableFind( pTmp->pStatics, wVar - pTmp->iStaticsBase ); fprintf( yyc, "\tHB_P_PUSHSTATICREF, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], pFunc->pCode[ lPCodePos + 2 ] ); @@ -922,10 +922,10 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ while( wLen-- ) { uchr = ( unsigned char ) ( pFunc->pCode[ lPCodePos++ ] ); - /* + /* * NOTE: After optimization some CHR(n) can be converted * into a string containing nonprintable characters. - * + * * TODO: add switch to use hexadecimal format "%#04x" */ if( ( uchr < (unsigned char) ' ' ) || ( uchr >= 127 ) ) @@ -945,11 +945,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wSym = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wSym ); + wFixPos = hb_compSymbolFixPos( wSym ); fprintf( yyc, "\tHB_P_PUSHSYM, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wSym )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wSym )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -961,11 +961,11 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ wVar = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; - wFixPos = FixSymbolPos( wVar ); + wFixPos = hb_compSymbolFixPos( wVar ); fprintf( yyc, "\tHB_P_PUSHVARIABLE, %i, %i,", HB_LOBYTE( wFixPos ), HB_HIBYTE( wFixPos ) ); - if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compGetSymbolOrd( wVar )->szName ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( wVar )->szName ); fprintf( yyc, "\n" ); lPCodePos += 3; } @@ -1007,8 +1007,8 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ /* we only generate it if there are statics used in this function */ if( pFunc->bFlags & FUN_USES_STATICS ) { - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); fprintf( yyc, "\tHB_P_SFRAME, %i, %i,", HB_LOBYTE( w ), HB_HIBYTE( w ) ); if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* symbol (_INITSTATICS) */" ); @@ -1019,8 +1019,8 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ case HB_P_STATICS: - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); fprintf( yyc, "\tHB_P_STATICS, %i, %i, %i, %i,", HB_LOBYTE( w ), HB_HIBYTE( w ), @@ -1074,19 +1074,19 @@ void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ pFunc = hb_comp_functions.pFirst; while( pFunc ) - pFunc = KillFunction( pFunc ); + pFunc = hb_compFunctionKill( pFunc ); pFunc = hb_comp_funcalls.pFirst; while( pFunc ) { hb_comp_funcalls.pFirst = pFunc->pNext; - hb_xfree( ( void * ) pFunc ); /* NOTE: szName will be released by KillSymbol() */ + hb_xfree( ( void * ) pFunc ); /* NOTE: szName will be released by hb_compSymbolKill() */ pFunc = hb_comp_funcalls.pFirst; } pSym = hb_comp_symbols.pFirst; while( pSym ) - pSym = KillSymbol( pSym ); + pSym = hb_compSymbolKill( pSym ); if( ! hb_comp_bQuiet ) printf( "Done.\n" ); diff --git a/harbour/source/compiler/genhrb.c b/harbour/source/compiler/genhrb.c index 9925fdc3f1..a7faab6208 100644 --- a/harbour/source/compiler/genhrb.c +++ b/harbour/source/compiler/genhrb.c @@ -100,13 +100,13 @@ void GenPortObj( PHB_FNAME pFileName ) /* specify the function address if it is a defined function or a external called function */ - if( GetFunction( pSym->szName ) ) /* is it a defined function ? */ + if( hb_compFunctionFind( pSym->szName ) ) /* is it a defined function ? */ { fputc( SYM_FUNC, yyc ); } else { - if( GetFuncall( pSym->szName ) ) + if( hb_compFunCallFind( pSym->szName ) ) { fputc( SYM_EXTERN, yyc ); } @@ -270,7 +270,7 @@ void GenPortObj( PHB_FNAME pFileName ) case HB_P_POPALIASEDFIELD: case HB_P_PUSHALIASEDFIELD: fputc( pFunc->pCode[ lPCodePos ], yyc ); - wVar = FixSymbolPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); + wVar = hb_compSymbolFixPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); fputc( HB_LOBYTE( wVar ), yyc ); fputc( HB_HIBYTE( wVar ), yyc ); lPCodePos += 3; @@ -278,7 +278,7 @@ void GenPortObj( PHB_FNAME pFileName ) case HB_P_PARAMETER: fputc( pFunc->pCode[ lPCodePos ], yyc ); - wVar = FixSymbolPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); + wVar = hb_compSymbolFixPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); fputc( HB_LOBYTE( wVar ), yyc ); fputc( HB_HIBYTE( wVar ), yyc ); fputc( pFunc->pCode[ lPCodePos + 3 ], yyc ); @@ -336,8 +336,8 @@ void GenPortObj( PHB_FNAME pFileName ) /* we only generate it if there are statics used in this function */ if( pFunc->bFlags & FUN_USES_STATICS ) { - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); fputc( pFunc->pCode[ lPCodePos ], yyc ); fputc( HB_LOBYTE( w ), yyc ); fputc( HB_HIBYTE( w ), yyc ); @@ -348,8 +348,8 @@ void GenPortObj( PHB_FNAME pFileName ) break; case HB_P_STATICS: - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); fputc( pFunc->pCode[ lPCodePos ], yyc ); fputc( HB_LOBYTE( w ), yyc ); fputc( HB_HIBYTE( w ), yyc ); diff --git a/harbour/source/compiler/genjava.c b/harbour/source/compiler/genjava.c index 2667a9a882..a75d899034 100644 --- a/harbour/source/compiler/genjava.c +++ b/harbour/source/compiler/genjava.c @@ -122,13 +122,13 @@ void GenJava( PHB_FNAME pFileName ) /* specify the function address if it is a defined function or a external called function */ - if( GetFunction( pSym->szName ) ) /* is it a defined function ? */ + if( hb_compFunctionFind( pSym->szName ) ) /* is it a defined function ? */ { hb_fputc( SYM_FUNC, yyc ); } else { - if( GetFuncall( pSym->szName ) ) + if( hb_compFunCallFind( pSym->szName ) ) { hb_fputc( SYM_EXTERN, yyc ); } @@ -292,7 +292,7 @@ void GenJava( PHB_FNAME pFileName ) case HB_P_POPALIASEDFIELD: case HB_P_PUSHALIASEDFIELD: hb_fputc( pFunc->pCode[ lPCodePos ], yyc ); - wVar = FixSymbolPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); + wVar = hb_compSymbolFixPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); hb_fputc( HB_LOBYTE( wVar ), yyc ); hb_fputc( HB_HIBYTE( wVar ), yyc ); lPCodePos += 3; @@ -300,7 +300,7 @@ void GenJava( PHB_FNAME pFileName ) case HB_P_PARAMETER: hb_fputc( pFunc->pCode[ lPCodePos ], yyc ); - wVar = FixSymbolPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); + wVar = hb_compSymbolFixPos( pFunc->pCode[ lPCodePos + 1 ] + 256 * pFunc->pCode[ lPCodePos + 2 ] ); hb_fputc( HB_LOBYTE( wVar ), yyc ); hb_fputc( HB_HIBYTE( wVar ), yyc ); hb_fputc( pFunc->pCode[ lPCodePos + 3 ], yyc ); @@ -358,8 +358,8 @@ void GenJava( PHB_FNAME pFileName ) /* we only generate it if there are statics used in this function */ if( pFunc->bFlags & FUN_USES_STATICS ) { - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); hb_fputc( pFunc->pCode[ lPCodePos ], yyc ); hb_fputc( HB_LOBYTE( w ), yyc ); hb_fputc( HB_HIBYTE( w ), yyc ); @@ -370,8 +370,8 @@ void GenJava( PHB_FNAME pFileName ) break; case HB_P_STATICS: - hb_compGetSymbol( hb_comp_pInitFunc->szName, &w ); - w = FixSymbolPos( w ); + hb_compSymbolFind( hb_comp_pInitFunc->szName, &w ); + w = hb_compSymbolFixPos( w ); hb_fputc( pFunc->pCode[ lPCodePos ], yyc ); hb_fputc( HB_LOBYTE( w ), yyc ); hb_fputc( HB_HIBYTE( w ), yyc ); @@ -429,7 +429,7 @@ static void hb_fputc( BYTE b, FILE * yyc ) fprintf( yyc, ", " ); if( _nChar == 9 ) - { + { fprintf( yyc, "\n " ); _nChar = 1; } diff --git a/harbour/source/compiler/genobj32.c b/harbour/source/compiler/genobj32.c index 92f31bf548..c8275856a9 100644 --- a/harbour/source/compiler/genobj32.c +++ b/harbour/source/compiler/genobj32.c @@ -170,7 +170,7 @@ static BOOL IsExternal( ULONG ulSymbol ) while( ul++ < ulSymbol ) pSymbol = pSymbol->pNext; - return ! GetFunction( pSymbol->szName ); + return ! hb_compFunctionFind( pSymbol->szName ); } static USHORT GetExternalPos( char * szExternal ) @@ -302,7 +302,7 @@ static void GenerateExternals( FILE * hObjFile ) pFunc = hb_comp_funcalls.pFirst; while( pFunc ) { - if( ! ( pFTemp = GetFunction( pFunc->szName ) ) || pFTemp == hb_comp_functions.pFirst ) + if( ! ( pFTemp = hb_compFunctionFind( pFunc->szName ) ) || pFTemp == hb_comp_functions.pFirst ) wExternals++; pFunc = pFunc->pNext; } @@ -315,7 +315,7 @@ static void GenerateExternals( FILE * hObjFile ) pFunc = hb_comp_funcalls.pFirst; while( pFunc ) { - if( ! ( pFTemp = GetFunction( pFunc->szName ) ) || pFTemp == hb_comp_functions.pFirst ) + if( ! ( pFTemp = hb_compFunctionFind( pFunc->szName ) ) || pFTemp == hb_comp_functions.pFirst ) externNames[ w++ ] = pFunc->szName; pFunc = pFunc->pNext; } @@ -528,7 +528,7 @@ static void DataSegment( FILE * hObjFile, BYTE * symbol, USHORT wSymLen, USHORT if( ! IsExternal( y ) ) { - ulFunctionOffset = ( GetFunctionPos( pSymbol->szName ) - 1 ) * + ulFunctionOffset = ( hb_compFunctionGetPos( pSymbol->szName ) - 1 ) * sizeof( prgFunction ); * ( ( ULONG * ) &symbol[ 5 ] ) = ulFunctionOffset; } diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index a7c610207f..7d8eb78896 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -85,9 +85,21 @@ static ULONG PackDateTime( void ); static void AddSearchPath( char *, PATHNAMES * * ); /* add pathname to a search list */ static char * RESERVED_FUNC( char * ); +static void hb_compCheckDuplVars( PVAR pVars, char * szVarName, int iVarScope ); /*checks for duplicate variables definitions */ +static void hb_compFieldGenPCode( BYTE , char * ); /* generates the pcode for database field */ +static int hb_compFieldGetVarPos( char *, PFUNCTION ); /* return if passed name is a field variable */ +static void hb_compFixReturns( void ); /* fixes all last defined function returns jumps offsets */ +static PFUNCTION hb_compFunctionNew( char *, char ); /* creates and initialises the _FUNC structure */ +static int hb_compLocalVarGetPos( char * szVarName ); /* returns the order + 1 of a local variable */ +static int hb_compMemvarGetPos( char *, PFUNCTION ); /* return if passed name is a memvar variable */ +static void hb_compMemvarGenPCode( BYTE , char * ); /* generates the pcode for memvar variable */ +static USHORT hb_compVariableGetPos( PVAR pVars, char * szVarName ); /* returns the order + 1 of a variable if defined or zero */ +static void hb_compVariableGenPCode( BYTE , char * ); /* generates the pcode for undeclared variable */ + + void EXTERNAL_LINKAGE close_on_exit( void ); -extern int iLine; /* currently parsed file line number */ +extern int hb_comp_iLine; /* currently parsed file line number */ /* global variables */ FILES hb_comp_files; @@ -95,6 +107,7 @@ FUNCTIONS hb_comp_functions, hb_comp_funcalls; SYMBOLS hb_comp_symbols; +int hb_comp_iLine = 1; /* currently processed line number */ PFUNCTION hb_comp_pInitFunc; PHB_FNAME hb_comp_pFileName = NULL; BOOL hb_comp_bStartProc = TRUE; /* holds if we need to create the starting procedure */ @@ -115,13 +128,9 @@ int hb_comp_iFunctionCnt = 0; int hb_comp_iErrorCount = 0; char hb_comp_cVarType = ' '; /* current declared variable type */ BOOL hb_comp_bDontGenLineNum = FALSE; /* suppress line number generation */ -LONG hb_comp_lLastPushPos = -1; /* position of last push pcode */ ULONG hb_comp_ulLastLinePos = 0; /* position of last opcode with line number */ ULONG hb_comp_ulMessageFix = 0; /* Position of the message which needs to be changed */ int hb_comp_iStaticCnt = 0; /* number of defined statics variables on the PRG */ -BOOL hb_comp_bExternal = FALSE; -PTR_LOOPEXIT hb_comp_pLoops = NULL; -PEXTERN hb_comp_pExterns = NULL; int hb_comp_iVarScope = VS_LOCAL; /* holds the scope for next variables to be defined */ /* different values for hb_comp_iVarScope */ @@ -132,6 +141,20 @@ static BOOL s_bLogo = TRUE; /* print logo */ static BOOL s_bSyntaxCheckOnly = FALSE; /* syntax check only */ static int s_iLanguage = LANG_C; /* default Harbour generated output language */ +typedef struct __EXTERN +{ + char * szName; + struct __EXTERN * pNext; +} _EXTERN, * PEXTERN; /* support structure for extern symbols */ +/* as they have to be placed on the symbol table later than the first public symbol */ + +/* EXTERNAL statement can be placed into any place in a function - this flag is + * used to suppress error report generation + */ +static BOOL hb_comp_bExternal = FALSE; +/* linked list with EXTERNAL symbols declarations +*/ +static PEXTERN hb_comp_pExterns = NULL; /* Table with parse errors */ char * hb_comp_szCErrors[] = @@ -200,7 +223,8 @@ char * hb_comp_szCWarnings[] = "3Suspicious operand type: \'UnKnown\' expected: \'%s\'", "3Suspicious operand type: \'UnKnown\' expected: \'Logical\'", "3Suspicious operand type: \'UnKnown\' expected: \'Numeric\'", - "0Meaningless use of expression: \'%s\'" + "0Meaningless use of expression: \'%s\'", + "1Unreachable code" }; /* Table with reserved functions names @@ -383,11 +407,11 @@ int main( int argc, char * argv[] ) break; default: - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADOPTION, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADOPTION, argv[ iArg ], NULL ); } } else - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADOPTION, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADOPTION, argv[ iArg ], NULL ); break; case 'g': @@ -410,7 +434,7 @@ int main( int argc, char * argv[] ) break; default: - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADOPTION, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADOPTION, argv[ iArg ], NULL ); } break; @@ -532,7 +556,7 @@ int main( int argc, char * argv[] ) { /*there is -w<0,1,2,3> probably */ hb_comp_iWarnings = argv[ iArg ][ 2 ] - '0'; if( hb_comp_iWarnings < 0 || hb_comp_iWarnings > 3 ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADOPTION, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADOPTION, argv[ iArg ], NULL ); } break; @@ -563,7 +587,7 @@ int main( int argc, char * argv[] ) break; default: - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADOPTION, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADOPTION, argv[ iArg ], NULL ); break; } } @@ -573,13 +597,13 @@ int main( int argc, char * argv[] ) else { if( hb_comp_pFileName ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADPARAM, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADPARAM, argv[ iArg ], NULL ); else { hb_comp_pFileName = hb_fsFNameSplit( argv[ iArg ] ); if( ! hb_comp_pFileName->szName ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_BADFILENAME, argv[ iArg ], NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_BADFILENAME, argv[ iArg ], NULL ); } } } @@ -596,7 +620,7 @@ int main( int argc, char * argv[] ) yyppo = fopen( szPpoName, "w" ); if( ! yyppo ) { - hb_compGenError( hb_comp_szCErrors, 'E', ERR_CREATE_PPO, szPpoName, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_CREATE_PPO, szPpoName, NULL ); return iStatus; } } @@ -681,6 +705,14 @@ int main( int argc, char * argv[] ) } } + hb_compFixReturns(); /* fix all previous function returns offsets */ + if( ! hb_comp_bQuiet ) + { + if( ! hb_comp_bStartProc ) + --hb_comp_iFunctionCnt; + printf( "\rLines %i, Functions/Procedures %i\n", hb_comp_iLine, hb_comp_iFunctionCnt ); + } + switch( s_iLanguage ) { case LANG_C: @@ -900,6 +932,163 @@ void EXTERNAL_LINKAGE close_on_exit( void ) } } + + +/* ------------------------------------------------------------------------- */ + +#define IS_PATH_SEP( c ) ( strchr( OS_PATH_DELIMITER_LIST, ( c ) ) != NULL ) + +/* Split given filename into path, name and extension */ +PHB_FNAME hb_fsFNameSplit( char * szFileName ) +{ + PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); + + int iLen = strlen( szFileName ); + int iSlashPos; + int iDotPos; + int iPos; + + pFileName->szPath = + pFileName->szName = + pFileName->szExtension = NULL; + + iSlashPos = iLen - 1; + iPos = 0; + + while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) ) + --iSlashPos; + + if( iSlashPos == 0 ) + { + /* root path -> \filename */ + pFileName->szBuffer[ 0 ] = OS_PATH_DELIMITER; + pFileName->szBuffer[ 1 ] = '\0'; + pFileName->szPath = pFileName->szBuffer; + iPos = 2; /* first free position after the slash */ + } + else if( iSlashPos > 0 ) + { + /* If we are after a drive letter let's keep the following backslash */ + if( IS_PATH_SEP( ':' ) && + ( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) ) + { + /* path with separator -> d:\path\filename or d:path\filename */ + memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 ); + pFileName->szBuffer[ iSlashPos + 1 ] = '\0'; + iPos = iSlashPos + 2; /* first free position after the slash */ + } + else + { + /* path with separator -> path\filename */ + memcpy( pFileName->szBuffer, szFileName, iSlashPos ); + pFileName->szBuffer[ iSlashPos ] = '\0'; + iPos = iSlashPos + 1; /* first free position after the slash */ + } + + pFileName->szPath = pFileName->szBuffer; + } + + iDotPos = iLen - 1; + while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' ) + --iDotPos; + + if( ( iDotPos - iSlashPos ) > 1 ) + { + /* the dot was found + * and there is at least one character between a slash and a dot + */ + if( iDotPos == iLen - 1 ) + { + /* the dot is the last character - use it as extension name */ + pFileName->szExtension = pFileName->szBuffer + iPos; + pFileName->szBuffer[ iPos++ ] = '.'; + pFileName->szBuffer[ iPos++ ] = '\0'; + } + else + { + pFileName->szExtension = pFileName->szBuffer + iPos; + /* copy rest of the string with terminating ZERO character */ + memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos ); + iPos += iLen - iDotPos; + } + } + else + /* there is no dot in the filename or it is '.filename' */ + iDotPos = iLen; + + if( ( iDotPos - iSlashPos - 1 ) > 0 ) + { + pFileName->szName = pFileName->szBuffer + iPos; + memcpy( pFileName->szName, szFileName + iSlashPos + 1, iDotPos - iSlashPos - 1 ); + pFileName->szName[ iDotPos - iSlashPos - 1 ] = '\0'; + } + +/* DEBUG + printf( "\nFilename: %s\n", szFileName ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); +*/ + + return pFileName; +} + +/* This function joins path, name and extension into a string with a filename */ +char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) +{ + if( pFileName->szPath && pFileName->szPath[ 0 ] ) + { + /* we have not empty path specified */ + int iLen = strlen( pFileName->szPath ); + + strcpy( szFileName, pFileName->szPath ); + + /* if the path is a root directory then we don't need to add path separator */ + if( !( IS_PATH_SEP( pFileName->szPath[ 0 ] ) && pFileName->szPath[ 0 ] == '\0' ) ) + { + /* add the path separator only in cases: + * when a name doesn't start with it + * when the path doesn't end with it + */ + if( !( IS_PATH_SEP( pFileName->szName[ 0 ] ) || IS_PATH_SEP( pFileName->szPath[ iLen-1 ] ) ) ) + { + szFileName[ iLen++ ] = OS_PATH_DELIMITER; + szFileName[ iLen ] = '\0'; + } + } + if( pFileName->szName ) + strcpy( szFileName + iLen, pFileName->szName ); + } + else + { + if( pFileName->szName ) + strcpy( szFileName, pFileName->szName ); + } + + if( pFileName->szExtension ) + { + int iLen = strlen( szFileName ); + + if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen - 1 ] == '.') ) + { + /* add extension separator only when extansion doesn't contain it */ + szFileName[ iLen++ ] = '.'; + szFileName[ iLen ] = '\0'; + } + strcpy( szFileName + iLen, pFileName->szExtension ); + } + +/* DEBUG + printf( "\nMERGE:\n" ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); + printf( "\nFilename result: %s\n", szFileName ); +*/ + + return szFileName; +} + /* ------------------------------------------------------------------------- */ void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on failure */ @@ -907,7 +1096,7 @@ void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on fail void * pMem = malloc( ulSize ); if( ! pMem ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_MEMALLOC, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_MEMALLOC, NULL, NULL ); return pMem; } @@ -917,7 +1106,7 @@ void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */ void * pResult = realloc( pMem, ulSize ); if( ! pResult ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_MEMREALLOC, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_MEMREALLOC, NULL, NULL ); return pResult; } @@ -927,7 +1116,7 @@ void hb_xfree( void * pMem ) /* frees fixed memory */ if( pMem ) free( pMem ); else - hb_compGenError( hb_comp_szCErrors, 'E', ERR_MEMFREE, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_MEMFREE, NULL, NULL ); } char * yy_strupr( char * p ) @@ -957,14 +1146,15 @@ char * yy_strdup( char * p ) void hb_compGenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { if( hb_comp_files.pLast != NULL && hb_comp_files.pLast->szFileName != NULL ) - printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, iLine ); + printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_iLine ); printf( "Error %c%04i ", cPrefix, iError ); printf( _szErrors[ iError - 1 ], szError1, szError2 ); printf( "\n" ); hb_comp_iErrorCount++; -/* exit( EXIT_FAILURE ); */ + if( cPrefix == 'F' ) /* fatal error - exit immediately */ + exit( EXIT_FAILURE ); } void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2) @@ -973,7 +1163,7 @@ void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * if( (szText[ 0 ] - '0') <= hb_comp_iWarnings ) { - printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, iLine ); + printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_iLine ); printf( "Warning %c%04i ", cPrefix, iWarning ); printf( szText + 1, szWarning1, szWarning2 ); printf( "\n" ); @@ -1090,7 +1280,7 @@ static FUNCINFO _StdFun[] = { 0 , 0, 0 } }; -void hb_compCheckArgs( char * szFuncCall, int iArgs ) +void hb_compFunCallCheck( char * szFuncCall, int iArgs ) { FUNCINFO * f = _StdFun; int i = 0; @@ -1141,9 +1331,9 @@ void hb_compCheckArgs( char * szFuncCall, int iArgs ) * as they have to be placed on the symbol table later than the first * public symbol */ -PFUNCTION hb_compAddFunCall( char * szFunctionName ) +PFUNCTION hb_compFunCallAdd( char * szFunctionName ) { - PFUNCTION pFunc = FunctionNew( szFunctionName, 0 ); + PFUNCTION pFunc = hb_compFunctionNew( szFunctionName, 0 ); if( ! hb_comp_funcalls.iCount ) { @@ -1165,7 +1355,7 @@ PFUNCTION hb_compAddFunCall( char * szFunctionName ) * as they have to be placed on the symbol table later than the first * public symbol */ -void hb_compAddExtern( char * szExternName ) /* defines a new extern name */ +void hb_compExternAdd( char * szExternName ) /* defines a new extern name */ { PEXTERN pExtern = ( PEXTERN ) hb_xgrab( sizeof( _EXTERN ) ), pLast; @@ -1181,9 +1371,10 @@ void hb_compAddExtern( char * szExternName ) /* defines a new extern name */ pLast = pLast->pNext; pLast->pNext = pExtern; } + hb_comp_bExternal = TRUE; } -void hb_compAddVar( char * szVarName, char cValueType ) +void hb_compVariableAdd( char * szVarName, char cValueType ) { PVAR pVar, pLastVar; PFUNCTION pFunc = hb_comp_functions.pLast; @@ -1192,8 +1383,9 @@ void hb_compAddVar( char * szVarName, char cValueType ) { /* Variable declaration is outside of function/procedure body. In this case only STATIC and PARAMETERS variables are allowed. */ - --iLine; + --hb_comp_iLine; hb_compGenError( hb_comp_szCErrors, 'E', ERR_OUTSIDE, NULL, NULL ); + return; } /* check if we are declaring local/static variable after some @@ -1202,7 +1394,7 @@ void hb_compAddVar( char * szVarName, char cValueType ) */ if( ( hb_comp_functions.pLast->bFlags & FUN_STATEMENTS ) && !( hb_comp_iVarScope == VS_FIELD || ( hb_comp_iVarScope & VS_MEMVAR ) ) ) { - --iLine; + --hb_comp_iLine; hb_compGenError( hb_comp_szCErrors, 'E', ERR_FOLLOWS_EXEC, ( hb_comp_iVarScope == VS_LOCAL ? "LOCAL" : "STATIC" ), NULL ); } @@ -1217,15 +1409,15 @@ void hb_compAddVar( char * szVarName, char cValueType ) if( pFunc->szName ) { /* variable defined in a function/procedure */ - CheckDuplVars( pFunc->pFields, szVarName, hb_comp_iVarScope ); - CheckDuplVars( pFunc->pStatics, szVarName, hb_comp_iVarScope ); + hb_compCheckDuplVars( pFunc->pFields, szVarName, hb_comp_iVarScope ); + hb_compCheckDuplVars( pFunc->pStatics, szVarName, hb_comp_iVarScope ); if( !( hb_comp_iVarScope == VS_PRIVATE || hb_comp_iVarScope == VS_PUBLIC ) ) - CheckDuplVars( pFunc->pMemvars, szVarName, hb_comp_iVarScope ); + hb_compCheckDuplVars( pFunc->pMemvars, szVarName, hb_comp_iVarScope ); } else /* variable defined in a codeblock */ hb_comp_iVarScope = VS_PARAMETER; - CheckDuplVars( pFunc->pLocals, szVarName, hb_comp_iVarScope ); + hb_compCheckDuplVars( pFunc->pLocals, szVarName, hb_comp_iVarScope ); pVar = ( PVAR ) hb_xgrab( sizeof( VAR ) ); pVar->szName = szVarName; @@ -1269,9 +1461,9 @@ void hb_compAddVar( char * szVarName, char cValueType ) bNewParameter = TRUE; } - pSym = hb_compGetSymbol( szVarName, &wPos ); /* check if symbol exists already */ + pSym = hb_compSymbolFind( szVarName, &wPos ); /* check if symbol exists already */ if( ! pSym ) - pSym = hb_compAddSymbol( yy_strdup( szVarName ), &wPos ); + pSym = hb_compSymbolAdd( yy_strdup( szVarName ), &wPos ); pSym->cScope |= VS_MEMVAR; hb_compGenPCode3( HB_P_PARAMETER, HB_LOBYTE( wPos ), HB_HIBYTE( wPos ) ); hb_compGenPCode1( HB_LOBYTE( hb_comp_functions.pLast->wParamNum ) ); @@ -1306,21 +1498,21 @@ void hb_compAddVar( char * szVarName, char cValueType ) break; case VS_PRIVATE: { - hb_compPushSymbol( yy_strdup( "__MVPRIVATE" ), 1); + hb_compGenPushSymbol( yy_strdup( "__MVPRIVATE" ), 1); hb_compGenPushNil(); - hb_compPushSymbol( yy_strdup( szVarName ), 0 ); - hb_compGenDoProc( 1 ); - pSym = hb_compGetSymbol( szVarName, NULL ); + hb_compGenPushSymbol( yy_strdup( szVarName ), 0 ); + hb_compGenPCode3( HB_P_DO, 1, 0 ); + pSym = hb_compSymbolFind( szVarName, NULL ); pSym->cScope |= VS_MEMVAR; } break; case VS_PUBLIC: { - hb_compPushSymbol( yy_strdup( "__MVPUBLIC" ), 1); + hb_compGenPushSymbol( yy_strdup( "__MVPUBLIC" ), 1); hb_compGenPushNil(); - hb_compPushSymbol( yy_strdup( szVarName ), 0 ); - hb_compGenDoProc( 1 ); - pSym = hb_compGetSymbol( szVarName, NULL ); + hb_compGenPushSymbol( yy_strdup( szVarName ), 0 ); + hb_compGenPCode3( HB_P_DO, 1, 0 ); + pSym = hb_compSymbolFind( szVarName, NULL ); pSym->cScope |= VS_MEMVAR; } break; @@ -1389,7 +1581,7 @@ void hb_compAddVar( char * szVarName, char cValueType ) } } -PCOMSYMBOL hb_compAddSymbol( char * szSymbolName, USHORT * pwPos ) +PCOMSYMBOL hb_compSymbolAdd( char * szSymbolName, USHORT * pwPos ) { PCOMSYMBOL pSym = ( PCOMSYMBOL ) hb_xgrab( sizeof( COMSYMBOL ) ); @@ -1417,30 +1609,17 @@ PCOMSYMBOL hb_compAddSymbol( char * szSymbolName, USHORT * pwPos ) return pSym; } -void Duplicate( void ) -{ - hb_compGenPCode1( HB_P_DUPLICATE ); -} - -void DupPCode( ULONG ulStart ) /* duplicates the current generated pcode from an offset */ -{ - ULONG w, wEnd = hb_comp_functions.pLast->lPCodePos - ulStart; - - for( w = 0; w < wEnd; w++ ) - hb_compGenPCode1( hb_comp_functions.pLast->pCode[ ulStart + w ] ); -} - /* * Function generates passed pcode for passed database field */ -void FieldPCode( BYTE bPCode, char * szVarName ) +void hb_compFieldGenPCode( BYTE bPCode, char * szVarName ) { USHORT wVar; PCOMSYMBOL pVar; - pVar = hb_compGetSymbol( szVarName, &wVar ); + pVar = hb_compSymbolFind( szVarName, &wVar ); if( ! pVar ) - pVar = hb_compAddSymbol( szVarName, &wVar ); + pVar = hb_compSymbolAdd( szVarName, &wVar ); pVar->cScope |= VS_MEMVAR; hb_compGenPCode3( bPCode, HB_LOBYTE( wVar ), HB_HIBYTE( wVar ) ); } @@ -1448,7 +1627,7 @@ void FieldPCode( BYTE bPCode, char * szVarName ) /* * This function creates and initialises the _FUNC structure */ -PFUNCTION FunctionNew( char * szName, HB_SYMBOLSCOPE cScope ) +static PFUNCTION hb_compFunctionNew( char * szName, HB_SYMBOLSCOPE cScope ) { PFUNCTION pFunc; @@ -1469,8 +1648,6 @@ PFUNCTION FunctionNew( char * szName, HB_SYMBOLSCOPE cScope ) pFunc->pOwner = NULL; pFunc->bFlags = 0; - hb_comp_lLastPushPos = -1; - return pFunc; } @@ -1480,21 +1657,21 @@ PFUNCTION FunctionNew( char * szName, HB_SYMBOLSCOPE cScope ) * cScope - scope of a function * iType - FUN_PROCEDURE if a procedure or 0 */ -void hb_compFunDef( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ) +void hb_compFunctionAdd( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ) { PCOMSYMBOL pSym; PFUNCTION pFunc; char * szFunction; - FixReturns(); /* fix all previous function returns offsets */ + hb_compFixReturns(); /* fix all previous function returns offsets */ - pFunc = GetFunction( szFunName ); + pFunc = hb_compFunctionFind( szFunName ); if( pFunc ) { /* The name of a function/procedure is already defined */ if( ( pFunc != hb_comp_functions.pFirst ) || hb_comp_bStartProc ) /* it is not a starting procedure that was automatically created */ - hb_compGenError( hb_comp_szCErrors, 'E', ERR_FUNC_DUPL, szFunName, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_FUNC_DUPL, szFunName, NULL ); } szFunction = RESERVED_FUNC( szFunName ); @@ -1508,17 +1685,17 @@ void hb_compFunDef( char * szFunName, HB_SYMBOLSCOPE cScope, int iType ) hb_comp_iFunctionCnt++; - pSym = hb_compGetSymbol( szFunName, NULL ); + pSym = hb_compSymbolFind( szFunName, NULL ); if( ! pSym ) /* there is not a symbol on the symbol table for this function name */ - pSym = hb_compAddSymbol( szFunName, NULL ); + pSym = hb_compSymbolAdd( szFunName, NULL ); if( cScope != FS_PUBLIC ) /* pSym->cScope = FS_PUBLIC; */ /* else */ pSym->cScope |= cScope; /* we may have a non public function and a object message */ - pFunc = FunctionNew( szFunName, cScope ); + pFunc = hb_compFunctionNew( szFunName, cScope ); pFunc->bFlags |= iType; if( hb_comp_functions.iCount == 0 ) @@ -1553,27 +1730,8 @@ void hb_compGenPushFunRef( char * szName ) HB_SYMBOL_UNUSED( szName ); /* TODO: */ } -void * GenElseIf( void * pFirst, ULONG ulOffset ) -{ - PELSEIF pElseIf = ( PELSEIF ) hb_xgrab( sizeof( _ELSEIF ) ), pLast; - pElseIf->ulOffset = ulOffset; - pElseIf->pNext = 0; - - if( ! pFirst ) - pFirst = pElseIf; - else - { - pLast = ( PELSEIF ) pFirst; - while( pLast->pNext ) - pLast = pLast->pNext; - pLast->pNext = pElseIf; - } - return pFirst; -} - - -PFUNCTION KillFunction( PFUNCTION pFunc ) +PFUNCTION hb_compFunctionKill( PFUNCTION pFunc ) { PFUNCTION pNext = pFunc->pNext; PVAR pVar; @@ -1623,14 +1781,14 @@ PFUNCTION KillFunction( PFUNCTION pFunc ) } hb_xfree( ( void * ) pFunc->pCode ); -/* hb_xfree( ( void * ) pFunc->szName ); The name will be released in KillSymbol() */ +/* hb_xfree( ( void * ) pFunc->szName ); The name will be released in hb_compSymbolKill() */ hb_xfree( ( void * ) pFunc ); return pNext; } -PCOMSYMBOL KillSymbol( PCOMSYMBOL pSym ) +PCOMSYMBOL hb_compSymbolKill( PCOMSYMBOL pSym ) { PCOMSYMBOL pNext = pSym->pNext; @@ -1642,28 +1800,28 @@ PCOMSYMBOL KillSymbol( PCOMSYMBOL pSym ) void hb_compGenBreak( void ) { - hb_compPushSymbol( yy_strdup("BREAK"), 1 ); + hb_compGenPushSymbol( yy_strdup("BREAK"), 1 ); hb_compGenPushNil(); } -void hb_compGenExterns( void ) /* generates the symbols for the EXTERN names */ +void hb_compExternGen( void ) /* generates the symbols for the EXTERN names */ { PEXTERN pDelete; if( hb_comp_bDebugInfo ) - hb_compAddExtern( yy_strdup( "__DBGENTRY" ) ); + hb_compExternAdd( yy_strdup( "__DBGENTRY" ) ); while( hb_comp_pExterns ) { - if( hb_compGetSymbol( hb_comp_pExterns->szName, NULL ) ) + if( hb_compSymbolFind( hb_comp_pExterns->szName, NULL ) ) { - if( ! GetFuncall( hb_comp_pExterns->szName ) ) - hb_compAddFunCall( hb_comp_pExterns->szName ); + if( ! hb_compFunCallFind( hb_comp_pExterns->szName ) ) + hb_compFunCallAdd( hb_comp_pExterns->szName ); } else { - hb_compAddSymbol( hb_comp_pExterns->szName, NULL ); - hb_compAddFunCall( hb_comp_pExterns->szName ); + hb_compSymbolAdd( hb_comp_pExterns->szName, NULL ); + hb_compFunCallAdd( hb_comp_pExterns->szName ); } pDelete = hb_comp_pExterns; hb_comp_pExterns = hb_comp_pExterns->pNext; @@ -1671,7 +1829,7 @@ void hb_compGenExterns( void ) /* generates the symbols for the EXTERN names */ } } -PFUNCTION GetFuncall( char * szFunctionName ) /* returns a previously called defined function */ +PFUNCTION hb_compFunCallFind( char * szFunctionName ) /* returns a previously called defined function */ { PFUNCTION pFunc = hb_comp_funcalls.pFirst; @@ -1690,7 +1848,7 @@ PFUNCTION GetFuncall( char * szFunctionName ) /* returns a previously called def return NULL; } -PFUNCTION GetFunction( char * szFunctionName ) /* returns a previously defined function */ +PFUNCTION hb_compFunctionFind( char * szFunctionName ) /* returns a previously defined function */ { PFUNCTION pFunc = hb_comp_functions.pFirst; @@ -1709,7 +1867,7 @@ PFUNCTION GetFunction( char * szFunctionName ) /* returns a previously defined f return NULL; } -PVAR GetVar( PVAR pVars, USHORT wOrder ) /* returns variable if defined or zero */ +PVAR hb_compVariableFind( PVAR pVars, USHORT wOrder ) /* returns variable if defined or zero */ { USHORT w = 1; @@ -1719,7 +1877,7 @@ PVAR GetVar( PVAR pVars, USHORT wOrder ) /* returns variable if defined or zero return pVars; } -USHORT GetVarPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a variable if defined or zero */ +USHORT hb_compVariableGetPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a variable if defined or zero */ { USHORT wVar = 1; @@ -1747,18 +1905,18 @@ USHORT GetVarPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a v return 0; } -int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if defined or zero */ +static int hb_compLocalVarGetPos( char * szVarName ) /* returns the order + 1 of a variable if defined or zero */ { int iVar = 0; PFUNCTION pFunc = hb_comp_functions.pLast; if( pFunc->szName ) /* we are in a function/procedure -we don't need any tricks */ - return GetVarPos( pFunc->pLocals, szVarName ); + return hb_compVariableGetPos( pFunc->pLocals, szVarName ); else { /* we are in a codeblock */ - iVar = GetVarPos( pFunc->pLocals, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pLocals, szVarName ); if( iVar == 0 ) { /* this is not a current codeblock parameter @@ -1770,7 +1928,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if pFunc = pFunc->pOwner; while( pFunc ) { - iVar = GetVarPos( pFunc->pLocals, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pLocals, szVarName ); if( iVar ) { if( pFunc->pOwner ) @@ -1780,6 +1938,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if * the current codeblock is defined */ hb_compGenError( hb_comp_szCErrors, 'E', ERR_OUTER_VAR, szVarName, NULL ); + return iVar; } else { @@ -1798,7 +1957,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if * outside of a function where it was defined when the local * variables are not accessible. */ - iVar = -GetVarPos( pOutBlock->pStatics, szVarName ); + iVar = -hb_compVariableGetPos( pOutBlock->pStatics, szVarName ); if( iVar == 0 ) { /* this variable was not referenced yet - add it to the list */ @@ -1855,7 +2014,7 @@ int GetStaticVarPos( char * szVarName ) */ if( pFunc->pOwner ) pFunc = pFunc->pOwner; /* we are in the static variable definition state */ - iPos = GetVarPos( pFunc->pStatics, szVarName ); + iPos = hb_compVariableGetPos( pFunc->pStatics, szVarName ); if( iPos ) return iPos + pFunc->iStaticsBase; @@ -1865,7 +2024,7 @@ int GetStaticVarPos( char * szVarName ) */ if( !hb_comp_bStartProc ) { - iPos = GetVarPos( hb_comp_functions.pFirst->pStatics, szVarName ); + iPos = hb_compVariableGetPos( hb_comp_functions.pFirst->pStatics, szVarName ); if( iPos ) return iPos; } @@ -1875,13 +2034,13 @@ int GetStaticVarPos( char * szVarName ) /* Checks if passed variable name is declared as FIELD * Returns 0 if not found in FIELD list or its position in this list if found */ -int GetFieldVarPos( char * szVarName, PFUNCTION pFunc ) +static int hb_compFieldGetVarPos( char * szVarName, PFUNCTION pFunc ) { int iVar; if( pFunc->szName ) /* we are in a function/procedure -we don't need any tricks */ - iVar = GetVarPos( pFunc->pFields, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pFields, szVarName ); else { /* we have to check the list of nested codeblock up to a function @@ -1889,7 +2048,7 @@ int GetFieldVarPos( char * szVarName, PFUNCTION pFunc ) */ while( pFunc->pOwner ) pFunc = pFunc->pOwner; - iVar = GetVarPos( pFunc->pFields, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pFields, szVarName ); } return iVar; } @@ -1897,13 +2056,13 @@ int GetFieldVarPos( char * szVarName, PFUNCTION pFunc ) /* Checks if passed variable name is declared as MEMVAR * Returns 0 if not found in MEMVAR list or its position in this list if found */ -int GetMemvarPos( char * szVarName, PFUNCTION pFunc ) +static int hb_compMemvarGetPos( char * szVarName, PFUNCTION pFunc ) { int iVar; if( pFunc->szName ) /* we are in a function/procedure -we don't need any tricks */ - iVar = GetVarPos( pFunc->pMemvars, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pMemvars, szVarName ); else { /* we have to check the list of nested codeblock up to a function @@ -1911,12 +2070,12 @@ int GetMemvarPos( char * szVarName, PFUNCTION pFunc ) */ while( pFunc->pOwner ) pFunc = pFunc->pOwner; - iVar = GetVarPos( pFunc->pMemvars, szVarName ); + iVar = hb_compVariableGetPos( pFunc->pMemvars, szVarName ); } return iVar; } -USHORT FixSymbolPos( USHORT wCompilePos ) +USHORT hb_compSymbolFixPos( USHORT wCompilePos ) { return ( hb_comp_bStartProc ? wCompilePos - 1 : wCompilePos - 2 ); } @@ -1925,7 +2084,7 @@ USHORT FixSymbolPos( USHORT wCompilePos ) /* returns a symbol pointer from the symbol table * and sets its position in the symbol table */ -PCOMSYMBOL hb_compGetSymbol( char * szSymbolName, USHORT * pwPos ) +PCOMSYMBOL hb_compSymbolFind( char * szSymbolName, USHORT * pwPos ) { PCOMSYMBOL pSym = hb_comp_symbols.pFirst; USHORT wCnt = 1; @@ -1954,7 +2113,7 @@ PCOMSYMBOL hb_compGetSymbol( char * szSymbolName, USHORT * pwPos ) return NULL; } -PCOMSYMBOL hb_compGetSymbolOrd( USHORT wSymbol ) /* returns a symbol based on its index on the symbol table */ +PCOMSYMBOL hb_compSymbolGetPos( USHORT wSymbol ) /* returns a symbol based on its index on the symbol table */ { PCOMSYMBOL pSym = hb_comp_symbols.pFirst; USHORT w = 1; @@ -1965,7 +2124,7 @@ PCOMSYMBOL hb_compGetSymbolOrd( USHORT wSymbol ) /* returns a symbol based on return pSym; } -USHORT GetFunctionPos( char * szFunctionName ) /* return 0 if not found or order + 1 */ +USHORT hb_compFunctionGetPos( char * szFunctionName ) /* return 0 if not found or order + 1 */ { PFUNCTION pFunc = hb_comp_functions.pFirst; USHORT wFunction = hb_comp_bStartProc; @@ -1988,17 +2147,12 @@ USHORT GetFunctionPos( char * szFunctionName ) /* return 0 if not found or order return 0; } -void Inc( void ) -{ - hb_compGenPCode1( HB_P_INC ); -} - ULONG hb_compGenJump( LONG lOffset ) { /* TODO: We need a longer offset (longer then two bytes) */ if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_JUMP_TOO_LONG, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_JUMP_TOO_LONG, NULL, NULL ); hb_compGenPCode3( HB_P_JUMP, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); @@ -2010,7 +2164,7 @@ ULONG hb_compGenJumpFalse( LONG lOffset ) /* TODO: We need a longer offset (longer then two bytes) */ if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_JUMP_TOO_LONG, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_JUMP_TOO_LONG, NULL, NULL ); hb_compGenPCode3( HB_P_JUMPFALSE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); @@ -2025,7 +2179,7 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo ) /* TODO: We need a longer offset (longer then two bytes) */ if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_JUMP_TOO_LONG, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_JUMP_TOO_LONG, NULL, NULL ); pCode[ ( ULONG ) ulFrom ] = HB_LOBYTE( lOffset ); pCode[ ( ULONG ) ulFrom + 1 ] = HB_HIBYTE( lOffset ); @@ -2041,47 +2195,62 @@ ULONG hb_compGenJumpTrue( LONG lOffset ) /* TODO: We need a longer offset (longer then two bytes) */ if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_JUMP_TOO_LONG, NULL, NULL ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_JUMP_TOO_LONG, NULL, NULL ); hb_compGenPCode3( HB_P_JUMPTRUE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); return hb_comp_functions.pLast->lPCodePos - 2; } -void Line( void ) /* generates the pcode with the currently compiled source code line */ + +void hb_compLinePush( void ) /* generates the pcode with the currently compiled source code line */ { if( hb_comp_bLineNumbers && ! hb_comp_bDontGenLineNum ) { if( ( ( hb_comp_functions.pLast->lPCodePos - hb_comp_ulLastLinePos ) > 3 ) || hb_comp_bDebugInfo ) { hb_comp_ulLastLinePos = hb_comp_functions.pLast->lPCodePos; - hb_compGenPCode3( HB_P_LINE, HB_LOBYTE( iLine ), HB_HIBYTE( iLine ) ); + hb_compGenPCode3( HB_P_LINE, HB_LOBYTE( hb_comp_iLine ), HB_HIBYTE( hb_comp_iLine ) ); } else { - hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +1 ] = HB_LOBYTE( iLine ); - hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +2 ] = HB_HIBYTE( iLine ); + hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +1 ] = HB_LOBYTE( hb_comp_iLine ); + hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +2 ] = HB_HIBYTE( hb_comp_iLine ); } } + if( hb_comp_functions.pLast->bFlags & FUN_BREAK_CODE ) + { + /* previous line contained RETURN/BREAK/LOOP/EXIT statement */ + hb_compGenWarning( hb_comp_szCWarnings, 'W', WARN_UNREACHABLE, NULL, NULL ); + } hb_comp_bDontGenLineNum = FALSE; - hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; /* clear RETURN flag */ - hb_comp_lLastPushPos = -1; + /* clear RETURN/BREAK flag */ + hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); } /* Generates the pcode with the currently compiled source code line * if debug code was requested only */ -void LineDebug( void ) +void hb_compLinePushIfDebugger( void ) { if( hb_comp_bDebugInfo ) - Line(); + hb_compLinePush(); else - hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; /* clear RETURN flag */ + { + if( hb_comp_functions.pLast->bFlags & FUN_BREAK_CODE ) + { + /* previous line contained RETURN/BREAK/LOOP/EXIT statement */ + hb_compGenWarning( hb_comp_szCWarnings, 'W', WARN_UNREACHABLE, NULL, NULL ); + } + hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); /* clear RETURN flag */ + } + } -void LineBody( void ) /* generates the pcode with the currently compiled source code line */ +void hb_compLinePushIfInside( void ) /* generates the pcode with the currently compiled source code line */ { - /* This line can be placed inside a procedure or function only */ - /* except EXTERNAL */ + /* This line can be placed inside a procedure or function only + * except EXTERNAL + */ if( ! hb_comp_bExternal ) { hb_comp_bExternal = FALSE; @@ -2092,13 +2261,13 @@ void LineBody( void ) /* generates the pcode with the currently compiled source } hb_comp_functions.pLast->bFlags |= FUN_STATEMENTS; - Line(); + hb_compLinePush(); } /* * Function generates passed pcode for passed variable name */ -void VariablePCode( BYTE bPCode, char * szVarName ) +static void hb_compVariableGenPCode( BYTE bPCode, char * szVarName ) { USHORT wVar; PCOMSYMBOL pSym; @@ -2107,12 +2276,12 @@ void VariablePCode( BYTE bPCode, char * szVarName ) /* Check if it is a FIELD declared in current function */ - wVar = GetFieldVarPos( szVarName, hb_comp_functions.pLast ); + wVar = hb_compFieldGetVarPos( szVarName, hb_comp_functions.pLast ); if( wVar == 0 ) { /* Check if it is a MEMVAR declared in current function */ - wVar = GetMemvarPos( szVarName, hb_comp_functions.pLast ); + wVar = hb_compMemvarGetPos( szVarName, hb_comp_functions.pLast ); if( wVar ) iType = VS_MEMVAR; } @@ -2127,10 +2296,10 @@ void VariablePCode( BYTE bPCode, char * szVarName ) */ if( wVar == 0 && ! hb_comp_bStartProc ) { - wVar = GetFieldVarPos( szVarName, hb_comp_functions.pFirst ); + wVar = hb_compFieldGetVarPos( szVarName, hb_comp_functions.pFirst ); if( wVar == 0 ) { - wVar = GetMemvarPos( szVarName, hb_comp_functions.pFirst ); + wVar = hb_compMemvarGetPos( szVarName, hb_comp_functions.pFirst ); if( wVar ) iType = VS_MEMVAR; } @@ -2167,7 +2336,7 @@ void VariablePCode( BYTE bPCode, char * szVarName ) if( iType == VS_FIELD ) { /* variable is declared using FIELD statement */ - PVAR pField = GetVar( pOwnerFunc->pFields, wVar ); + PVAR pField = hb_compVariableFind( pOwnerFunc->pFields, wVar ); if( pField->szAlias ) { /* the alias was specified in FIELD declaration */ @@ -2181,7 +2350,7 @@ void VariablePCode( BYTE bPCode, char * szVarName ) /* * Push alias symbol before the field symbol */ - hb_compPushSymbol( yy_strdup( pField->szAlias ), 0 ); + hb_compGenPushSymbol( yy_strdup( pField->szAlias ), 0 ); } else { /* this is unaliased field */ @@ -2205,9 +2374,9 @@ void VariablePCode( BYTE bPCode, char * szVarName ) /* Check if this variable name is placed into the symbol table */ - pSym = hb_compGetSymbol( szVarName, &wVar ); + pSym = hb_compSymbolFind( szVarName, &wVar ); if( ! pSym ) - pSym = hb_compAddSymbol( szVarName, &wVar ); + pSym = hb_compSymbolAdd( szVarName, &wVar ); pSym->cScope |= VS_MEMVAR; hb_compGenPCode3( bPCode, HB_LOBYTE( wVar ), HB_HIBYTE( wVar ) ); } @@ -2215,16 +2384,16 @@ void VariablePCode( BYTE bPCode, char * szVarName ) /* * Function generates passed pcode for passed memvar name */ -void MemvarPCode( BYTE bPCode, char * szVarName ) +void hb_compMemvarGenPCode( BYTE bPCode, char * szVarName ) { USHORT wVar; PCOMSYMBOL pSym; /* Check if this variable name is placed into the symbol table */ - pSym = hb_compGetSymbol( szVarName, &wVar ); + pSym = hb_compSymbolFind( szVarName, &wVar ); if( ! pSym ) - pSym = hb_compAddSymbol( szVarName, &wVar ); + pSym = hb_compSymbolAdd( szVarName, &wVar ); pSym->cScope |= VS_MEMVAR; hb_compGenPCode3( bPCode, HB_LOBYTE( wVar ), HB_HIBYTE( wVar ) ); } @@ -2232,10 +2401,10 @@ void MemvarPCode( BYTE bPCode, char * szVarName ) void hb_compGenMessage( char * szMsgName ) /* sends a message to an object */ { USHORT wSym; - PCOMSYMBOL pSym = hb_compGetSymbol( szMsgName, &wSym ); + PCOMSYMBOL pSym = hb_compSymbolFind( szMsgName, &wSym ); if( ! pSym ) /* the symbol was not found on the symbol table */ - pSym = hb_compAddSymbol( szMsgName, &wSym ); + pSym = hb_compSymbolAdd( szMsgName, &wSym ); pSym->cScope |= FS_MESSAGE; hb_compGenPCode3( HB_P_MESSAGE, HB_LOBYTE( wSym ), HB_HIBYTE( wSym ) ); } @@ -2254,7 +2423,7 @@ void hb_compGenPopVar( char * szVarName ) /* generates the pcode to pop a value { int iVar; - iVar = GetLocalVarPos( szVarName ); + iVar = hb_compLocalVarGetPos( szVarName ); if( iVar ) hb_compGenPCode3( HB_P_POPLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); else @@ -2267,7 +2436,7 @@ void hb_compGenPopVar( char * szVarName ) /* generates the pcode to pop a value } else { - VariablePCode( HB_P_POPVARIABLE, szVarName ); + hb_compVariableGenPCode( HB_P_POPVARIABLE, szVarName ); } } } @@ -2286,7 +2455,7 @@ void hb_compGenPopAliasedVar( char * szVarName, { if( szAlias[ 0 ] == 'M' && szAlias[ 1 ] == '\0' ) { /* M->variable */ - MemvarPCode( HB_P_POPMEMVAR, szVarName ); + hb_compMemvarGenPCode( HB_P_POPMEMVAR, szVarName ); } else { @@ -2295,7 +2464,7 @@ void hb_compGenPopAliasedVar( char * szVarName, iCmp = strncmp( szAlias, "MEMVAR", strlen( szAlias ) ); if( iCmp == 0 ) { /* MEMVAR-> or MEMVA-> or MEMV-> */ - MemvarPCode( HB_P_POPMEMVAR, szVarName ); + hb_compMemvarGenPCode( HB_P_POPMEMVAR, szVarName ); } else { /* field variable */ @@ -2304,12 +2473,12 @@ void hb_compGenPopAliasedVar( char * szVarName, iCmp = strncmp( szAlias, "FIELD", strlen( szAlias ) ); if( iCmp == 0 ) { /* FIELD-> */ - FieldPCode( HB_P_POPFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_POPFIELD, szVarName ); } else { /* database alias */ - hb_compPushSymbol( yy_strdup( szAlias ), 0 ); - FieldPCode( HB_P_POPALIASEDFIELD, szVarName ); + hb_compGenPushSymbol( yy_strdup( szAlias ), 0 ); + hb_compFieldGenPCode( HB_P_POPALIASEDFIELD, szVarName ); } } } @@ -2317,12 +2486,12 @@ void hb_compGenPopAliasedVar( char * szVarName, else { hb_compGenPushLong( lWorkarea ); - FieldPCode( HB_P_POPALIASEDFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_POPALIASEDFIELD, szVarName ); } } else /* Alias is already placed on stack */ - FieldPCode( HB_P_POPALIASEDFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_POPALIASEDFIELD, szVarName ); } /* generates the pcode to push a nonaliased variable value to the virtual @@ -2332,7 +2501,7 @@ void hb_compGenPushVar( char * szVarName ) { int iVar; - iVar = GetLocalVarPos( szVarName ); + iVar = hb_compLocalVarGetPos( szVarName ); if( iVar ) hb_compGenPCode3( HB_P_PUSHLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); else @@ -2345,7 +2514,7 @@ void hb_compGenPushVar( char * szVarName ) } else { - VariablePCode( HB_P_PUSHVARIABLE, szVarName ); + hb_compVariableGenPCode( HB_P_PUSHVARIABLE, szVarName ); } } } @@ -2354,7 +2523,7 @@ void hb_compGenPushVarRef( char * szVarName ) /* generates the pcode to push a v { USHORT iVar; - iVar = GetLocalVarPos( szVarName ); + iVar = hb_compLocalVarGetPos( szVarName ); if( iVar ) hb_compGenPCode3( HB_P_PUSHLOCALREF, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); else @@ -2371,7 +2540,7 @@ void hb_compGenPushVarRef( char * szVarName ) /* generates the pcode to push a v * variable is assumed because fields cannot be passed by * a reference */ - VariablePCode( HB_P_PUSHMEMVARREF, szVarName ); + hb_compVariableGenPCode( HB_P_PUSHMEMVARREF, szVarName ); } } } @@ -2394,7 +2563,7 @@ void hb_compGenPushAliasedVar( char * szVarName, */ if( szAlias[ 0 ] == 'M' && szAlias[ 1 ] == '\0' ) { /* M->variable */ - MemvarPCode( HB_P_PUSHMEMVAR, szVarName ); + hb_compMemvarGenPCode( HB_P_PUSHMEMVAR, szVarName ); } else { @@ -2403,7 +2572,7 @@ void hb_compGenPushAliasedVar( char * szVarName, iCmp = strncmp( szAlias, "MEMVAR", strlen( szAlias ) ); if( iCmp == 0 ) { /* MEMVAR-> or MEMVA-> or MEMV-> */ - MemvarPCode( HB_P_PUSHMEMVAR, szVarName ); + hb_compMemvarGenPCode( HB_P_PUSHMEMVAR, szVarName ); } else { /* field variable */ @@ -2412,12 +2581,12 @@ void hb_compGenPushAliasedVar( char * szVarName, iCmp = strncmp( szAlias, "FIELD", strlen( szAlias ) ); if( iCmp == 0 ) { /* FIELD-> */ - FieldPCode( HB_P_PUSHFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_PUSHFIELD, szVarName ); } else { /* database alias */ - hb_compPushSymbol( yy_strdup( szAlias ), 0 ); - FieldPCode( HB_P_PUSHALIASEDFIELD, szVarName ); + hb_compGenPushSymbol( yy_strdup( szAlias ), 0 ); + hb_compFieldGenPCode( HB_P_PUSHALIASEDFIELD, szVarName ); } } } @@ -2425,12 +2594,12 @@ void hb_compGenPushAliasedVar( char * szVarName, else { hb_compGenPushLong( lWorkarea ); - FieldPCode( HB_P_PUSHALIASEDFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_PUSHALIASEDFIELD, szVarName ); } } else /* Alias is already placed on stack */ - FieldPCode( HB_P_PUSHALIASEDFIELD, szVarName ); + hb_compFieldGenPCode( HB_P_PUSHALIASEDFIELD, szVarName ); } void hb_compGenPushLogical( int iTrueFalse ) /* pushes a logical value on the virtual machine stack */ @@ -2463,10 +2632,10 @@ void hb_compGenPushFunCall( char * szFunName ) { /* Abbreviated function name was used - change it for whole name */ - hb_compPushSymbol( yy_strdup( szFunction ), 1 ); + hb_compGenPushSymbol( yy_strdup( szFunction ), 1 ); } else - hb_compPushSymbol( szFunName, 1 ); + hb_compGenPushSymbol( szFunName, 1 ); } /* generates the pcode to push a integer number on the virtual machine stack */ @@ -2501,7 +2670,7 @@ void hb_compGenPushString( char * szText, ULONG ulStrLen ) } /* generates the pcode to push a symbol on the virtual machine stack */ -void hb_compPushSymbol( char * szSymbolName, int iIsFunction ) +void hb_compGenPushSymbol( char * szSymbolName, int iIsFunction ) { USHORT wSym; PCOMSYMBOL pSym; @@ -2518,59 +2687,39 @@ void hb_compPushSymbol( char * szSymbolName, int iIsFunction ) szSymbolName[ strlen( pName ) ] ='\0'; } - pSym = hb_compGetSymbol( szSymbolName, &wSym ); + pSym = hb_compSymbolFind( szSymbolName, &wSym ); if( ! pSym ) /* the symbol was not found on the symbol table */ { - pSym = hb_compAddSymbol( szSymbolName, &wSym ); + pSym = hb_compSymbolAdd( szSymbolName, &wSym ); if( iIsFunction ) - hb_compAddFunCall( szSymbolName ); + hb_compFunCallAdd( szSymbolName ); } else { - if( iIsFunction && ! GetFuncall( szSymbolName ) ) - hb_compAddFunCall( szSymbolName ); + if( iIsFunction && ! hb_compFunCallFind( szSymbolName ) ) + hb_compFunCallAdd( szSymbolName ); } hb_compGenPCode3( HB_P_PUSHSYM, HB_LOBYTE( wSym ), HB_HIBYTE( wSym ) ); } -void CheckDuplVars( PVAR pVar, char * szVarName, int iVarScope ) +static void hb_compCheckDuplVars( PVAR pVar, char * szVarName, int iVarScope ) { while( pVar ) { if( ! strcmp( pVar->szName, szVarName ) ) { if( ! ( iVarScope & VS_PARAMETER ) ) - --iLine; + --hb_comp_iLine; hb_compErrorDuplVar( szVarName ); + break; } else pVar = pVar->pNext; } } -void Dec( void ) -{ - hb_compGenPCode1( HB_P_DEC ); -} - -void hb_compGenDoProc( BYTE bParams ) -{ - hb_compGenPCode3( HB_P_DO, bParams, 0 ); -} - -void FixElseIfs( void * pFixElseIfs ) -{ - PELSEIF pFix = ( PELSEIF ) pFixElseIfs; - - while( pFix ) - { - hb_compGenJumpHere( pFix->ulOffset ); - pFix = pFix->pNext; - } -} - -void FixReturns( void ) /* fixes all last defined function returns jumps offsets */ +static void hb_compFixReturns( void ) /* fixes all last defined function returns jumps offsets */ { if( hb_comp_iWarnings && hb_comp_functions.pLast ) { @@ -2601,30 +2750,6 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets hb_compGenWarning( hb_comp_szCWarnings, 'W', WARN_FUN_WITH_NO_RETURN, hb_comp_functions.pLast->szName, NULL ); } - -/* TODO: check why it triggers this error in keywords.prg - if( hb_comp_pLoops ) - { - PTR_LOOPEXIT pLoop = hb_comp_pLoops; - char cLine[ 64 ]; - - while( pLoop->pNext ) - pLoop = pLoop->pNext; - - itoa( pLoop->iLine, cLine, 10 ); - hb_compGenError( hb_comp_szCErrors, 'E', ERR_UNCLOSED_STRU, cLine, NULL ); - } -*/ -} - -void Function( BYTE bParams ) -{ - hb_compGenPCode3( HB_P_FUNCTION, bParams, 0 ); -} - -void hb_compGenArray( int iElements ) -{ - hb_compGenPCode3( HB_P_ARRAYGEN, HB_LOBYTE( iElements ), HB_HIBYTE( iElements ) ); } void hb_compGenPCode1( BYTE byte ) @@ -2689,7 +2814,7 @@ void hb_compGenPCodeN( BYTE * pBuffer, ULONG ulSize ) * - either the address of HB_P_SEQEND opcode if there is no RECOVER clause * - or the address of RECOVER code */ -ULONG SequenceBegin( void ) +ULONG hb_compSequenceBegin( void ) { hb_compGenPCode3( HB_P_SEQBEGIN, 0, 0 ); @@ -2703,7 +2828,7 @@ ULONG SequenceBegin( void ) * last statement in code beetwen BEGIN ... RECOVER) or if BREAK was requested * and there was no matching RECOVER clause. */ -ULONG SequenceEnd( void ) +ULONG hb_compSequenceEnd( void ) { hb_compGenPCode3( HB_P_SEQEND, 0, 0 ); @@ -2713,7 +2838,7 @@ ULONG SequenceEnd( void ) /* Remove unnecessary opcodes in case there were no executable statements * beetwen BEGIN and RECOVER sequence */ -void SequenceFinish( ULONG ulStartPos, int bUsualStmts ) +void hb_compSequenceFinish( ULONG ulStartPos, int bUsualStmts ) { if( ! hb_comp_bDebugInfo ) /* only if no debugger info is required */ { @@ -2731,7 +2856,7 @@ void SequenceFinish( ULONG ulStartPos, int bUsualStmts ) * szAlias -> name of the alias * iField -> position of the first FIELD name to change */ -void FieldsSetAlias( char * szAlias, int iField ) +void hb_compFieldSetAlias( char * szAlias, int iField ) { PVAR pVar; @@ -2747,9 +2872,9 @@ void FieldsSetAlias( char * szAlias, int iField ) } /* This functions counts the number of FIELD declaration in a function - * We will required this information in FieldsSetAlias function + * We will required this information in hb_compFieldSetAlias function */ -int FieldsCount() +int hb_compFieldsCount() { int iFields = 0; PVAR pVar = hb_comp_functions.pLast->pFields; @@ -2778,7 +2903,7 @@ void hb_compStaticDefStart( void ) { BYTE pBuffer[ 5 ]; - hb_comp_pInitFunc = FunctionNew( yy_strdup("(_INITSTATICS)"), FS_INIT ); + hb_comp_pInitFunc = hb_compFunctionNew( yy_strdup("(_INITSTATICS)"), FS_INIT ); hb_comp_pInitFunc->pOwner = hb_comp_functions.pLast; hb_comp_pInitFunc->bFlags = FUN_USES_STATICS | FUN_PROCEDURE; hb_comp_pInitFunc->cScope = FS_INIT | FS_EXIT; @@ -2815,13 +2940,13 @@ void hb_compStaticDefEnd( void ) */ void hb_compCodeBlockStart() { - PFUNCTION pFunc = FunctionNew( NULL, FS_STATIC ); + PFUNCTION pFunc = hb_compFunctionNew( NULL, FS_STATIC ); pFunc->pOwner = hb_comp_functions.pLast; pFunc->iStaticsBase = hb_comp_functions.pLast->iStaticsBase; hb_comp_functions.pLast = pFunc; - LineDebug(); + hb_compLinePushIfDebugger(); } void hb_compCodeBlockEnd( void ) @@ -2874,7 +2999,7 @@ void hb_compCodeBlockEnd( void ) pVar = pCodeblock->pStatics; while( wLocals-- ) { - wPos = GetVarPos( pFunc->pLocals, pVar->szName ); + wPos = hb_compVariableGetPos( pFunc->pLocals, pVar->szName ); hb_compGenPCode1( HB_LOBYTE( wPos ) ); hb_compGenPCode1( HB_HIBYTE( wPos ) ); diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 1ece43c51a..9c9464eccb 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -73,21 +73,16 @@ extern int PreProcess( FILE*, FILE*, char *); int yy_lex_input( char *, int ); #define YY_INPUT( buf, result, max_size ) result = yy_lex_input( buf, max_size ); -/* variables defined in harbour.y */ -extern int hb_comp_bRestrictSymbolLength; - -int iLine = 1; -long lNumber = 0; #define LOOKUP 0 /* scan from the begining of line */ #define OPERATOR -1 #define SEPARATOR -2 -int hb_comp_iState = LOOKUP; +static int hb_comp_iState = LOOKUP; static int _iOpenBracket = 0; /* Support for Array Index */ -int iIndexSets = 0; -int i_INDEX_STATE = 0; +static int iIndexSets = 0; +static int i_INDEX_STATE = 0; %} @@ -220,16 +215,16 @@ Separator {SpaceTab} \n.* { hb_comp_iState = LOOKUP; yyless( 1 ); - /*++iLine;*/ + /*++hb_comp_iLine;*/ #if 0 if( ! hb_comp_bQuiet ) { - printf( "\r%i", iLine ); + printf( "\r%i", hb_comp_iLine ); } #endif - if( ! hb_comp_bQuiet && ( iLine % 100 ) == 0 ) + if( ! hb_comp_bQuiet && ( hb_comp_iLine % 100 ) == 0 ) { - printf( "\r%i", iLine ); + printf( "\r%i", hb_comp_iLine ); fflush( stdout ); } return '\n'; @@ -1175,7 +1170,10 @@ Separator {SpaceTab} {Number} { return yy_ConvertNumber( yytext ); } -{HexNumber} { sscanf( yytext, "%lxI", &lNumber ); +{HexNumber} { + long lNumber = 0; + + sscanf( yytext, "%lxI", &lNumber ); if( ( double )SHRT_MIN <= lNumber && lNumber <= ( double )SHRT_MAX ) diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index a592a6452d..9b26408396 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -37,14 +37,8 @@ /* TODO list * 1) jumps longer then 2^15 bytes * 2) macro support - * 3) correct support for undeclared variables (all variables are assumed - * memvars now - we should add runtime recognition of variable type) - * - work in progress (rglab@imid.med.pl) - * 4) in some cases incorrect warnings are generated when -w option is used - * 5) in some cases GPF occurs when -w option is used, example: - * LOCAL nDouble := NumAnd32(RandGetLong() / 65536, 32767) / 997 - * 6) Change the pcode generated by ::cVar from Self:cVar to QSELF():cVar - * 7) Support this syntax: nPtr := @Hello() + * 3) Change the pcode generated by ::cVar from Self:cVar to QSELF():cVar + * 4) Support this syntax: nPtr := @Hello() */ #include "compiler.h" @@ -52,7 +46,7 @@ /* Compile using: bison -d -v harbour.y */ extern FILE *yyin; /* currently yacc parsed file */ -extern int iLine; /* currently parsed file line number */ +extern int hb_comp_iLine; /* currently parsed file line number */ extern char *yytext; #ifdef __cplusplus @@ -76,14 +70,18 @@ extern "C" int yywrap( void ); int yywrap( void ); /* manages the EOF of current processed file */ #endif -static void LoopStart( void ); -static void LoopEnd( void ); -static void LoopLoop( void ); -static void LoopExit( void ); -static void LoopHere( void ); +static void hb_compLoopStart( void ); +static void hb_compLoopEnd( void ); +static void hb_compLoopLoop( void ); +static void hb_compLoopExit( void ); +static void hb_compLoopHere( void ); +static void * hb_compElseIfGen( void * pFirstElseIf, ULONG ulOffset ); /* generates a support structure for elseifs pcode fixups */ +static void hb_compElseIfFix( void * pIfElseIfs ); /* implements the ElseIfs pcode fixups */ /* Misc functions defined in harbour.c */ +extern PHB_FNAME hb_fsFNameSplit( char * szFileName ); +extern char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ); extern void * hb_xgrab( ULONG ulSize ); /* allocates fixed memory, exits on failure */ extern void * hb_xrealloc( void * pMem, ULONG ulSize ); /* reallocates memory */ extern void hb_xfree( void * pMem ); /* frees fixed memory */ @@ -97,6 +95,21 @@ extern void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, #define YYDEBUG 1 /* Parser debug information support */ #endif +typedef struct __ELSEIF +{ + ULONG ulOffset; + struct __ELSEIF * pNext; +} _ELSEIF, * PELSEIF; /* support structure for else if pcode fixups */ + +typedef struct _LOOPEXIT +{ + ULONG ulOffset; + int iLine; + USHORT wSeqCounter; + struct _LOOPEXIT * pLoopList; + struct _LOOPEXIT * pExitList; + struct _LOOPEXIT * pNext; +} LOOPEXIT, * PTR_LOOPEXIT; /* support structure for EXIT and LOOP statements */ USHORT hb_comp_wSeqCounter = 0; USHORT hb_comp_wForCounter = 0; @@ -104,6 +117,8 @@ USHORT hb_comp_wIfCounter = 0; USHORT hb_comp_wWhileCounter = 0; USHORT hb_comp_wCaseCounter = 0; +PTR_LOOPEXIT hb_comp_pLoops = NULL; + %} %union /* special structure used by lex and yacc to share info */ @@ -146,24 +161,24 @@ USHORT hb_comp_wCaseCounter = 0; %left POST /*assigment - from right to left*/ %right INASSIGN -%left PLUSEQ MINUSEQ -%left MULTEQ DIVEQ MODEQ -%left EXPEQ +%right PLUSEQ MINUSEQ +%right MULTEQ DIVEQ MODEQ +%right EXPEQ /*logical operators*/ -%left OR -%left AND -%left NOT +%right OR +%right AND +%right NOT /*relational operators*/ -%left '=' '<' '>' EQ NE1 NE2 LE GE '$' +%right '=' '<' '>' EQ NE1 NE2 LE GE '$' /*mathematical operators*/ -%left '+' '-' -%left '*' '/' '%' -%left POWER +%right '+' '-' +%right '*' '/' '%' +%right POWER %right UNARY /*preincrement and predecrement*/ -%left PRE +%right PRE /*special operators*/ -%left ALIASOP '&' '@' +%right ALIASOP '&' '@' %right '\n' ';' ',' /*the highest precedence*/ @@ -174,10 +189,11 @@ USHORT hb_comp_wCaseCounter = 0; %type FunScope AsType %type Params ParamList %type IfBegin VarList -%type FieldList DoArgList +%type FieldList %type WhileBegin %type IfElseIf Cases %type Argument ArgList ElemList BlockExpList BlockVarList BlockNoVar +%type DoProc DoArgument DoArgList %type PareExpList1 PareExpList2 PareExpList3 PareExpListN %type ExpList ExpList1 ExpList2 ExpList3 %type NumValue NumAlias @@ -201,7 +217,8 @@ USHORT hb_comp_wCaseCounter = 0; %type Expression SimpleExpression LValue %type EmptyExpression %type ExprAssign ExprOperEq ExprPreOp ExprPostOp -%type ExprEqual ExprMath ExprBool ExprRelation +%type ExprEqual ExprMath ExprBool ExprRelation ExprUnary +%type ExprPlusEq ExprMinusEq ExprMultEq ExprDivEq ExprModEq ExprExpEq %type ArrayIndex IndexList %type DimIndex DimList %type FieldAlias FieldVarAlias @@ -209,15 +226,7 @@ USHORT hb_comp_wCaseCounter = 0; %% -Main : { Line(); } Source { - FixReturns(); /* fix all previous function returns offsets */ - if( ! hb_comp_bQuiet ) - { - if( ! hb_comp_bStartProc ) - --hb_comp_iFunctionCnt; - printf( "\rLines %i, Functions/Procedures %i\n", iLine, hb_comp_iFunctionCnt ); - } - } +Main : { hb_compLinePush(); } Source { } Source : Crlf | VarDefs @@ -239,9 +248,9 @@ Line : LINE NUM_INTEGER LITERAL Crlf | LINE NUM_INTEGER LITERAL '@' LITERAL Crlf /* XBase++ style */ ; -Function : FunScope FUNCTION IDENTIFIER { hb_comp_cVarType = ' '; hb_compFunDef( $3, ( HB_SYMBOLSCOPE ) $1, 0 ); } Params Crlf {} - | FunScope PROCEDURE IDENTIFIER { hb_comp_cVarType = ' '; hb_compFunDef( $3, ( HB_SYMBOLSCOPE ) $1, FUN_PROCEDURE ); } Params Crlf {} - | FunScope DECLARE_FUN IDENTIFIER Params AsType Crlf { hb_compAddSymbol( $3, NULL ); } +Function : FunScope FUNCTION IDENTIFIER { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, 0 ); } Params Crlf {} + | FunScope PROCEDURE IDENTIFIER { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, FUN_PROCEDURE ); } Params Crlf {} + | FunScope DECLARE_FUN IDENTIFIER Params AsType Crlf { hb_compSymbolAdd( $3, NULL ); } ; FunScope : { $$ = FS_PUBLIC; } @@ -265,8 +274,8 @@ AsType : /* not specified */ { hb_comp_cVarType = ' '; } | AS_OBJECT { hb_comp_cVarType = 'O'; } ; -ParamList : IDENTIFIER AsType { hb_compAddVar( $1, ' ' ); $$ = 1; } - | ParamList ',' IDENTIFIER AsType { hb_compAddVar( $3, $4 ); $$++; } +ParamList : IDENTIFIER AsType { hb_compVariableAdd( $1, ' ' ); $$ = 1; } + | ParamList ',' IDENTIFIER AsType { hb_compVariableAdd( $3, $4 ); $$++; } ; /* NOTE: This alllows the use of Expression as a statement. @@ -274,10 +283,24 @@ ParamList : IDENTIFIER AsType { hb_compAddVar( $1, ' ' ); $$ = 1 * hb_compExprGenStatement(). With this solution we don't have to * stop compilation if invalid syntax will be used. */ -Statement : ExecFlow CrlfStmnt { } - | Expression CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } - | BREAK { hb_compGenBreak(); } CrlfStmnt { hb_compGenDoProc( 0 ); } - | BREAK { hb_compGenBreak(); } Expression CrlfStmnt { hb_compExprDelete( hb_compExprGenPush( $3 ) ); hb_compGenDoProc( 1 ); } +Statement : ExecFlow CrlfStmnt { } + | IfInline CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | FunCall CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | AliasExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ObjectMethod CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | PareExpList CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ExprPreOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ExprPostOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ExprOperEq CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ExprEqual CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | ExprAssign CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | DoProc CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | BREAK CrlfStmnt { hb_compGenBreak(); hb_compGenPCode3( HB_P_DO, 0, 0 ); + hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } + | BREAK Expression CrlfStmnt { hb_compGenBreak(); hb_compExprDelete( hb_compExprGenPush( $2 ) ); + hb_compGenPCode3( HB_P_DO, 1, 0 ); + hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; + } | RETURN CrlfStmnt { if( hb_comp_wSeqCounter ) { @@ -290,6 +313,7 @@ Statement : ExecFlow CrlfStmnt { } } hb_comp_functions.pLast->bFlags |= FUN_WITH_RETURN; hb_comp_bDontGenLineNum = TRUE; + hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } | RETURN Expression CrlfStmnt { if( hb_comp_wSeqCounter ) @@ -305,29 +329,29 @@ Statement : ExecFlow CrlfStmnt { } } hb_comp_functions.pLast->bFlags |= FUN_WITH_RETURN; hb_comp_bDontGenLineNum = TRUE; + hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } | PUBLIC { hb_comp_iVarScope = VS_PUBLIC; } VarList CrlfStmnt | PRIVATE { hb_comp_iVarScope = VS_PRIVATE; } VarList CrlfStmnt - | EXITLOOP CrlfStmnt { LoopExit(); } - | LOOP CrlfStmnt { LoopLoop(); } - | DoProc CrlfStmnt - | EXTERN { hb_comp_bExternal = TRUE; } ExtList CrlfStmnt + | EXITLOOP CrlfStmnt { hb_compLoopExit(); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } + | LOOP CrlfStmnt { hb_compLoopLoop(); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } + | EXTERN ExtList CrlfStmnt ; -CrlfStmnt : { LineBody(); } Crlf +CrlfStmnt : { hb_compLinePushIfInside(); } Crlf ; -LineStat : Crlf { $$ = 0; } +LineStat : Crlf { $$ = 0; hb_comp_bDontGenLineNum = TRUE; } | Statement { $$ = 1; } ; -Statements : LineStat { $$ = $1; } - | Statements { Line(); } LineStat { $$ += $3; } +Statements : LineStat { $$ = $1; } + | Statements LineStat { $$ += $3; } ; -ExtList : IDENTIFIER { hb_compAddExtern( $1 ); } - | ExtList ',' IDENTIFIER { hb_compAddExtern( $3 ); } +ExtList : IDENTIFIER { hb_compExternAdd( $1 ); } + | ExtList ',' IDENTIFIER { hb_compExternAdd( $3 ); } ; /* Numeric values @@ -558,7 +582,7 @@ ObjectMethodAlias : ObjectMethod ALIASOP { $$ = $1; } ; /* NOTE: We have to distinguish IDENTIFIER here because it is repeated - * in DoExpression (a part of DO WITH .. statement) + * in DoArgument (a part of DO WITH .. statement) * where it generates different action. */ SimpleExpression : @@ -581,9 +605,9 @@ SimpleExpression : | AliasExpr { $$ = $1; } | ExprAssign { $$ = $1; } | ExprOperEq { $$ = $1; } - | ExprEqual { $$ = $1; } | ExprPostOp { $$ = $1; } | ExprPreOp { $$ = $1; } + | ExprUnary { $$ = $1; } | ExprMath { $$ = $1; } | ExprBool { $$ = $1; } | ExprRelation { $$ = $1; } @@ -613,8 +637,9 @@ PostOp : INC { $$ = hb_compExprNewPostInc( $0 ); } | DEC { $$ = hb_compExprNewPostDec( $0 ); } ; -/* NOTE: We cannot use 'Expression PostOp' because it caused - * shift/reduce conflicts +/* NOTE: The rule: Expression Operator Expression + * that can be used standalone as a statement have to be written + * using all possible left values to resolve shift/reduce conflicts */ ExprPostOp : NumValue PostOp %prec POST { $$ = $2; } | NilValue PostOp %prec POST { $$ = $2; } @@ -639,25 +664,193 @@ ExprPostOp : NumValue PostOp %prec POST { $$ = $2; } ExprPreOp : INC Expression %prec PRE { $$ = hb_compExprNewPreInc( $2 ); } | DEC Expression %prec PRE { $$ = hb_compExprNewPreDec( $2 ); } - | NOT Expression %prec UNARY { $$ = hb_compExprNewNot( $2 ); } + ; + +ExprUnary : NOT Expression { $$ = hb_compExprNewNot( $2 ); } | '-' Expression %prec UNARY { $$ = hb_compExprNewNegate( $2 ); } | '+' Expression %prec UNARY { $$ = $2; } ; - +/* ExprAssign : Expression INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } ; +*/ -ExprOperEq : Expression PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } - | Expression MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } - | Expression MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } - | Expression DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } - | Expression MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } - | Expression EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } +ExprAssign : NumValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | NilValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | LiteralValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | CodeBlock INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | Logical INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | SelfValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | Array INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | ArrayAt INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | Variable INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | MacroVar INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | MacroExpr INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | AliasVar INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | AliasExpr INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | VariableAt INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | PareExpList INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | IfInline INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | FunCall INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | ObjectData INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | ObjectMethod INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } ; -ExprEqual : Expression '=' Expression { $$ = hb_compExprSetOperand( hb_compExprNewEqual( $1 ), $3 ); } +ExprEqual : NumValue '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | NilValue '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | LiteralValue '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | CodeBlock '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | Logical '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | SelfValue '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | Array '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | ArrayAt '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | Variable '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | MacroVar '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | MacroExpr '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | AliasVar '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | AliasExpr '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | VariableAt '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | PareExpList '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | IfInline '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | FunCall '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | ObjectData '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } + | ObjectMethod '=' Expression %prec INASSIGN { $$ = hb_compExprAssign( $1, $3 ); } ; +ExprPlusEq : NumValue PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | NilValue PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | LiteralValue PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | CodeBlock PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | Logical PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | SelfValue PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | Array PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | ArrayAt PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | Variable PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | MacroVar PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | MacroExpr PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | AliasVar PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | AliasExpr PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | VariableAt PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | PareExpList PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | IfInline PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | FunCall PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | ObjectData PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + | ObjectMethod PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1 ), $3 ); } + ; + +ExprMinusEq : NumValue MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | NilValue MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | LiteralValue MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | CodeBlock MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | Logical MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | SelfValue MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | Array MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | ArrayAt MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | Variable MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | MacroVar MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | MacroExpr MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | AliasVar MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | AliasExpr MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | VariableAt MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | PareExpList MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | IfInline MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | FunCall MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | ObjectData MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + | ObjectMethod MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1 ), $3 ); } + ; + +ExprMultEq : NumValue MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | NilValue MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | LiteralValue MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | CodeBlock MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | Logical MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | SelfValue MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | Array MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | ArrayAt MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | Variable MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | MacroVar MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | MacroExpr MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | AliasVar MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | AliasExpr MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | VariableAt MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | PareExpList MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | IfInline MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | FunCall MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | ObjectData MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + | ObjectMethod MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1 ), $3 ); } + ; + +ExprDivEq : NumValue DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | NilValue DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | LiteralValue DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | CodeBlock DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | Logical DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | SelfValue DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | Array DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | ArrayAt DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | Variable DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | MacroVar DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | MacroExpr DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | AliasVar DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | AliasExpr DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | VariableAt DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | PareExpList DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | IfInline DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | FunCall DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | ObjectData DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + | ObjectMethod DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1 ), $3 ); } + ; + +ExprModEq : NumValue MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | NilValue MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | LiteralValue MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | CodeBlock MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | Logical MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | SelfValue MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | Array MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | ArrayAt MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | Variable MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | MacroVar MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | MacroExpr MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | AliasVar MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | AliasExpr MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | VariableAt MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | PareExpList MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | IfInline MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | FunCall MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | ObjectData MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + | ObjectMethod MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1 ), $3 ); } + ; + +ExprExpEq : NumValue EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | NilValue EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | LiteralValue EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | CodeBlock EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | Logical EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | SelfValue EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | Array EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | ArrayAt EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | Variable EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | MacroVar EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | MacroExpr EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | AliasVar EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | AliasExpr EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | VariableAt EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | PareExpList EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | IfInline EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | FunCall EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | ObjectData EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + | ObjectMethod EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1 ), $3 ); } + ; + +ExprOperEq : ExprPlusEq { $$ = $1; } + | ExprMinusEq { $$ = $1; } + | ExprMultEq { $$ = $1; } + | ExprDivEq { $$ = $1; } + | ExprModEq { $$ = $1; } + | ExprExpEq { $$ = $1; } + ; + ExprMath : Expression '+' Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlus( $1 ), $3 ); } | Expression '-' Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinus( $1 ), $3 ); } | Expression '*' Expression { $$ = hb_compExprSetOperand( hb_compExprNewMult( $1 ), $3 ); } @@ -678,6 +871,7 @@ ExprRelation: Expression EQ Expression { $$ = hb_compExprSetOperand( hb_compE | Expression NE1 Expression { $$ = hb_compExprSetOperand( hb_compExprNewNE( $1 ), $3 ); } | Expression NE2 Expression { $$ = hb_compExprSetOperand( hb_compExprNewNE( $1 ), $3 ); } | Expression '$' Expression { $$ = hb_compExprSetOperand( hb_compExprNewIN( $1 ), $3 ); } + | Expression '=' Expression { $$ = hb_compExprSetOperand( hb_compExprNewEqual( $1 ), $3 ); } ; ArrayIndex : IndexList ']' { $$ = $1; } @@ -768,8 +962,8 @@ IfInline : IIF PareExpList3 { $$ = hb_compExprNewIIF( $2 ); } IfInlineAlias : IfInline ALIASOP { $$ = $1; } ; -VarDefs : LOCAL { hb_comp_iVarScope = VS_LOCAL; Line(); } VarList Crlf { hb_comp_cVarType = ' '; } - | STATIC { hb_comp_iVarScope = VS_STATIC; Line(); } VarList Crlf { hb_comp_cVarType = ' '; } +VarDefs : LOCAL { hb_comp_iVarScope = VS_LOCAL; hb_compLinePush(); } VarList Crlf { hb_comp_cVarType = ' '; } + | STATIC { hb_comp_iVarScope = VS_STATIC; hb_compLinePush(); } VarList Crlf { hb_comp_cVarType = ' '; } | PARAMETERS { if( hb_comp_functions.pLast->bFlags & FUN_USES_LOCAL_PARAMS ) hb_compGenError( hb_comp_szCErrors, 'E', ERR_PARAMETERS_NOT_ALLOWED, NULL, NULL ); else @@ -786,11 +980,11 @@ VarDef : IDENTIFIER AsType if( hb_comp_iVarScope == VS_STATIC ) { hb_compStaticDefStart(); /* switch to statics pcode buffer */ - hb_compAddVar( $1, $2 ); + hb_compVariableAdd( $1, $2 ); hb_compStaticDefEnd(); } else - hb_compAddVar( $1, $2 ); + hb_compVariableAdd( $1, $2 ); } | IDENTIFIER AsType INASSIGN Expression @@ -798,13 +992,13 @@ VarDef : IDENTIFIER AsType if( hb_comp_iVarScope == VS_STATIC ) { hb_compStaticDefStart(); /* switch to statics pcode buffer */ - hb_compAddVar( $1, $2 ); + hb_compVariableAdd( $1, $2 ); hb_compExprDelete( hb_compExprGenStatement( hb_compExprAssignStatic( hb_compExprNewVar( $1 ), $4 ) ) ); hb_compStaticDefEnd(); } else { - hb_compAddVar( $1, $2 ); + hb_compVariableAdd( $1, $2 ); hb_compExprDelete( hb_compExprGenStatement( hb_compExprAssign( hb_compExprNewVar( $1 ), $4 ) ) ); } } @@ -812,7 +1006,7 @@ VarDef : IDENTIFIER AsType | IDENTIFIER DimList { USHORT uCount = hb_compExprListLen( $2 ); - hb_compAddVar( $1, 'A' ); + hb_compVariableAdd( $1, 'A' ); hb_compExprDelete( hb_compExprGenPush( $2 ) ); hb_compGenPCode3( HB_P_ARRAYDIM, HB_LOBYTE( uCount ), HB_HIBYTE( uCount ) ); hb_compExprDelete( hb_compExprGenPop( hb_compExprNewVar( $1 ) ) ); @@ -820,7 +1014,7 @@ VarDef : IDENTIFIER AsType | IDENTIFIER DimList AS_ARRAY { USHORT uCount = hb_compExprListLen( $2 ); - hb_compAddVar( $1, 'A' ); + hb_compVariableAdd( $1, 'A' ); hb_compExprDelete( hb_compExprGenPush( $2 ) ); hb_compGenPCode3( HB_P_ARRAYDIM, HB_LOBYTE( uCount ), HB_HIBYTE( uCount ) ); hb_compExprDelete( hb_compExprGenPop( hb_compExprNewVar( $1 ) ) ); @@ -842,16 +1036,16 @@ DimIndex : '[' Expression { $$ = hb_compExprNewArgList( $2 ); } FieldsDef : FIELD { hb_comp_iVarScope = VS_FIELD; } FieldList Crlf ; -FieldList : IDENTIFIER AsType { $$=FieldsCount(); hb_compAddVar( $1, $2 ); } - | FieldList ',' IDENTIFIER AsType { hb_compAddVar( $3, $4 ); } - | FieldList IN IDENTIFIER { FieldsSetAlias( $3, $1 ); } +FieldList : IDENTIFIER AsType { $$=hb_compFieldsCount(); hb_compVariableAdd( $1, $2 ); } + | FieldList ',' IDENTIFIER AsType { hb_compVariableAdd( $3, $4 ); } + | FieldList IN IDENTIFIER { hb_compFieldSetAlias( $3, $1 ); } ; MemvarDef : MEMVAR { hb_comp_iVarScope = VS_MEMVAR; } MemvarList Crlf ; -MemvarList : IDENTIFIER { hb_compAddVar( $1, ' ' ); } - | MemvarList ',' IDENTIFIER { hb_compAddVar( $3, ' ' ); } +MemvarList : IDENTIFIER { hb_compVariableAdd( $1, ' ' ); } + | MemvarList ',' IDENTIFIER { hb_compVariableAdd( $3, ' ' ); } ; ExecFlow : IfEndif @@ -863,52 +1057,53 @@ ExecFlow : IfEndif IfEndif : IfBegin EndIf { hb_compGenJumpHere( $1 ); } | IfBegin IfElse EndIf { hb_compGenJumpHere( $1 ); } - | IfBegin IfElseIf EndIf { hb_compGenJumpHere( $1 ); FixElseIfs( $2 ); } - | IfBegin IfElseIf IfElse EndIf { hb_compGenJumpHere( $1 ); FixElseIfs( $2 ); } + | IfBegin IfElseIf EndIf { hb_compGenJumpHere( $1 ); hb_compElseIfFix( $2 ); } + | IfBegin IfElseIf IfElse EndIf { hb_compGenJumpHere( $1 ); hb_compElseIfFix( $2 ); } ; -EmptyStats : /* empty */ +EmptyStats : /* empty */ { hb_comp_bDontGenLineNum = TRUE; } | Statements ; -IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; Line(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } +IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF Variable { ++hb_comp_wIfCounter; Line(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } + | IF Variable { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF PareExpList1 { ++hb_comp_wIfCounter; Line(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } + | IF PareExpList1 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF PareExpList2 { ++hb_comp_wIfCounter; Line(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } + | IF PareExpList2 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF PareExpListN { ++hb_comp_wIfCounter; Line(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } + | IF PareExpListN { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } ; -IfElse : ELSE Crlf { Line(); } EmptyStats +IfElse : ELSE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); } + EmptyStats ; -IfElseIf : ELSEIF Expression Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } - EmptyStats { $$ = GenElseIf( 0, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $4 ); } +IfElseIf : ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + EmptyStats { $$ = hb_compElseIfGen( NULL, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $4 ); } - | IfElseIf ELSEIF Expression Crlf { hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); Line(); } - EmptyStats { $$ = GenElseIf( $1, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $5 ); } + | IfElseIf ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + EmptyStats { $$ = hb_compElseIfGen( $1, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $5 ); } ; -EndIf : ENDIF { --hb_comp_wIfCounter; hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; } - | END { --hb_comp_wIfCounter; hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; } +EndIf : ENDIF { --hb_comp_wIfCounter; hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); } + | END { --hb_comp_wIfCounter; hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); } ; DoCase : DoCaseBegin Cases - EndCase { FixElseIfs( $2 ); } + EndCase { hb_compElseIfFix( $2 ); } | DoCaseBegin Otherwise @@ -920,21 +1115,27 @@ DoCase : DoCaseBegin | DoCaseBegin Cases Otherwise - EndCase { FixElseIfs( $2 ); } + EndCase { hb_compElseIfFix( $2 ); } ; -EndCase : ENDCASE { --hb_comp_wCaseCounter; hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; } - | END { --hb_comp_wCaseCounter; hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; } +EndCase : ENDCASE + { --hb_comp_wCaseCounter; + hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); + } + | END + { --hb_comp_wCaseCounter; + hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); + } ; -DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; } Crlf { Line(); } +DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; } Crlf { hb_compLinePush(); } ; DoCaseBegin : DoCaseStart { } | DoCaseStart Statements { if( $2 > 0 ) { - --iLine; + --hb_comp_iLine; hb_compGenError( hb_comp_szCErrors, 'E', ERR_MAYHEM_IN_CASE, NULL, NULL ); } } @@ -944,52 +1145,55 @@ Cases : CASE Expression Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); - Line(); + hb_compLinePush(); } EmptyStats { - $$ = GenElseIf( 0, hb_compGenJump( 0 ) ); + hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; + $$ = hb_compElseIfGen( 0, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $4 ); - Line(); + hb_compLinePush(); } | Cases CASE Expression Crlf { hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); - Line(); + hb_compLinePush(); } EmptyStats { - $$ = GenElseIf( $1, hb_compGenJump( 0 ) ); + hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; + $$ = hb_compElseIfGen( $1, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $5 ); - Line(); + hb_compLinePush(); } ; -Otherwise : OTHERWISE Crlf { Line(); } EmptyStats +Otherwise : OTHERWISE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); } + EmptyStats ; DoWhile : WhileBegin Expression Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); - Line(); + hb_compLinePush(); } EmptyStats { - LoopHere(); + hb_compLoopHere(); hb_compGenJump( $1 - hb_comp_functions.pLast->lPCodePos ); } EndWhile { hb_compGenJumpHere( $4 ); --hb_comp_wWhileCounter; - LoopEnd(); - hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; + hb_compLoopEnd(); + hb_comp_functions.pLast->bFlags &= ~ ( FUN_WITH_RETURN | FUN_BREAK_CODE ); } ; -WhileBegin : WHILE { $$ = hb_comp_functions.pLast->lPCodePos; ++hb_comp_wWhileCounter; LoopStart(); } +WhileBegin : WHILE { $$ = hb_comp_functions.pLast->lPCodePos; ++hb_comp_wWhileCounter; hb_compLoopStart(); } ; EndWhile : END @@ -1003,7 +1207,7 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ } TO Expression StepExpr /* 6 7 8 */ { - LoopStart(); + hb_compLoopStart(); $$ = hb_comp_functions.pLast->lPCodePos; /* 9 */ hb_compExprGenPush( $2 ); /* counter */ hb_compExprGenPush( $7 ); /* end */ @@ -1017,18 +1221,18 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ else hb_compGenPCode1( HB_P_LESSEQUAL ); $$ = hb_compGenJumpFalse( 0 ); /* 11 */ - Line(); + hb_compLinePush(); } ForStatements /* 12 */ { - LoopHere(); + hb_compLoopHere(); if( $8 ) hb_compExprGenStatement( hb_compExprSetOperand( hb_compExprNewPlusEq( $2 ), $8 ) ); else hb_compExprGenStatement( hb_compExprNewPreInc( $2 ) ); hb_compGenJump( $9 - hb_comp_functions.pLast->lPCodePos ); hb_compGenJumpHere( $11 ); - LoopEnd(); + hb_compLoopEnd(); hb_compExprDelete( $7 ); hb_compExprDelete( $5 ); hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; @@ -1047,15 +1251,15 @@ ForStatements : EmptyStats NEXT { --hb_comp_wForCounter; } | EmptyStats NEXT IDENTIFIER { --hb_comp_wForCounter; } ; -BeginSeq : BEGINSEQ { ++hb_comp_wSeqCounter; $$ = SequenceBegin(); } Crlf { Line(); } +BeginSeq : BEGINSEQ { ++hb_comp_wSeqCounter; $$ = hb_compSequenceBegin(); } Crlf { hb_compLinePush(); } EmptyStats { /* Set jump address for HB_P_SEQBEGIN opcode - this address * will be used in BREAK code if there is no RECOVER clause */ hb_compGenJumpHere( $2 ); - $$ = SequenceEnd(); - Line(); + $$ = hb_compSequenceEnd(); + hb_compLinePush(); } RecoverSeq { @@ -1073,21 +1277,22 @@ BeginSeq : BEGINSEQ { ++hb_comp_wSeqCounter; $$ = SequenceBegin(); } */ hb_compGenJumpThere( $6, hb_comp_functions.pLast->lPCodePos-((hb_comp_bLineNumbers && !$7)?3:0) ); if( $7 ) /* only if there is RECOVER clause */ - LineDebug(); + hb_compLinePushIfDebugger(); else --hb_comp_wSeqCounter; /* RECOVER is also considered as end of sequence */ - SequenceFinish( $2, $5 ); + hb_compSequenceFinish( $2, $5 ); hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; } ; RecoverSeq : /* no recover */ { $$ = 0; } - | RecoverEmpty Crlf { $$ = $1; Line(); } EmptyStats - | RecoverUsing Crlf { $$ = $1; Line(); } EmptyStats + | RecoverEmpty Crlf { $$ = $1; hb_compLinePush(); } EmptyStats + | RecoverUsing Crlf { $$ = $1; hb_compLinePush(); } EmptyStats ; RecoverEmpty : RECOVER { + hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; $$ = hb_comp_functions.pLast->lPCodePos; --hb_comp_wSeqCounter; hb_compGenPCode1( HB_P_SEQRECOVER ); @@ -1097,6 +1302,7 @@ RecoverEmpty : RECOVER RecoverUsing : RECOVER USING IDENTIFIER { + hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; $$ = hb_comp_functions.pLast->lPCodePos; --hb_comp_wSeqCounter; hb_compGenPCode1( HB_P_SEQRECOVER ); @@ -1110,24 +1316,28 @@ RecoverUsing : RECOVER USING IDENTIFIER * DO .. WITH ++variable * will pass the value of variable not a reference */ -DoProc : DO IDENTIFIER { hb_compPushSymbol( $2, 1 ); hb_compGenPushNil(); hb_compGenDoProc( 0 ); } - | DO IDENTIFIER { hb_compPushSymbol( $2, 1 ); hb_compGenPushNil(); } WITH DoArgList { hb_compGenDoProc( $5 ); } - | WHILE { hb_compPushSymbol( yy_strdup("WHILE"), 1 ); hb_compGenPushNil(); } WITH DoArgList { hb_compGenDoProc( $4 ); } +DoProc : DO IDENTIFIER + { $$ = hb_compExprNewFunCall( $2, NULL ); } + | DO IDENTIFIER WITH DoArgList + { $$ = hb_compExprNewFunCall( $2, $4 ); } + | WHILE WITH DoArgList + { $$ = hb_compExprNewFunCall( yy_strdup("WHILE"), $3 ); } ; -DoArgList : ',' { hb_compGenPushNil(); hb_compGenPushNil(); $$ = 2; } - | DoExpression { $$ = 1; } - | DoArgList ',' { hb_compGenPushNil(); $$++; } - | DoArgList ',' DoExpression { $$++; } - | ',' { hb_compGenPushNil(); } DoExpression { $$ = 2; } +DoArgList : ',' { $$ = hb_compExprAddListExpr( hb_compExprNewArgList( hb_compExprNewNil() ), hb_compExprNewNil() ); } + | ',' DoArgument { $$ = hb_compExprAddListExpr( hb_compExprNewArgList( hb_compExprNewNil() ), $2 ); } + | DoArgument { $$ = hb_compExprNewArgList( $1 ); } + | DoArgList ',' { $$ = hb_compExprAddListExpr( $1, hb_compExprNewNil() ); } + | DoArgList ',' DoArgument { $$ = hb_compExprAddListExpr( $1, $3 ); } ; -DoExpression: IDENTIFIER { hb_compExprDelete( hb_compExprGenPush( hb_compExprNewVarRef( $1 ) ) ); } - | SimpleExpression { hb_compExprDelete( hb_compExprGenPush( $1 ) ); } - | PareExpList { hb_compExprDelete( hb_compExprGenPush( $1 ) ); } +DoArgument : IDENTIFIER { $$ = hb_compExprNewVarRef( $1 ); } + | '@' IDENTIFIER '(' ')' { $$ = hb_compExprNewFunRef( $2 ); } + | SimpleExpression { $$ = $1; } + | PareExpList { $$ = $1; } ; -Crlf : '\n' { ++iLine; } +Crlf : '\n' { ++hb_comp_iLine; } | ';' { hb_comp_bDontGenLineNum = TRUE; } ; @@ -1142,17 +1352,17 @@ int harbour_main( char * szName ) /* Generate the starting procedure frame */ if( hb_comp_bStartProc ) - hb_compFunDef( yy_strupr( yy_strdup( szName ) ), FS_PUBLIC, FUN_PROCEDURE ); + hb_compFunctionAdd( yy_strupr( yy_strdup( szName ) ), FS_PUBLIC, FUN_PROCEDURE ); else /* Don't pass the name of module if the code for starting procedure * will be not generated. The name cannot be placed as first symbol * because this symbol can be used as function call or memvar's name. */ - hb_compFunDef( yy_strupr( yy_strdup( "" ) ), FS_PUBLIC, FUN_PROCEDURE ); + hb_compFunctionAdd( yy_strupr( yy_strdup( "" ) ), FS_PUBLIC, FUN_PROCEDURE ); yyparse(); - hb_compGenExterns(); /* generates EXTERN symbols names */ + hb_compExternGen(); /* generates EXTERN symbols names */ if( hb_comp_pInitFunc ) { @@ -1163,7 +1373,7 @@ int harbour_main( char * szName ) hb_comp_pInitFunc->pCode[ 4 ] = HB_HIBYTE( hb_comp_iStaticCnt ); hb_comp_pInitFunc->iStaticsBase = hb_comp_iStaticCnt; - pSym = hb_compAddSymbol( hb_comp_pInitFunc->szName, NULL ); + pSym = hb_compSymbolAdd( hb_comp_pInitFunc->szName, NULL ); pSym->cScope |= hb_comp_pInitFunc->cScope; hb_comp_functions.pLast->pNext = hb_comp_pInitFunc; ++hb_comp_functions.iCount; @@ -1184,11 +1394,12 @@ int harbour_main( char * szName ) void yyerror( char * s ) { if( yytext[ 0 ] == '\n' ) - hb_compGenError( hb_comp_szCErrors, 'E', ERR_YACC, s, "" ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_YACC, s, "" ); else - hb_compGenError( hb_comp_szCErrors, 'E', ERR_YACC, s, yytext ); + hb_compGenError( hb_comp_szCErrors, 'F', ERR_YACC, s, yytext ); } + BOOL Include( char * szFileName, PATHNAMES * pSearch ) { PFILE pFile; @@ -1221,9 +1432,6 @@ BOOL Include( char * szFileName, PATHNAMES * pSearch ) return FALSE; } - if( ! hb_comp_bQuiet ) - printf( "\nCompiling \'%s\'\n", szFileName ); - pFile = ( PFILE ) hb_xgrab( sizeof( _FILE ) ); pFile->handle = yyin; pFile->szFileName = szFileName; @@ -1233,8 +1441,8 @@ BOOL Include( char * szFileName, PATHNAMES * pSearch ) hb_comp_files.pLast = pFile; else { - hb_comp_files.pLast->iLine = iLine; - iLine = 1; + hb_comp_files.pLast->iLine = hb_comp_iLine; + hb_comp_iLine = 1; pFile->pPrev = hb_comp_files.pLast; hb_comp_files.pLast = pFile; } @@ -1259,9 +1467,7 @@ int yywrap( void ) /* handles the EOF of the currently processed file */ pLast = hb_comp_files.pLast; fclose( hb_comp_files.pLast->handle ); hb_comp_files.pLast = ( PFILE ) ( ( PFILE ) hb_comp_files.pLast )->pPrev; - iLine = hb_comp_files.pLast->iLine; - if( ! hb_comp_bQuiet ) - printf( "\nCompiling %s\n", hb_comp_files.pLast->szFileName ); + hb_comp_iLine = hb_comp_files.pLast->iLine; #ifdef __cplusplus yy_delete_buffer( ( YY_BUFFER_STATE ) ( ( PFILE ) pLast )->pBuffer ); #else @@ -1285,7 +1491,7 @@ int yywrap( void ) /* handles the EOF of the currently processed file */ * This function stores the position in pcode buffer where the FOR/WHILE * loop starts. It will be used to fix any LOOP/EXIT statements */ -static void LoopStart( void ) +static void hb_compLoopStart( void ) { PTR_LOOPEXIT pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof( LOOPEXIT ) ); @@ -1304,121 +1510,176 @@ static void LoopStart( void ) pLoop->pExitList = NULL; pLoop->pLoopList = NULL; pLoop->ulOffset = hb_comp_functions.pLast->lPCodePos; /* store the start position */ - pLoop->iLine = iLine; + pLoop->iLine = hb_comp_iLine; pLoop->wSeqCounter = hb_comp_wSeqCounter; /* store current SEQUENCE counter */ } /* * Stores the position of LOOP statement to fix it later at the end of loop */ -static void LoopLoop( void ) +static void hb_compLoopLoop( void ) { - PTR_LOOPEXIT pLast, pLoop; - - pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof( LOOPEXIT ) ); - - pLoop->pLoopList = NULL; - pLoop->ulOffset = hb_comp_functions.pLast->lPCodePos; /* store the position to fix */ - - pLast = hb_comp_pLoops; - while( pLast->pNext ) - pLast = pLast->pNext; - - if( pLast->wSeqCounter != hb_comp_wSeqCounter ) + if( ! hb_comp_pLoops ) { - /* Attempt to LOOP from BEGIN/END sequence - * Current SEQUENCE counter is different then at the beginning of loop - * Notice that LOOP is allowed in RECOVER code. - */ hb_compGenError( hb_comp_szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "LOOP", NULL ); } + else + { + PTR_LOOPEXIT pLast, pLoop; - while( pLast->pLoopList ) - pLast = pLast->pLoopList; + pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof( LOOPEXIT ) ); - pLast->pLoopList = pLoop; + pLoop->pLoopList = NULL; + pLoop->ulOffset = hb_comp_functions.pLast->lPCodePos; /* store the position to fix */ - hb_compGenJump( 0 ); + pLast = hb_comp_pLoops; + while( pLast->pNext ) + pLast = pLast->pNext; + + if( pLast->wSeqCounter != hb_comp_wSeqCounter ) + { + /* Attempt to LOOP from BEGIN/END sequence + * Current SEQUENCE counter is different then at the beginning of loop + * Notice that LOOP is allowed in RECOVER code. + */ + hb_compGenError( hb_comp_szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "LOOP", NULL ); + } + else + { + while( pLast->pLoopList ) + pLast = pLast->pLoopList; + + pLast->pLoopList = pLoop; + + hb_compGenJump( 0 ); + } + } } /* * Stores the position of EXIT statement to fix it later at the end of loop */ -static void LoopExit( void ) +static void hb_compLoopExit( void ) { - PTR_LOOPEXIT pLast, pLoop; - - pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof( LOOPEXIT ) ); - - pLoop->pExitList = NULL; - pLoop->ulOffset = hb_comp_functions.pLast->lPCodePos; /* store the position to fix */ - - pLast = hb_comp_pLoops; - while( pLast->pNext ) - pLast = pLast->pNext; - - if( pLast->wSeqCounter != hb_comp_wSeqCounter ) + if( ! hb_comp_pLoops ) { - /* Attempt to LOOP from BEGIN/END sequence - * Current SEQUENCE counter is different then at the beginning of loop - * Notice that LOOP is allowed in RECOVER code. - */ hb_compGenError( hb_comp_szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "EXIT", NULL ); } + else + { + PTR_LOOPEXIT pLast, pLoop; - while( pLast->pExitList ) - pLast = pLast->pExitList; + pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof( LOOPEXIT ) ); - pLast->pExitList = pLoop; + pLoop->pExitList = NULL; + pLoop->ulOffset = hb_comp_functions.pLast->lPCodePos; /* store the position to fix */ - hb_compGenJump( 0 ); + pLast = hb_comp_pLoops; + while( pLast->pNext ) + pLast = pLast->pNext; + + if( pLast->wSeqCounter != hb_comp_wSeqCounter ) + { + /* Attempt to LOOP from BEGIN/END sequence + * Current SEQUENCE counter is different then at the beginning of loop + * Notice that LOOP is allowed in RECOVER code. + */ + hb_compGenError( hb_comp_szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "EXIT", NULL ); + } + else + { + while( pLast->pExitList ) + pLast = pLast->pExitList; + + pLast->pExitList = pLoop; + + hb_compGenJump( 0 ); + } + } } /* * Fixes the LOOP statement */ -static void LoopHere( void ) +static void hb_compLoopHere( void ) { PTR_LOOPEXIT pLoop = hb_comp_pLoops, pFree; - while( pLoop->pNext ) - pLoop = pLoop->pNext; - - pLoop = pLoop->pLoopList; - while( pLoop ) + if( pLoop ) { - hb_compGenJumpHere( pLoop->ulOffset + 1 ); - pFree = pLoop; + while( pLoop->pNext ) + pLoop = pLoop->pNext; + pLoop = pLoop->pLoopList; - hb_xfree( ( void * ) pFree ); + while( pLoop ) + { + hb_compGenJumpHere( pLoop->ulOffset + 1 ); + pFree = pLoop; + pLoop = pLoop->pLoopList; + hb_xfree( ( void * ) pFree ); + } } } /* * Fixes the EXIT statements and releases memory allocated for current loop */ -static void LoopEnd( void ) +static void hb_compLoopEnd( void ) { PTR_LOOPEXIT pExit, pLoop = hb_comp_pLoops, pLast = hb_comp_pLoops, pFree; - while( pLoop->pNext ) + if( pLoop ) { - pLast = pLoop; - pLoop = pLoop->pNext; - } + while( pLoop->pNext ) + { + pLast = pLoop; + pLoop = pLoop->pNext; + } - pExit = pLoop->pExitList; - while( pExit ) - { - hb_compGenJumpHere( pExit->ulOffset + 1 ); - pFree = pExit; - pExit = pExit->pExitList; - hb_xfree( ( void * ) pFree ); - } + pExit = pLoop->pExitList; + while( pExit ) + { + hb_compGenJumpHere( pExit->ulOffset + 1 ); + pFree = pExit; + pExit = pExit->pExitList; + hb_xfree( ( void * ) pFree ); + } - pLast->pNext = NULL; - if( pLoop == hb_comp_pLoops ) - hb_comp_pLoops = NULL; - hb_xfree( ( void * ) pLoop ); + pLast->pNext = NULL; + if( pLoop == hb_comp_pLoops ) + hb_comp_pLoops = NULL; + hb_xfree( ( void * ) pLoop ); + } +} + +static void * hb_compElseIfGen( void * pFirst, ULONG ulOffset ) +{ + PELSEIF pElseIf = ( PELSEIF ) hb_xgrab( sizeof( _ELSEIF ) ), pLast; + + pElseIf->ulOffset = ulOffset; + pElseIf->pNext = 0; + + if( ! pFirst ) + pFirst = pElseIf; + else + { + pLast = ( PELSEIF ) pFirst; + while( pLast->pNext ) + pLast = pLast->pNext; + pLast->pNext = pElseIf; + } + return pFirst; +} + + +static void hb_compElseIfFix( void * pFixElseIfs ) +{ + PELSEIF pFix = ( PELSEIF ) pFixElseIfs; + + while( pFix ) + { + hb_compGenJumpHere( pFix->ulOffset ); + pFix = pFix->pNext; + } } diff --git a/harbour/source/debug/debugger.prg b/harbour/source/debug/debugger.prg index 02c77fecf9..ce1bca9198 100644 --- a/harbour/source/debug/debugger.prg +++ b/harbour/source/debug/debugger.prg @@ -868,8 +868,6 @@ METHOD GetHotKeyPos( cKey ) CLASS TDbMenu return 0 -return .f. - METHOD GoBottom() CLASS TDbMenu local oPopup diff --git a/harbour/source/pp/hbpp.c b/harbour/source/pp/hbpp.c index 7a9302d117..c436257e0e 100644 --- a/harbour/source/pp/hbpp.c +++ b/harbour/source/pp/hbpp.c @@ -184,7 +184,7 @@ int ParseDirective( char* sLine ) if ( i == 4 && memcmp ( sDirective, "ELSE", 4 ) == 0 ) { /* --- #else --- */ if ( nCondCompile == 0 ) - hb_compGenError( _szPErrors, 'P', ERR_DIRECTIVE_ELSE, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_DIRECTIVE_ELSE, NULL, NULL ); else if ( nCondCompile == 1 || aCondCompile[nCondCompile-2] ) aCondCompile[nCondCompile-1] = 1 - aCondCompile[nCondCompile-1]; } @@ -192,7 +192,7 @@ int ParseDirective( char* sLine ) else if ( i == 5 && memcmp ( sDirective, "ENDIF", 5 ) == 0 ) { /* --- #endif --- */ if ( nCondCompile == 0 ) - hb_compGenError( _szPErrors, 'P', ERR_DIRECTIVE_ENDIF, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_DIRECTIVE_ENDIF, NULL, NULL ); else nCondCompile--; } @@ -208,8 +208,8 @@ int ParseDirective( char* sLine ) { /* --- #include --- */ char cDelimChar; - if ( *sLine != '\"' && *sLine != '\'' && *sLine != '<' && *sLine != '`' ) - hb_compGenError( _szPErrors, 'P', ERR_WRONG_NAME, NULL, NULL ); + if ( *sLine != '\"' && *sLine != '\'' && *sLine != '<' ) + hb_compGenError( _szPErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); cDelimChar = *sLine; if( cDelimChar == '<' ) @@ -220,7 +220,7 @@ int ParseDirective( char* sLine ) sLine++; i = 0; while ( *(sLine+i) != '\0' && *(sLine+i) != cDelimChar ) i++; if ( *(sLine+i) != cDelimChar ) - hb_compGenError( _szPErrors, 'P', ERR_WRONG_NAME, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); *(sLine+i) = '\0'; /* if ((handl_i = fopen(sLine, "r")) == NULL) */ @@ -232,7 +232,7 @@ int ParseDirective( char* sLine ) fclose(handl_i); } else - hb_compGenError( _szPErrors, 'P', ERR_CANNOT_OPEN, sLine, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_CANNOT_OPEN, sLine, NULL ); } else if ( i == 6 && memcmp ( sDirective, "DEFINE", 6 ) == 0 ) @@ -256,12 +256,12 @@ int ParseDirective( char* sLine ) else if ( i == 5 && memcmp ( sDirective, "ERROR", 5 ) == 0 ) /* --- #error --- */ - hb_compGenError( _szPErrors, 'P', ERR_EXPLICIT, sLine, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_EXPLICIT, sLine, NULL ); else if ( i == 4 && memcmp ( sDirective, "LINE", 4 ) == 0 ) return -1; else - hb_compGenError( _szPErrors, 'P', ERR_WRONG_DIRECTIVE, sDirective, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_WRONG_DIRECTIVE, sDirective, NULL ); } return 0; } @@ -300,7 +300,7 @@ int ParseDefine( char* sLine) lastdef->pars = ( npars <= 0 )? NULL : strodup ( pars ); } else - hb_compGenError( _szPErrors, 'P', ERR_DEFINE_ABSENT, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); return 0; } @@ -365,7 +365,7 @@ int ParseIfdef( char* sLine, int usl) { NextWord( &sLine, defname, FALSE ); if ( *defname == '\0' ) - hb_compGenError( _szPErrors, 'P', ERR_DEFINE_ABSENT, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); } if ( nCondCompile == maxCondCompile ) { @@ -468,7 +468,7 @@ void ParseCommand( char* sLine, int com_or_xcom, int com_or_tra ) if ( (ipos = pp_strAt( "=>", 2, sLine, strolen(sLine) )) > 0 ) stroncpy( mpatt, sLine, ipos-1 ); else - hb_compGenError( _szPErrors, 'P', ERR_COMMAND_DEFINITION, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_COMMAND_DEFINITION, NULL, NULL ); RemoveSlash( mpatt ); mlen = strotrim( mpatt ); @@ -535,13 +535,13 @@ void ConvertPatterns ( char *mpatt, int mlen, char *rpatt, int rlen ) { if ( *(exppatt+explen-1) == '*' ) explen--; else - hb_compGenError( _szPErrors, 'P', ERR_PATTERN_DEFINITION, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); } else if ( exptype == '4' ) { if ( *(exppatt+explen-1) == ')' ) explen--; else - hb_compGenError( _szPErrors, 'P', ERR_PATTERN_DEFINITION, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); } rmlen = i - ipos + 1; /* Convert match marker into inner format */ @@ -756,7 +756,7 @@ int ParseExpression( char* sLine, char* sOutLine ) while ( ipos != 0 ); kolpass++; if( kolpass > 20 && rezDef ) - hb_compGenError( _szPErrors, 'P', ERR_RECURSE, NULL, NULL ); + hb_compGenError( _szPErrors, 'F', ERR_RECURSE, NULL, NULL ); } while ( rezDef || rezTra || rezCom );