From 4979496da554d462ba0bec58697ebeb68c7dc64e Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Tue, 22 Jun 1999 23:45:57 +0000 Subject: [PATCH] ChangeLog:19990622-00:35 --- harbour/ChangeLog | 9 + harbour/include/compiler.h | 3 +- harbour/source/compiler/harbour.l | 22 +- harbour/source/compiler/harbour.y | 648 ++++++++++++++++-------------- 4 files changed, 370 insertions(+), 312 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 78d1ba2e8f..68fe191d1e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +19990622-00:35 Ryszard Glab +* source/compiler/harbour.y +* source/compiler/harbour.l + * removed some unnecessary rules + * added the very begginning of MEMVAR support + +* include/compiler.h + + added pMemvars member to _FUNC structure + 19990622-14:00 CET Victor Szel * source/rdd/rdd.api moved to /include diff --git a/harbour/include/compiler.h b/harbour/include/compiler.h index 3fb28c87b2..da2d45265e 100644 --- a/harbour/include/compiler.h +++ b/harbour/include/compiler.h @@ -25,6 +25,7 @@ typedef struct __FUNC /* functions definition support */ PVAR pLocals; /* pointer to local variables list */ PVAR pStatics; /* pointer to static variables list */ PVAR pFields; /* pointer to fields variables list */ + PVAR pMemvars; /* pointer to memvar variables list */ BYTE * pCode; /* pointer to a memory block where pcode is stored */ LONG lPCodeSize; /* total memory size for pcode */ LONG lPCodePos; /* actual pcode offset */ @@ -66,6 +67,6 @@ WORD GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a functi void * OurMalloc( LONG lSize ); /* our malloc with error control */ void * OurRealloc( void * p, LONG lSize ); /* our malloc with error control */ -#define OurFree( p ) free( (p) ); /* just for symetry -we can expand it later */ +void OurFree( void * p ); /* releases allocated memory */ #endif /* COMPILER_H_ */ diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index f8c9466927..129ff2cfbf 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -19,9 +19,13 @@ #include "hberrors.h" #include "types.h" -void yyerror( char * ); +/* Functions defined in harbour.y */ char *yy_strupr( char * ); char * yy_strdup( char *p ); +void OurFree( void * ); + +/* YACC functions */ +void yyerror( char * ); static void yyunput( int, char * ); #undef yywrap /* to implement our own yywrap() funtion to handle EOFs */ #ifdef __cplusplus @@ -31,7 +35,8 @@ int yywrap( void ); #endif #undef YY_INPUT /* to implement our own YY_INPUT function to manage PRGs without \n at the end */ extern FILE * yyin; /* currently yacc parsed file */ - /* Following three lines added for preprocessor */ + +/* Following three lines added for preprocessor */ extern FILE *yyppo; /* output .ppo file */ extern int lPpo; /* flag indicating, is ppo output needed */ extern int PreProcess( FILE*, FILE*, char *); @@ -97,7 +102,7 @@ SubArray "]"[ \t]*"[" Separator {SpaceTab} -%x DEFINE STRING1 STRING2 STRING3 +%x STRING1 STRING2 STRING3 %x NEXT_ BREAK_ CASE_ DO_ WHILE_ WITH_ END_ EXIT_ EXTERNAL_ FIELD_ %x FOR_ FUNCTION_ IIF_ IF_ IN_ INIT_ LOCAL_ LOOP_ %x LINECONT_ @@ -195,8 +200,6 @@ Separator {SpaceTab} return yytext[ 0 ]; } -{Identifier}/{SpaceTab}*\n BEGIN 0; - {SpaceTab} ; \n.* _iState=LOOKUP; yyless( 1 ); ++iLine; if( ! _iQuiet ) printf( "\rline: %i", iLine ); return '\n'; @@ -279,7 +282,6 @@ Separator {SpaceTab} return IDENTIFIER; } } -. { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); } %{ /* ************************************************************************ */ %} @@ -477,7 +479,7 @@ Separator {SpaceTab} if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { - free( yylval.string ); + OurFree( (void *) yylval.string ); _iState =EXTERN; return EXTERN; } @@ -510,7 +512,7 @@ Separator {SpaceTab} if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { - free( yylval.string ); + OurFree( (void *) yylval.string ); _iState =FIELD; return FIELD; } @@ -1172,6 +1174,10 @@ Separator {SpaceTab} int yy_lex_input( char *buffer, int iBufferSize ) { +#ifdef __WATCOMC__ + iBufferSize =iBufferSize; +#else if( 0 && iBufferSize ) printf( "/* compiler warning */" ); +#endif return PreProcess( yyin, (lPpo)? yyppo:NULL, buffer ); } diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 6a2b20c8a7..a67096b2b0 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -27,9 +27,6 @@ #define debug_msg( x, z ) -#undef OurFree -#define OurFree( p ) if( p ) free(p); else {printf( "ERROR FREE" ); exit(4);} - /* TODO: #define this for various platforms */ #define PATH_DELIMITER "/\\" #define IS_PATH_SEP( c ) (strchr(PATH_DELIMITER, (c))!=NULL) @@ -190,6 +187,7 @@ PFUNCTION KillFunction( PFUNCTION ); /* releases all memory allocated by func PCOMSYMBOL KillSymbol( PCOMSYMBOL ); /* releases all memory allocated by symbol and returns the next one */ void Line( 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 MemvarPCode( BYTE , char * ); /* generates the pcode for memvar variable */ void Message( char * szMsgName ); /* sends a message to an object */ void MessageFix( char * szMsgName ); /* fix a generated message to an object */ void MessageDupl( char * szMsgName ); /* fix a one generated message to an object and duplicate */ @@ -247,12 +245,13 @@ typedef enum extern int iLine; /* currently compiled source code line */ -int iVarScope = 0; /* holds the scope for next variables to be defined */ -#define VS_LOCAL 0 /* different values for iVarScope */ -#define VS_STATIC 1 -#define VS_PARAMETER 2 -#define VS_FIELD 3 -#define VS_MEMVAR 4 +#define VS_LOCAL 1 +#define VS_STATIC 2 +#define VS_FIELD 4 +#define VS_MEMVAR 8 +#define VS_PARAMETER 16 +int iVarScope = VS_LOCAL; /* holds the scope for next variables to be defined */ + /* different values for iVarScope */ /* Table with parse errors */ char * _szErrors[] = { "Statement not allowed outside of procedure or function", @@ -279,18 +278,19 @@ char * _szErrors[] = { "Statement not allowed outside of procedure or function", }; /* Table with parse warnings */ -char * _szWarnings[] = { "Ambiguous reference, assuming memvar: \'%s\'", - "Variable: \'%s\' declared but not used in function: \'%s\'", - "CodeBlock Parameter: \'%s\' declared but not used in function: \'%s\'", - "Incompatible type in assignment to: \'%s\' expected: \'%s\'", - "Incompatible operand type: \'%s\' expected: \'Logical\'", - "Incompatible operand type: \'%s\' expected: \'Numeric\'", - "Incompatible operand types: \'%s\' and: \'%s\'", - "Suspicious type in assignment to: \'%s\' expected: \'%s\'", - "Suspicious operand type: \'UnKnown\' expected: \'%s\'", - "Suspicious operand type: \'UnKnown\' expected: \'Logical\'", - "Suspicious operand type: \'UnKnown\' expected: \'Numeric\'" - }; +char * _szWarnings[] = { + "Ambiguous reference, assuming memvar: \'%s\'", + "Variable: \'%s\' declared but not used in function: \'%s\'", + "CodeBlock Parameter: \'%s\' declared but not used in function: \'%s\'", + "Incompatible type in assignment to: \'%s\' expected: \'%s\'", + "Incompatible operand type: \'%s\' expected: \'Logical\'", + "Incompatible operand type: \'%s\' expected: \'Numeric\'", + "Incompatible operand types: \'%s\' and: \'%s\'", + "Suspicious type in assignment to: \'%s\' expected: \'%s\'", + "Suspicious operand type: \'UnKnown\' expected: \'%s\'", + "Suspicious operand type: \'UnKnown\' expected: \'Logical\'", + "Suspicious operand type: \'UnKnown\' expected: \'Numeric\'" + }; /* Table with reserved functions names * NOTE: THIS TABLE MUST BE SORTED ALPHABETICALLY @@ -439,7 +439,7 @@ char cVarType = ' '; /* current declared variable type */ %token INC DEC ALIAS DOCASE CASE OTHERWISE ENDCASE ENDDO MEMVAR %token WHILE EXIT LOOP END FOR NEXT TO STEP LE GE FIELD IN PARAMETERS %token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ EXITLOOP -%token PRIVATE BEGINSEQ BREAK RECOVER USING DO WITH SELF MEMVAR +%token PRIVATE BEGINSEQ BREAK RECOVER USING DO WITH SELF %token AS_NUMERIC AS_CHARACTER AS_LOGICAL AS_DATE AS_ARRAY AS_BLOCK AS_OBJECT DECLARE_FUN /*the lowest precedence*/ @@ -488,7 +488,7 @@ Source : Crlf | Include | VarDefs | FieldsDef - | MEMVAR IdentList + | MemvarDef | Function | Statement | Source Crlf @@ -498,7 +498,7 @@ Source : Crlf | Source { LineBody(); } Statement | Source VarDefs | Source FieldsDef - | Source MEMVAR IdentList + | Source MemvarDef ; Include : NE1 INCLUDE LITERAL { if( ! Include( $3, _pIncludePath ) ) @@ -661,47 +661,44 @@ Expression : NIL { PushNil(); } IfInline : IIF '(' Expression ',' { $$ = JumpFalse( 0 ); } IfInlExp ',' { $$ = Jump( 0 ); JumpHere( $5 ); } - IfInlExp ')' { - JumpHere( $8 ); + IfInlExp ')' { JumpHere( $8 ); + if( _iWarnings ) + { + PSTACK_VAL_TYPE pFree; - if( _iWarnings ) - { - PSTACK_VAL_TYPE pFree; + if( pStackValType ) + { + pFree = pStackValType; + debug_msg( "\n***---IIF()\n", NULL ); - if( pStackValType ) - { - pFree = pStackValType; - debug_msg( "\n***---IIF()\n", NULL ); - - pStackValType = pStackValType->pPrev; - OurFree( pFree ); - } - else - debug_msg( "\n***IIF() Compile time stack overflow\n", NULL ); - } - } + pStackValType = pStackValType->pPrev; + OurFree( (void *)pFree ); + } + else + debug_msg( "\n***IIF() Compile time stack overflow\n", NULL ); + } + } | IF '(' Expression ',' { $$ = JumpFalse( 0 ); } IfInlExp ',' { $$ = Jump( 0 ); JumpHere( $5 ); } - IfInlExp ')' { - JumpHere( $8 ); + IfInlExp ')' { JumpHere( $8 ); - if( _iWarnings ) - { - PSTACK_VAL_TYPE pFree; + if( _iWarnings ) + { + PSTACK_VAL_TYPE pFree; - if( pStackValType ) - { - pFree = pStackValType; - debug_msg( "\n***---IIF()\n", NULL ); + if( pStackValType ) + { + pFree = pStackValType; + debug_msg( "\n***---IIF()\n", NULL ); - pStackValType = pStackValType->pPrev; - OurFree( pFree ); - } - else - debug_msg( "\n***IIF() Compile time stack overflow\n", NULL ); - } - } + pStackValType = pStackValType->pPrev; + OurFree( (void *)pFree ); + } + else + debug_msg( "\n***IIF() Compile time stack overflow\n", NULL ); + } + } ; IfInlExp : /* nothing => nil */ { PushNil(); } @@ -925,6 +922,13 @@ FieldList : IDENTIFIER { cVarType = ' '; $$=FieldsCo | FieldList IN IDENTIFIER { SetAlias( $3, $1 ); } ; +MemvarDef : MEMVAR { iVarScope = VS_MEMVAR; } MemvarList Crlf { LineBody(); } + ; + +MemvarList : IDENTIFIER { AddVar( $1 ); } + | MemvarList ',' IDENTIFIER { AddVar( $3 ); } + ; + IdentList : IDENTIFIER {} | IdentList ',' IDENTIFIER {} ; @@ -1155,6 +1159,10 @@ int harbour_main( int argc, char * argv[] ) _iRestrictSymbolLength = 1; break; + case 'a': + case 'A': + break; + case 'd': case 'D': /* defines a Lex #define from the command line */ { @@ -1259,6 +1267,10 @@ int harbour_main( int argc, char * argv[] ) _iAltSymbolTableInit = 1; break; + case 'v': + case 'V': + break; + case 'w': case 'W': _iWarnings = 1; @@ -1417,7 +1429,7 @@ int harbour_main( int argc, char * argv[] ) printf( "Can't open input file: %s\n", szFileName ); iStatus = 1; } - OurFree( pFileName ); + OurFree( (void *) pFileName ); } else PrintUsage( argv[ 0 ] ); @@ -1742,6 +1754,18 @@ void AddVar( char * szVarName ) pLastVar->pNext = pVar; } break; + + case VS_MEMVAR: + if( ! pFunc->pMemvars ) + pFunc->pMemvars = pVar; + else + { + pLastVar = pFunc->pMemvars; + while( pLastVar->pNext ) + pLastVar = pLastVar->pNext; + pLastVar->pNext = pVar; + } + break; } } @@ -1796,7 +1820,7 @@ int Include( char * szFileName, PATHNAMES *pSearch ) return 0; } } - OurFree( pFileName ); + OurFree( (void *) pFileName ); } else return 0; @@ -1897,6 +1921,7 @@ PFUNCTION FunctionNew( char *szName, char cScope ) pFunc->pLocals = 0; pFunc->pStatics = 0; pFunc->pFields = 0; + pFunc->pMemvars = 0; pFunc->pCode = 0; pFunc->lPCodeSize = 0; pFunc->lPCodePos = 0; @@ -1998,7 +2023,11 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag char chr; FILE * yyc; /* file handle for C output */ +#ifdef __WATCOMC__ + szName =NULL; /* Watcom complains about unreachable code in if(0) */ +#else if( 0 && szName ) printf("/* just to keep compiler silent */" ); +#endif yyc = fopen( szFileName, "wb" ); if( ! yyc ) @@ -2667,7 +2696,7 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag while( pFunc ) { funcalls.pFirst =pFunc->pNext; - OurFree( pFunc ); /*NOTE: szName will be released by KillSymbol() */ + OurFree( (void *) pFunc ); /*NOTE: szName will be released by KillSymbol() */ pFunc =funcalls.pFirst; } @@ -2689,8 +2718,8 @@ PFUNCTION KillFunction( PFUNCTION pFunc ) pVar = pFunc->pLocals; pFunc->pLocals =pVar->pNext; - OurFree( pVar->szName ); - OurFree( pVar ); + OurFree( (void *) pVar->szName ); + OurFree( (void *) pVar ); } while( pFunc->pStatics ) @@ -2698,8 +2727,8 @@ PFUNCTION KillFunction( PFUNCTION pFunc ) pVar = pFunc->pStatics; pFunc->pStatics =pVar->pNext; - OurFree( pVar->szName ); - OurFree( pVar ); + OurFree( (void *) pVar->szName ); + OurFree( (void *) pVar ); } while( pFunc->pFields ) @@ -2707,17 +2736,30 @@ PFUNCTION KillFunction( PFUNCTION pFunc ) pVar = pFunc->pFields; pFunc->pFields =pVar->pNext; - OurFree( pVar->szName ); + OurFree( (void *) pVar->szName ); if( pVar->szAlias ) { - OurFree( pVar->szAlias ); + OurFree( (void *) pVar->szAlias ); } - OurFree( pVar ); + OurFree( (void *) pVar ); } - OurFree( pFunc->pCode ); -/* OurFree( pFunc->szName ); The name will be released in KillSymbol() */ - OurFree( pFunc ); + while( pFunc->pMemvars ) + { + pVar =pFunc->pMemvars; + pFunc->pMemvars =pVar->pNext; + + OurFree( (void *) pVar->szName ); + if( pVar->szAlias ) + { + OurFree( (void *) pVar->szAlias ); + } + OurFree( (void *) pVar ); + } + + OurFree( (void *) pFunc->pCode ); +/* OurFree( (void *) pFunc->szName ); The name will be released in KillSymbol() */ + OurFree( (void *) pFunc ); return pNext; } @@ -2727,8 +2769,8 @@ PCOMSYMBOL KillSymbol( PCOMSYMBOL pSym ) { PCOMSYMBOL pNext = pSym->pNext; - OurFree( pSym->szName ); - OurFree( pSym ); + OurFree( (void *) pSym->szName ); + OurFree( (void *) pSym ); return pNext; } @@ -2752,7 +2794,7 @@ void GenExterns( void ) /* generates the symbols for the EXTERN names */ } pDelete = pExterns; pExterns = pExterns->pNext; - OurFree( pDelete ); + OurFree( (void *) pDelete ); } } @@ -2841,8 +2883,8 @@ WORD GetVarPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a var pNewStackType->pPrev = pStackValType; pStackValType = pNewStackType; - debug_msg( "\n***GetVarPos()\n", NULL ); - } + debug_msg( "\n***GetVarPos()\n", NULL ); + } return wVar; } else @@ -3066,7 +3108,7 @@ void Inc( void ) sType[1] = 0; } else - debug_msg( "\n***Inc() Compile time stack overflow\n", NULL ); + debug_msg( "\n***Inc() Compile time stack overflow\n", NULL ); if( pStackValType && pStackValType->cType == ' ' ) @@ -3098,7 +3140,7 @@ WORD JumpFalse( int iOffset ) sType[1] = 0; } else - debug_msg( "\n***HB_P_JUMPFALSE Compile time stack overflow\n", NULL ); + debug_msg( "\n***HB_P_JUMPFALSE Compile time stack overflow\n", NULL ); /* compile time Operand value */ if( pStackValType && pStackValType->cType == ' ' ) @@ -3117,7 +3159,7 @@ WORD JumpFalse( int iOffset ) if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } @@ -3152,7 +3194,7 @@ WORD JumpTrue( int iOffset ) sType[1] = 0; } else - debug_msg( "\n***HB_P_JUMPTRUE Compile time stack overflow\n", NULL ); + debug_msg( "\n***HB_P_JUMPTRUE Compile time stack overflow\n", NULL ); /* compile time Operand value */ if( pStackValType && pStackValType->cType == ' ' ) @@ -3171,7 +3213,7 @@ WORD JumpTrue( int iOffset ) if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } @@ -3196,6 +3238,28 @@ void LineBody( void ) /* generates the pcode with the currently compiled source GenPCode3( HB_P_LINE, LOBYTE( iLine ), HIBYTE( iLine ) ); } +/* + * Function generates passed pcode for passed variable name + */ +void MemvarPCode( BYTE bPCode, char * szVarName ) +{ + WORD wVar; + + GenWarning( WARN_AMBIGUOUS_VAR, szVarName, NULL ); + + if( ( wVar = GetSymbolPos( szVarName ) ) ) + { + wVar -=(_iStartProc ? 1: 2); + GenPCode3( bPCode, LOBYTE( wVar ), HIBYTE( wVar ) ); + } + else + { + AddSymbol( szVarName ); + wVar = GetSymbolPos( szVarName ) - (_iStartProc ? 1: 2); + GenPCode3( bPCode, LOBYTE( wVar ), HIBYTE( wVar ) ); + } +} + void Message( char * szMsgName ) /* sends a message to an object */ { WORD wSym = GetSymbolPos( szMsgName ); @@ -3283,19 +3347,8 @@ void PopId( char * szVarName ) /* generates the pcode to pop a value from the vi GenPCode3( HB_P_POPSTATIC, LOBYTE( iVar ), HIBYTE( iVar ) ); else { - GenWarning( WARN_AMBIGUOUS_VAR, szVarName, NULL ); - - iVar = GetSymbolPos( szVarName ); - if( iVar - _iStartProc ? 1: 2 ) - GenPCode3( HB_P_POPMEMVAR, LOBYTE( iVar ), HIBYTE( iVar ) ); - - else - { - AddSymbol( szVarName ); - iVar = GetSymbolPos( szVarName ) - _iStartProc ? 1: 2; - GenPCode3( HB_P_POPMEMVAR, LOBYTE( iVar ), HIBYTE( iVar ) ); - } - } + MemvarPCode( HB_P_POPMEMVAR, szVarName ); + } } if( _iWarnings ) @@ -3315,7 +3368,7 @@ void PopId( char * szVarName ) /* generates the pcode to pop a value from the vi pStackValType = pStackValType->pPrev; } else - debug_msg( "\n***PopId() Compile time stack overflow\n", NULL ); + debug_msg( "\n***PopId() Compile time stack overflow\n", NULL ); if( pVarType && pStackValType && pVarType->cType != ' ' && pStackValType->cType == ' ' ) GenWarning( WARN_ASSIGN_SUSPECT, szVarName, sType ); @@ -3325,7 +3378,7 @@ void PopId( char * szVarName ) /* generates the pcode to pop a value from the vi /* compile time variable has to be released */ if( pVarType ) { - OurFree( pVarType ); + OurFree( (void *) pVarType ); } debug_msg( "\n***--- Var at PopId()\n", NULL ); @@ -3340,12 +3393,12 @@ void PopId( char * szVarName ) /* generates the pcode to pop a value from the vi } else { - debug_msg( "\n***PopId() Compile time stack overflow\n", NULL ); + debug_msg( "\n***PopId() Compile time stack overflow\n", NULL ); } if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } } @@ -3372,31 +3425,21 @@ void PushId( char * szVarName ) /* generates the pcode to push a variable value GenPCode3( HB_P_PUSHSTATIC, LOBYTE( iVar ), HIBYTE( iVar ) ); else { - GenWarning( WARN_AMBIGUOUS_VAR, szVarName, NULL ); - - iVar = GetSymbolPos( szVarName ) - _iStartProc ? 1: 2; - if( iVar ) - GenPCode3( HB_P_PUSHMEMVAR, LOBYTE( iVar ), HIBYTE( iVar ) ); - else - { - AddSymbol( szVarName ); - iVar = GetSymbolPos( szVarName ) - _iStartProc ? 1: 2; - GenPCode3( HB_P_PUSHMEMVAR, LOBYTE( iVar ), HIBYTE( iVar ) ); - } - - if( _iWarnings ) - { - PSTACK_VAL_TYPE pNewStackType; - - pNewStackType = ( STACK_VAL_TYPE * )OurMalloc( sizeof( STACK_VAL_TYPE ) ); - pNewStackType->cType = cVarType; - pNewStackType->pPrev = pStackValType; - - pStackValType = pNewStackType; - debug_msg( "\n***HB_P_PUSHMEMVAR\n ", NULL ); - } + MemvarPCode( HB_P_PUSHMEMVAR, szVarName ); } } + + if( _iWarnings ) + { + PSTACK_VAL_TYPE pNewStackType; + + pNewStackType = ( STACK_VAL_TYPE * )OurMalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType->cType = cVarType; + pNewStackType->pPrev = pStackValType; + + pStackValType = pNewStackType; + debug_msg( "\n***HB_P_PUSHMEMVAR\n ", NULL ); + } } void PushIdByRef( char * szVarName ) /* generates the pcode to push a variable by reference to the virtual machine stack */ @@ -3421,23 +3464,7 @@ void PushIdByRef( char * szVarName ) /* generates the pcode to push a variable b GenPCode3( HB_P_PUSHSTATICREF, LOBYTE( iVar ), HIBYTE( iVar ) ); else { - iVar = GetStaticVarPos( szVarName ); - if( iVar ) - GenPCode3( HB_P_PUSHSTATICREF, LOBYTE( iVar ), HIBYTE( iVar ) ); - else - { - GenWarning( WARN_AMBIGUOUS_VAR, szVarName, NULL ); - - iVar = GetSymbolPos( szVarName ) - _iStartProc ? 1: 2; - if( iVar ) - GenPCode3( HB_P_PUSHMEMVARREF, LOBYTE( iVar ), HIBYTE( iVar ) ); - else - { - AddSymbol( szVarName ); - iVar = GetSymbolPos( szVarName ) - _iStartProc ? 1: 2; - GenPCode3( HB_P_PUSHMEMVARREF, LOBYTE( iVar ), HIBYTE( iVar ) ); - } - } + MemvarPCode( HB_P_PUSHMEMVARREF, szVarName ); } } } @@ -3615,9 +3642,9 @@ void PushSymbol( char * szSymbolName, int iIsFunction ) char cType; if( iIsFunction ) - cType = GetSymbolOrd( wFunId - 1 )->cType; + cType = GetSymbolOrd( wFunId - 1 )->cType; else - cType = cVarType; + cType = cVarType; pNewStackType = ( STACK_VAL_TYPE * )OurMalloc( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = cType; @@ -3653,11 +3680,11 @@ void Dec( void ) if( pStackValType ) { - sType[0] = pStackValType->cType; - sType[1] = 0; + sType[0] = pStackValType->cType; + sType[1] = 0; } else - debug_msg( "\n***Dec() Compile time stack overflow\n", NULL ); + debug_msg( "\n***Dec() Compile time stack overflow\n", NULL ); if( pStackValType && pStackValType->cType == ' ' ) GenWarning( WARN_NUMERIC_SUSPECT, NULL, NULL ); @@ -3686,14 +3713,14 @@ void Do( BYTE bParams ) pFree = pStackValType; debug_msg( "\n***---Do() \n", NULL ); - if( pStackValType ) - pStackValType = pStackValType->pPrev; - else + if( pStackValType ) + pStackValType = pStackValType->pPrev; + else debug_msg( "\n***Do() Compile time stack overflow\n", NULL ); if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } @@ -3703,11 +3730,11 @@ void Do( BYTE bParams ) if( pStackValType ) pStackValType = pStackValType->pPrev; else - debug_msg( "\n***Do(2) Compile time stack overflow\n", NULL ); + debug_msg( "\n***Do(2) Compile time stack overflow\n", NULL ); if ( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } /* releasing the compile time procedure value */ @@ -3721,7 +3748,7 @@ void Do( BYTE bParams ) if ( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } } @@ -3766,12 +3793,12 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets /* Clear the compile time stack values (should be empty at this point) */ while( pStackValType ) { - PSTACK_VAL_TYPE pFree; + PSTACK_VAL_TYPE pFree; - debug_msg( "\n***Compile time stack underflow - type: %c\n", pStackValType->cType ); - pFree = pStackValType; - pStackValType = pStackValType->pPrev; - OurFree( pFree ); + debug_msg( "\n***Compile time stack underflow - type: %c\n", pStackValType->cType ); + pFree = pStackValType; + pStackValType = pStackValType->pPrev; + OurFree( (void *) pFree ); } pStackValType = 0; } @@ -3788,7 +3815,7 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets while( pLast ) { pLast = pLast->pNext; - OurFree( pDelete ); + OurFree( (void *) pDelete ); pDelete = pLast; } pReturns = 0; @@ -3823,14 +3850,14 @@ void Function( BYTE bParams ) pFree = pStackValType; debug_msg( "\n***---Function() parameter %i \n", i ); - if( pStackValType ) - pStackValType = pStackValType->pPrev; - else - debug_msg( "\n***Function() parameter %i Compile time stack overflow\n", i ); + if( pStackValType ) + pStackValType = pStackValType->pPrev; + else + debug_msg( "\n***Function() parameter %i Compile time stack overflow\n", i ); if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } @@ -3845,7 +3872,7 @@ void Function( BYTE bParams ) if ( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } } @@ -3865,15 +3892,15 @@ void GenArray( WORD wElements ) pFree = pStackValType; debug_msg( "\n***---element %i at GenArray()\n", wIndex ); - if( pStackValType ) - pStackValType = pStackValType->pPrev; - else + if( pStackValType ) + pStackValType = pStackValType->pPrev; + else debug_msg( "\n***GenArray() Compile time stack overflow\n", NULL ); - if ( pFree ) - { - OurFree( pFree ); - } + if ( pFree ) + { + OurFree( (void *) pFree ); + } } if( wElements == 0 ) @@ -3929,7 +3956,7 @@ void GenPCode1( BYTE byte ) if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } /* Releasing compile time array element index value */ @@ -3938,12 +3965,12 @@ void GenPCode1( BYTE byte ) if( pStackValType ) pStackValType = pStackValType->pPrev; - else + else debug_msg( "\n***HB_P_ARRAYPUT2 Compile time stack overflow\n", NULL ); if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } else if( byte == HB_P_POP || byte == HB_P_RETVALUE || byte == HB_P_FORTEST || byte == HB_P_ARRAYAT ) @@ -3955,173 +3982,173 @@ void GenPCode1( BYTE byte ) if( pStackValType ) pStackValType = pStackValType->pPrev; - else + else debug_msg( "\n***pCode: %i Compile time stack overflow\n", byte ); if( pFree ) { - OurFree( pFree ); + OurFree( (void *) pFree ); } } else if( byte == HB_P_MULT || byte == HB_P_DIVIDE || byte == HB_P_MODULUS || byte == HB_P_POWER || byte == HB_P_NEGATE ) { - PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; - char sType1[2], sType2[2]; + PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; + char sType1[2], sType2[2]; - /* 2nd. Operand (stack top)*/ - pOperand2 = pStackValType; + /* 2nd. Operand (stack top)*/ + pOperand2 = pStackValType; - /* skip back to the 1st. operand */ - if( pOperand2 ) - { - pOperand1 = pOperand2->pPrev; - sType2[0] = pOperand1->cType; - sType2[1] = 0; - } - else + /* skip back to the 1st. operand */ + if( pOperand2 ) + { + pOperand1 = pOperand2->pPrev; + sType2[0] = pOperand1->cType; + sType2[1] = 0; + } + else debug_msg( "\n***HB_P_MULT pCode: %i Compile time stack overflow\n", byte ); - /* skip back to the 1st. operand */ - if( pOperand1 ) - { - sType1[0] = pOperand1->cType; - sType1[1] = 0; - } - else + /* skip back to the 1st. operand */ + if( pOperand1 ) + { + sType1[0] = pOperand1->cType; + sType1[1] = 0; + } + else debug_msg( "\n***HB_P_MULT2 pCode: %i Compile time stack overflow\n", byte ); - if( pOperand1 && pOperand1->cType != 'N' && pOperand1->cType != ' ' ) - GenWarning( WARN_NUMERIC_TYPE, sType1, NULL ); - else if( pOperand1 && pOperand1->cType == ' ' ) - GenWarning( WARN_NUMERIC_SUSPECT, NULL, NULL ); + if( pOperand1 && pOperand1->cType != 'N' && pOperand1->cType != ' ' ) + GenWarning( WARN_NUMERIC_TYPE, sType1, NULL ); + else if( pOperand1 && pOperand1->cType == ' ' ) + GenWarning( WARN_NUMERIC_SUSPECT, NULL, NULL ); - if( pOperand2 && pOperand2->cType != 'N' && pOperand2->cType != ' ' ) - GenWarning( WARN_NUMERIC_TYPE, sType2, NULL ); - else if( pOperand2 && pOperand2->cType == ' ' ) - GenWarning( WARN_NUMERIC_SUSPECT, NULL, NULL ); + if( pOperand2 && pOperand2->cType != 'N' && pOperand2->cType != ' ' ) + GenWarning( WARN_NUMERIC_TYPE, sType2, NULL ); + else if( pOperand2 && pOperand2->cType == ' ' ) + GenWarning( WARN_NUMERIC_SUSPECT, NULL, NULL ); /* compile time 2nd. operand has to be released */ - if( pOperand2 ) - { - OurFree( pOperand2 ); - } + if( pOperand2 ) + { + OurFree( (void *) pOperand2 ); + } - /* compile time 1st. operand has to be released *but* result will be pushed and assumed numeric type */ - pStackValType = pOperand1; - pStackValType->cType = 'N'; + /* compile time 1st. operand has to be released *but* result will be pushed and assumed numeric type */ + pStackValType = pOperand1; + pStackValType->cType = 'N'; } else if( byte == HB_P_PLUS || byte == HB_P_MINUS ) { - PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; - char sType1[2], sType2[2], cType = ' '; + PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; + char sType1[2], sType2[2], cType = ' '; - /* 2nd. Operand (stack top)*/ - pOperand2 = pStackValType; + /* 2nd. Operand (stack top)*/ + pOperand2 = pStackValType; - /* skip back to the 1st. operand */ - if( pOperand2 ) - { - pOperand1 = pOperand2->pPrev; - sType2[0] = pOperand2->cType; - sType2[1] = 0; - } - else - debug_msg( "\n***HB_P_PLUS / HB_P_MINUS Compile time stack overflow\n", NULL ); + /* skip back to the 1st. operand */ + if( pOperand2 ) + { + pOperand1 = pOperand2->pPrev; + sType2[0] = pOperand2->cType; + sType2[1] = 0; + } + else + debug_msg( "\n***HB_P_PLUS / HB_P_MINUS Compile time stack overflow\n", NULL ); - if( pOperand1 ) - { - sType1[0] = pOperand1->cType; - sType1[1] = 0; - } - else + if( pOperand1 ) + { + sType1[0] = pOperand1->cType; + sType1[1] = 0; + } + else debug_msg( "\n***HB_P_PLUS / HB_P_MINUS2 Compile time stack overflow\n", NULL ); - if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType != ' ' && pOperand1->cType != pOperand2->cType ) - GenWarning( WARN_OPERANDS_INCOMPATBLE, sType1, sType2 ); - else if( pOperand1 && pOperand2 && pOperand2->cType != ' ' && pOperand1->cType == ' ' ) - GenWarning( WARN_OPERAND_SUSPECT, sType2, NULL ); - else if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType == ' ' ) - GenWarning( WARN_OPERAND_SUSPECT, sType1, NULL ); - else - cType = pOperand1->cType; + if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType != ' ' && pOperand1->cType != pOperand2->cType ) + GenWarning( WARN_OPERANDS_INCOMPATBLE, sType1, sType2 ); + else if( pOperand1 && pOperand2 && pOperand2->cType != ' ' && pOperand1->cType == ' ' ) + GenWarning( WARN_OPERAND_SUSPECT, sType2, NULL ); + else if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType == ' ' ) + GenWarning( WARN_OPERAND_SUSPECT, sType1, NULL ); + else + cType = pOperand1->cType; /* compile time 2nd. operand has to be released */ - if( pOperand2 ) - { - OurFree( pOperand2 ); - } + if( pOperand2 ) + { + OurFree( (void *) pOperand2 ); + } - /* compile time 1st. operand has to be released *but* result will be pushed and type as calculated */ - /* Resetting */ - pStackValType = pOperand1; - pStackValType->cType = cType; + /* compile time 1st. operand has to be released *but* result will be pushed and type as calculated */ + /* Resetting */ + pStackValType = pOperand1; + pStackValType->cType = cType; } else if( byte == HB_P_EQUAL || byte == HB_P_LESS || byte == HB_P_GREATER || byte == HB_P_INSTRING || byte == HB_P_LESSEQUAL || byte == HB_P_GREATEREQUAL || byte == HB_P_EXACTLYEQUAL || byte == HB_P_NOTEQUAL ) { - PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; - char sType1[2], sType2[2]; + PSTACK_VAL_TYPE pOperand1 = 0, pOperand2; + char sType1[2], sType2[2]; - /* 2nd. Operand (stack top)*/ - pOperand2 = pStackValType; + /* 2nd. Operand (stack top)*/ + pOperand2 = pStackValType; - /* skip back to the 1st. operand */ - if( pOperand2 ) - { - pOperand1 = pOperand2->pPrev; - sType2[0] = pOperand2->cType; - sType2[1] = 0; - } - else + /* skip back to the 1st. operand */ + if( pOperand2 ) + { + pOperand1 = pOperand2->pPrev; + sType2[0] = pOperand2->cType; + sType2[1] = 0; + } + else debug_msg( "\n***HB_P_EQUAL pCode: %i Compile time stack overflow\n", byte ); - if( pOperand1 ) - { - sType1[0] = pOperand1->cType; - sType1[1] = 0; - } - else + if( pOperand1 ) + { + sType1[0] = pOperand1->cType; + sType1[1] = 0; + } + else debug_msg( "\n***HB_P_EQUAL2 pCode: %i Compile time stack overflow\n", byte ); - if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType != ' ' && pOperand1->cType != pOperand2->cType ) - GenWarning( WARN_OPERANDS_INCOMPATBLE, sType1, sType2 ); - else if( pOperand1 && pOperand2 && pOperand2->cType != ' ' && pOperand1->cType == ' ' ) - GenWarning( WARN_OPERAND_SUSPECT, sType2, NULL ); - else if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType == ' ' ) - GenWarning( WARN_OPERAND_SUSPECT, sType1, NULL ); + if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType != ' ' && pOperand1->cType != pOperand2->cType ) + GenWarning( WARN_OPERANDS_INCOMPATBLE, sType1, sType2 ); + else if( pOperand1 && pOperand2 && pOperand2->cType != ' ' && pOperand1->cType == ' ' ) + GenWarning( WARN_OPERAND_SUSPECT, sType2, NULL ); + else if( pOperand1 && pOperand2 && pOperand1->cType != ' ' && pOperand2->cType == ' ' ) + GenWarning( WARN_OPERAND_SUSPECT, sType1, NULL ); /* compile time 2nd. operand has to be released */ - if( pOperand2 ) - { - OurFree( pOperand2 ); - } + if( pOperand2 ) + { + OurFree( (void *) pOperand2 ); + } - /* compile time 1st. operand has to be released *but* result will be pushed and of type logical */ - if( pOperand1 ) - pOperand1->cType = 'L'; + /* compile time 1st. operand has to be released *but* result will be pushed and of type logical */ + if( pOperand1 ) + pOperand1->cType = 'L'; - /* Resetting */ - pStackValType = pOperand1; + /* Resetting */ + pStackValType = pOperand1; } else if( byte == HB_P_NOT ) { - char sType[2]; + char sType[2]; - if( pStackValType ) - { - sType[0] = pStackValType->cType; - sType[1] = 0; - } - else - debug_msg( "\n***HB_P_NOT Compile time stack overflow\n", NULL ); + if( pStackValType ) + { + sType[0] = pStackValType->cType; + sType[1] = 0; + } + else + debug_msg( "\n***HB_P_NOT Compile time stack overflow\n", NULL ); - if( pStackValType && pStackValType->cType == ' ' ) - GenWarning( WARN_LOGICAL_SUSPECT, NULL, NULL ); - else if( pStackValType && pStackValType->cType != 'L' ) - GenWarning( WARN_LOGICAL_TYPE, sType, NULL ); + if( pStackValType && pStackValType->cType == ' ' ) + GenWarning( WARN_LOGICAL_SUSPECT, NULL, NULL ); + else if( pStackValType && pStackValType->cType != 'L' ) + GenWarning( WARN_LOGICAL_TYPE, sType, NULL ); - /* compile time 1st. operand has to be released *but* result will be pushed and assumed logical */ - if( pStackValType ) - pStackValType->cType = 'L'; + /* compile time 1st. operand has to be released *but* result will be pushed and assumed logical */ + if( pStackValType ) + pStackValType->cType = 'L'; } } @@ -4270,16 +4297,16 @@ void CodeBlockEnd() GenPCode1( HIBYTE(wPos) ); pFree = pVar; - OurFree( pFree->szName ); + OurFree( (void *) pFree->szName ); pVar = pVar->pNext; - OurFree( pFree ); + OurFree( (void *) pFree ); } GenPCodeN( pCodeblock->pCode, pCodeblock->lPCodePos ); GenPCode1( HB_P_ENDBLOCK ); /* finish the codeblock */ /* this fake-function is no longer needed */ - OurFree( pCodeblock->pCode ) + OurFree( (void *) pCodeblock->pCode ); pVar = pCodeblock->pLocals; while( pVar ) { @@ -4288,11 +4315,11 @@ void CodeBlockEnd() /* free used variables */ pFree = pVar; - OurFree( pFree->szName ); + OurFree( (void *) pFree->szName ); pVar = pVar->pNext; - OurFree( pFree ); + OurFree( (void *) pFree ); } - OurFree( pCodeblock ); + OurFree( (void *) pCodeblock ); if( _iWarnings ) { @@ -4383,7 +4410,7 @@ void StaticDefEnd( WORD wCount ) functions.pLast =_pInitFunc->pOwner; _pInitFunc->pOwner =NULL; _wStatics += wCount; - iVarScope =0; + iVarScope =VS_LOCAL; if( _iWarnings ) { @@ -4391,11 +4418,11 @@ void StaticDefEnd( WORD wCount ) if( pStackValType ) { - pFree = pStackValType; + pFree = pStackValType; debug_msg( "\n***---%i in StaticeDefEnd()\n", _wStatics ); - pStackValType = pStackValType->pPrev; - OurFree( pFree ); + pStackValType = pStackValType->pPrev; + OurFree( (void *) pFree ); } else debug_msg( "\n***StaticDefEnd() Compile time stack overflow\n", NULL ); @@ -4499,7 +4526,7 @@ static void LoopHere( void ) JumpHere( pLoop->wOffset +1 ); pFree = pLoop; pLoop = pLoop->pLoopList; - OurFree( pFree ); + OurFree( (void *) pFree ); } } @@ -4522,13 +4549,13 @@ static void LoopEnd( void ) JumpHere( pExit->wOffset +1 ); pFree = pExit; pExit = pExit->pExitList; - OurFree( pFree ); + OurFree( (void *) pFree ); } pLast->pNext = NULL; if( pLoop == pLoops ) pLoops = NULL; - OurFree( pLoop ); + OurFree( (void *) pLoop ); } @@ -4552,6 +4579,19 @@ void * OurRealloc( void * p, LONG lSize ) return pMem; } +void OurFree( void *ptr ) +{ + if( ptr ) + free( ptr ); + else + { + printf( "ERROR FREE" ); + exit(4); + } +} + + + char * yy_strupr( char * p ) { char * p1; @@ -4597,7 +4637,9 @@ void GenPortObj( char *szFileName, char *szName ) return; } +#ifndef __WATCOMC__ if( 0 && szName ) printf("/* just to keep compiler silent */" ); +#endif if( ! _iQuiet ) printf( "\ngenerating portable object file...\n" );