From 2bdcf6417e01210ca600bd73e0e12ffee9346c4a Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Sat, 24 Jun 2000 19:06:52 +0000 Subject: [PATCH] 2000-06-24 11:42 UTC-0800 Ron Pinkas * include/hbclass.ch - Uncommented the VO #xtranslate as they do work correctly. * source/pp/pplib.c - Removed int hb_comp_iIncLine * include/hbcomp.h - Removed int hb_comp_iIncLine + Added int hb_comp_iCompiled + Added char* hb_comp_szFile + Added BOOL hb_comp_bError * source/compiler/harbour.c ! Fixed Compile Time Line Numbers ! Fixed Run Time Line Numbers * source/compiler/harbour.l ! Rewrote rules for STRING1 STRING2 STRING3 INDEX, were severly broken with regard to unterminated support. /* When working on errors, I founf major problems, with unterminated Array Index and Unterminated Strings I'm surprised no one reported. This mass was a nightmere to fix. it seems to be working great now. */ * source/compiler/harbour.y ! Many fixes to support correct line numbers. * source/compiler/hbgenerr.c ! Fixed Error System to never report more than 1 error per source line. * source/pp/ppcomp.c - Removed code for hb_comp_iIncLine * source/pp/ppcore.c * Minor formating. --- harbour/ChangeLog | 50 +++++++-- harbour/include/hbclass.ch | 6 +- harbour/include/hbcomp.h | 3 + harbour/source/compiler/harbour.c | 62 ++++------- harbour/source/compiler/harbour.l | 164 +++++++++++++++++++---------- harbour/source/compiler/harbour.y | 65 +++++++----- harbour/source/compiler/hbgenerr.c | 20 ++-- harbour/source/pp/ppcomp.c | 40 ++++++- harbour/source/pp/ppcore.c | 57 +++++----- harbour/source/pp/pplib.c | 6 +- 10 files changed, 290 insertions(+), 183 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6afe5bd08b..f17d2d5a5f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,37 @@ +2000-06-24 11:42 UTC-0800 Ron Pinkas + * include/hbclass.ch + - Uncommented the VO #xtranslate as they do work correctly. + + * source/pp/pplib.c + - Removed int hb_comp_iIncLine + + * include/hbcomp.h + - Removed int hb_comp_iIncLine + + Added int hb_comp_iCompiled + + Added char* hb_comp_szFile + + Added BOOL hb_comp_bError + + * source/compiler/harbour.c + ! Fixed Compile Time Line Numbers + ! Fixed Run Time Line Numbers + + * source/compiler/harbour.l + ! Rewrote rules for STRING1 STRING2 STRING3 INDEX, were severly broken with regard to unterminated support. + /* When working on errors, I founf major problems, with unterminated Array Index and Unterminated Strings + I'm surprised no one reported. This mass was a nightmere to fix. it seems to be working great now. */ + + * source/compiler/harbour.y + ! Many fixes to support correct line numbers. + + * source/compiler/hbgenerr.c + ! Fixed Error System to never report more than 1 error per source line. + + * source/pp/ppcomp.c + - Removed code for hb_comp_iIncLine + + * source/pp/ppcore.c + * Minor formating. + 2000-06-24 20:10 UTC+0100 Ryszard Glab *include/hbapi.h @@ -11,27 +45,27 @@ user defined background tasks *HB_IAMIDLE() - signals that user code is in idle state *HB_ADDIDLE(), HB_DELIDLE() - handle background tasks - + *tests/Makefile *tests/onidle.prg * test program that demonstrate background tasks - + *source/vm/garbage.c * new module with the garbage collector code - + *source/rtl/Makefile * added a new file idle.c - + *source/rtl/errorapi.c *source/rtl/inkey.c * fixed to correct support idle states and garbage collector - + NOTICE: static HB_ITEM structures cannot be initialized with hb_itemClear() call because the structure can occupy a memory with random bits set - + *source/vm/Makefile * added a new file garbage.c - + *source/vm/arrays.c *source/vm/codebloc.c *source/vm/memvars.c @@ -41,7 +75,7 @@ NOTICE: static HB_ITEM structures cannot be initialized with hb_itemClear() *makefile.bc *makefile.vc *updated to support idle states and the garbage collector - + 2000-06-23 22:45 GMT -3 Luiz Rafael Culik *contrib/samples/gauge.c *Fixed a small bug on Gaugenew() diff --git a/harbour/include/hbclass.ch b/harbour/include/hbclass.ch index 13ded0eff9..7e8acb9ec2 100644 --- a/harbour/include/hbclass.ch +++ b/harbour/include/hbclass.ch @@ -95,9 +95,9 @@ #endif /* HB_SHORTNAMES */ /* VO compatibility */ -/*#xtranslate ( { [] } => ( ():New(

) */ -/*#xtranslate := { [] } => := ():New(

) */ -/*#xtranslate = { [] } => = ():New(

) */ +#xtranslate ( { [] } => ( ():New(

) +#xtranslate := { [] } => := ():New(

) +#xtranslate = { [] } => = ():New(

) /*#xtranslate , { [] } => , ():New(

) */ diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 84641d8e44..ee325c0239 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -413,6 +413,8 @@ extern void hb_compGenObj32( PHB_FNAME ); /* generates OBJ 32 bits */ /* variable used by compiler */ extern int hb_comp_iLine; +extern int hb_comp_iCompiled; +extern char * hb_comp_szFile; extern FUNCTIONS hb_comp_functions; extern FUNCTIONS hb_comp_funcalls; extern SYMBOLS hb_comp_symbols; @@ -473,6 +475,7 @@ extern char * hb_comp_szWarnings[]; extern char * hb_pp_STD_CH; extern BOOL hb_comp_bAutoOpen; +extern BOOL hb_comp_bError; /* /GC command line setting types */ #define HB_COMPGENC_COMPACT 0 diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 1ab97049e1..6b7c5833e6 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -90,6 +90,8 @@ char * hb_comp_szFromClass; PCOMDECLARED hb_comp_pLastMethod; int hb_comp_iLine; /* currently processed line number (globaly) */ +int hb_comp_iCompiled; /* Last compiled line */ +char * hb_comp_szFile; /* File Name of last compiled line */ PFUNCTION hb_comp_pInitFunc; PHB_FNAME hb_comp_pFileName = NULL; @@ -126,6 +128,7 @@ BOOL hb_comp_EOL; char * hb_comp_szDeclaredFun = NULL; BOOL hb_comp_bAutoOpen = TRUE; +BOOL hb_comp_bError = FALSE; /* EXTERNAL statement can be placed into any place in a function - this flag is * used to suppress error report generation @@ -1933,54 +1936,28 @@ void hb_compLinePush( void ) /* generates the pcode with the currently compiled { if( hb_comp_bLineNumbers && ! hb_comp_bDontGenLineNum ) { - int iLine = hb_comp_iLine; + /* + int iLine = hb_comp_files.pLast->iLine - 1; - if( hb_comp_files.iFiles == 1 ) - { - iLine = hb_comp_files.pLast->iLine ; - } - else - { - PFILE tmpFile = hb_comp_files.pLast; - while( tmpFile->pPrev ) - { - tmpFile = tmpFile->pPrev; - } - if( tmpFile ) - { - iLine = tmpFile->iLine; - } - } - - if( yytext[0] == '\n' ) - { - if( hb_pp_nEmptyStrings ) - { - iLine -= ( hb_pp_nEmptyStrings + 2 ); - } - else - { - iLine--; - } - } - else - { - iLine--; - } - - #if 0 - printf( "\nLine: %i Empty: %i >%s<\n", iLine, hb_pp_nEmptyStrings, yytext ); - #endif + if( hb_pp_nEmptyStrings ) + iLine -= hb_pp_nEmptyStrings - 2; + */ if( ( ( hb_comp_functions.pLast->lPCodePos - hb_comp_ulLastLinePos ) > 3 ) || hb_comp_bDebugInfo ) { + /* + printf( "File: %s Line: %i Compiled: %i iLine: %i Empty: %i\n", hb_comp_szFile, hb_comp_files.pLast->iLine, hb_comp_iCompiled, iLine, hb_pp_nEmptyStrings ); + */ hb_comp_ulLastLinePos = hb_comp_functions.pLast->lPCodePos; - hb_compGenPCode3( HB_P_LINE, HB_LOBYTE( iLine ), HB_HIBYTE( iLine ), ( BOOL ) 0 ); + hb_compGenPCode3( HB_P_LINE, HB_LOBYTE( hb_comp_iCompiled ), HB_HIBYTE( hb_comp_iCompiled ), ( BOOL ) 0 ); } 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 ); + /* + printf( "*File: %s Line: %i Compiled: %i iLine: %i Empty: %i\n", hb_comp_szFile, hb_comp_files.pLast->iLine, hb_comp_iCompiled, iLine, hb_pp_nEmptyStrings ); + */ + hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +1 ] = HB_LOBYTE( hb_comp_iCompiled ); + hb_comp_functions.pLast->pCode[ hb_comp_ulLastLinePos +2 ] = HB_HIBYTE( hb_comp_iCompiled ); } } @@ -2024,7 +2001,6 @@ void hb_compLinePushIfInside( void ) /* generates the pcode with the currently c */ if( ! hb_comp_bExternal ) { - hb_comp_bExternal = FALSE; if( ! hb_comp_bStartProc && hb_comp_functions.iCount <= 1 ) { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_OUTSIDE, NULL, NULL ); @@ -3335,6 +3311,7 @@ static void hb_compInitVars( void ) hb_comp_bAnyWarning = FALSE; hb_comp_iLine = 1; + hb_comp_iCompiled = 1; hb_comp_iFunctionCnt = 0; hb_comp_iErrorCount = 0; hb_comp_cVarType = ' '; @@ -3444,6 +3421,7 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] ) hb_comp_files.pLast = NULL ; hb_comp_files.iFiles = 0 ; hb_comp_iLine = 1 ; + hb_comp_iLine = 1 ; } else #endif @@ -3479,6 +3457,8 @@ int hb_compCompile( char * szPrg, int argc, char * argv[] ) } #endif + hb_comp_szFile = szFileName; + if( ! hb_comp_bQuiet ) { if( hb_comp_bPPO ) diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 64cf3d7d2c..3957d3a81d 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -157,76 +157,127 @@ Separator {SpaceTab} ^[ \t]*"do"[ \t]*"while"[ \t]*"[" { BEGIN STRING3; return WHILE; } \[ { BEGIN STRING3; } -[^'^\n]* { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } -[^\"^\n]* { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } -[^\]]*\n { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } - -[^']*' { if( i_INDEX_STATE ) - BEGIN INDEX; - else +[^'\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; BEGIN 0; + return '\n'; + } +[^\"\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return '\n'; + } +[^\]\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return '\n'; + } - yyleng--; - yytext[yyleng] = 0; - yylval.string = hb_strdup( yytext ); - /*printf( "\nLITERAL = %s\n", yylval.string );*/ - return LITERAL; +[^"'"\n]*' { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yyleng--; + yytext[yyleng] = 0; + yylval.string = hb_strdup( yytext ); + return LITERAL; + } + +[^\"\n]*\" { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yyleng--; + yytext[yyleng] = 0; + yylval.string = hb_strdup( yytext ); + return LITERAL; + } + +[^\]\n]*\] { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yyleng--; + yytext[yyleng] = 0; + yylval.string = hb_strdup( yytext ); + return LITERAL; + } + +\[[^\n]*$ { iIndexSets++; + /* + printf( "%i >%s<\n", iIndexSets, yytext ); + */ + { + char * tmpStr = yytext; + + while( *tmpStr != '\0' ) + { + if( *tmpStr++ == ']' ) + { + yyless(1); + return '['; + } + } + + /* No Closing Bracket - Error! */ + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_UNTERM_ARRAY_INDEX, NULL, NULL ); + i_INDEX_STATE = 0; + iIndexSets = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return '\n'; + } } -[^\"]*\" { if( i_INDEX_STATE ) - BEGIN INDEX; - else - BEGIN 0; +\][^\n]*\n { if( iIndexSets ) + iIndexSets-- ; - yyleng--; - yytext[yyleng] = 0; - yylval.string = hb_strdup( yytext ); - /*printf( "\nLITERAL = %s\n", yylval.string );*/ - return LITERAL; - } + /* + printf( ">%s<\n", yytext ); + */ -[^\]]*\] { if( i_INDEX_STATE ) - BEGIN INDEX; - else - BEGIN 0; + if( iIndexSets == 0 ) + { + char * tmpStr = yytext; - yyleng--; - yytext[yyleng] = 0; - yylval.string = hb_strdup( yytext ); - /*printf( "\nLITERAL = %s\n", yylval.string );*/ - return LITERAL; - } + /* Default to no Opening Bracket. */ + i_INDEX_STATE = 0; + BEGIN 0; -\n { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_UNTERM_ARRAY_INDEX, NULL, NULL ); } + /* No longer in this state. */ + while( *tmpStr != '\0' ) + { + if( *tmpStr++ == '[' ) + { -\[ { iIndexSets++; return yytext[ 0 ]; } + i_INDEX_STATE = 1; + BEGIN INDEX; + break; + } + } + } -\] { - iIndexSets-- ; - if( iIndexSets == 0 ) - { - /*printf( "\nIndex End\n" );*/ - - /* No longer in this state. */ - i_INDEX_STATE = 0; - BEGIN 0; - } - hb_comp_iState =OPERATOR; - return yytext[ 0 ]; - } + yyless(1); + hb_comp_iState = OPERATOR; + return ']'; + } {SpaceTab} ; -\n.* { +\n. { /* "." after "\n" is important so we skip empty lines, until begining of non empty next line - don't remove!!! */ hb_comp_iState = LOOKUP; + yyless( 1 ); - /*++hb_comp_iLine;*/ -#if 0 - if( ! hb_comp_bQuiet ) - { - printf( "\r%i", hb_comp_iLine ); - } -#endif + if( ! hb_comp_bQuiet && ( hb_comp_iLine % 100 ) == 0 ) { printf( "\r%i", hb_comp_iLine ); @@ -1668,7 +1719,8 @@ Separator {SpaceTab} i_INDEX_STATE = 1; } - iIndexSets--; + if( iIndexSets ) + iIndexSets--; unput( '[' ); hb_comp_iState = OPERATOR; diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 4179a9e292..049a9701b9 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -37,7 +37,7 @@ /* TODO list * 1) Change the pcode generated by ::cVar from Self:cVar to QSELF():cVar * The major problem to solve is how to support QSELF() inside a codeblock. - * 2) Support this syntax: nPtr := @Hello() + * 2) Support this syntax: nPtr := @Hello() */ #include @@ -241,24 +241,25 @@ Main : { hb_compLinePush(); } Source { } ; Source : Crlf { hb_comp_EOL = FALSE; } - | VarDefs { hb_comp_EOL = FALSE; } - | FieldsDef { hb_comp_EOL = FALSE; } - | MemvarDef { hb_comp_EOL = FALSE; } - | Declaration { hb_comp_EOL = FALSE; } - | Function { hb_comp_EOL = FALSE; } - | Statement { hb_comp_EOL = FALSE; } - | Line { hb_comp_EOL = FALSE; } + | VarDefs { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | FieldsDef { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | MemvarDef { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Declaration { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Function { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Statement { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Line { hb_comp_EOL = FALSE; hb_comp_iCompiled = 2; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } | ProcReq { hb_comp_EOL = FALSE; } + | error Crlf { hb_comp_EOL = FALSE; yyclearin; } | Source Crlf { hb_comp_EOL = FALSE; } - | Source Function { hb_comp_EOL = FALSE; } - | Source Statement { hb_comp_EOL = FALSE; } - | Source VarDefs { hb_comp_EOL = FALSE; } - | Source FieldsDef { hb_comp_EOL = FALSE; } - | Source MemvarDef { hb_comp_EOL = FALSE; } - | Source Declaration { hb_comp_EOL = FALSE; } - | Source Line { hb_comp_EOL = FALSE; } + | Source VarDefs { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source FieldsDef { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source MemvarDef { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source Declaration { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source Function { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source Statement { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } + | Source Line { hb_comp_EOL = FALSE; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; hb_comp_szFile = hb_strdup( hb_comp_files.pLast->szFileName ); } | Source ProcReq { hb_comp_EOL = FALSE; } - | Source error Crlf { hb_comp_EOL = FALSE; yyclearin; } + | Source error Crlf { hb_comp_EOL = FALSE; yyclearin; } ; Line : LINE NUM_INTEGER LITERAL Crlf @@ -402,10 +403,10 @@ Statement : ExecFlow CrlfStmnt { } ; CrlfStmnt : { hb_compLinePushIfInside(); } Crlf -; + ; LineStat : Crlf { $$ = 0; hb_comp_bDontGenLineNum = TRUE; } - | Statement { $$ = 1; } + | Statement { $$ = 1; hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } ; Statements : LineStat { $$ = $1; hb_compLinePush(); } @@ -1274,19 +1275,19 @@ EmptyStats : /* empty */ { hb_comp_bDontGenLineNum = TRUE; hb_comp_EOL | EmptyStatements { hb_comp_EOL = FALSE; $$ = $1; } ; -IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } +IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF Variable { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + | IF Variable { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF PareExpList1 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + | IF PareExpList1 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } - | IF PareExpList2 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + | IF PareExpList2 { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } @@ -1295,14 +1296,14 @@ IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; hb_compLinePush(); } Cr { $$ = hb_compGenJump( 0 ); hb_compGenJumpHere( $5 ); } ; -IfElse : ELSE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); } +IfElse : ELSE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats ; -IfElseIf : ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } +IfElseIf : ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compElseIfGen( NULL, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $4 ); } - | IfElseIf ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); } + | IfElseIf ELSEIF Expression Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { $$ = hb_compElseIfGen( $1, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $5 ); } ; @@ -1337,7 +1338,7 @@ EndCase : ENDCASE } ; -DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; } Crlf { hb_compLinePush(); } +DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; } Crlf { hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } ; DoCaseBegin : DoCaseStart { } @@ -1354,6 +1355,7 @@ Cases : CASE Expression Crlf hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { @@ -1361,6 +1363,7 @@ Cases : CASE Expression Crlf $$ = hb_compElseIfGen( 0, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $4 ); hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } | Cases CASE Expression Crlf @@ -1368,6 +1371,7 @@ Cases : CASE Expression Crlf hb_compExprDelete( hb_compExprGenPush( $3 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { @@ -1375,10 +1379,11 @@ Cases : CASE Expression Crlf $$ = hb_compElseIfGen( $1, hb_compGenJump( 0 ) ); hb_compGenJumpHere( $5 ); hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } ; -Otherwise : OTHERWISE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); } +Otherwise : OTHERWISE Crlf { hb_comp_functions.pLast->bFlags &= ~ FUN_BREAK_CODE; hb_compLinePush(); hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats | Otherwise OTHERWISE { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_MAYHEM_IN_CASE, NULL, NULL ); } Crlf EmptyStats @@ -1389,17 +1394,20 @@ DoWhile : WhileBegin Expression Crlf hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EmptyStats { hb_compLoopHere(); hb_compGenJump( $1 - hb_comp_functions.pLast->lPCodePos ); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } EndWhile { hb_compGenJumpHere( $4 ); --hb_comp_wWhileCounter; hb_compLoopEnd(); hb_comp_functions.pLast->bFlags &= ~ FUN_WITH_RETURN; + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } ; @@ -1433,6 +1441,7 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ hb_compGenPCode1( HB_P_LESSEQUAL ); $$ = hb_compGenJumpFalse( 0 ); /* 11 */ hb_compLinePush(); + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; } ForStatements /* 12 */ { @@ -1556,7 +1565,7 @@ DoArgument : IdentName { $$ = hb_compExprNewVarRef( $1 ); } | PareExpList { $$ = $1; } ; -Crlf : '\n' { ++hb_comp_iLine; hb_comp_EOL = TRUE; } +Crlf : '\n' { ++hb_comp_iLine; hb_comp_EOL = TRUE; hb_comp_bError = FALSE; } | ';' { hb_comp_bDontGenLineNum = TRUE; } ; diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index 279560c7a5..6fefa751ba 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -124,19 +124,18 @@ char * hb_comp_szWarnings[] = void hb_compGenError( char * szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { - int iOffset = 0; + if( cPrefix != 'F' && hb_comp_bError ) + return; - if( yytext[0] == '\n' ) - iOffset = hb_pp_nEmptyStrings + 1; - - if( hb_comp_files.pLast != NULL && hb_comp_files.pLast->szFileName != NULL ) - printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_files.pLast->iLine - 1 - iOffset ); + if( hb_comp_files.pLast && hb_comp_files.pLast->szFileName ) + printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_files.pLast->iLine - 1 ); printf( "Error %c%04i ", cPrefix, iError ); printf( szErrors[ iError - 1 ], szError1, szError2 ); printf( "\n" ); hb_comp_iErrorCount++; + hb_comp_bError = TRUE; /* fatal error - exit immediately */ if( cPrefix == 'F' ) @@ -147,15 +146,10 @@ void hb_compGenWarning( char * szWarnings[], char cPrefix, int iWarning, char * { char * szText = szWarnings[ iWarning - 1 ]; - int iOffset = 0; - - if( yytext[0] == '\n' ) - iOffset = hb_pp_nEmptyStrings + 1; - if( ( szText[ 0 ] - '0' ) <= hb_comp_iWarnings ) { - if( hb_comp_files.pLast != NULL && hb_comp_files.pLast->szFileName != NULL ) - printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_files.pLast->iLine - 1 - iOffset ); + if( hb_comp_files.pLast && hb_comp_files.pLast->szFileName ) + printf( "\r%s(%i) ", hb_comp_files.pLast->szFileName, hb_comp_files.pLast->iLine - 1 ); printf( "Warning %c%04i ", cPrefix, iWarning ); printf( szText + 1, szWarning1, szWarning2 ); diff --git a/harbour/source/pp/ppcomp.c b/harbour/source/pp/ppcomp.c index 834120ecf1..9cc1e45fff 100644 --- a/harbour/source/pp/ppcomp.c +++ b/harbour/source/pp/ppcomp.c @@ -121,15 +121,35 @@ int hb_pp_Internal( FILE * handl_o, char * sOut ) pFile = ( PFILE ) ( ( PFILE ) hb_comp_files.pLast )->pPrev; if( lLine ) + { sprintf( s_szLine, "#line %d \"%s\"\n", pFile->iLine + hb_pp_nEmptyStrings, pFile->szFileName ); + } else + { *s_szLine = '\0'; + } lLine = 0; + /* Ron Pinkas added 2000-06-23 */ + /* Produce empty lines, only if previous file is the main prg. */ + if( hb_comp_files.iFiles == 2 ) + { + tmpPtr = s_szLine + strlen(s_szLine); + + for( i=0; i < hb_pp_nEmptyStrings; i++ ) + *tmpPtr++ = '\n'; + + *tmpPtr = '\0'; + } + /* Ron Pinkas end 2000-06-23 */ + + sprintf( s_szLine + strlen(s_szLine), "#line 1 \"%s\"", hb_comp_files.pLast->szFileName ); + + /* Ron Pinkas added 2000-06-23 */ pFile->iLine += ( 1 + hb_pp_nEmptyStrings ); - sprintf( s_szLine+strlen(s_szLine), "#line 1 \"%s\"", hb_comp_files.pLast->szFileName ); hb_pp_nEmptyStrings = 0; + /* Ron Pinkas end 2000-06-23 */ } else { @@ -178,17 +198,31 @@ int hb_pp_Internal( FILE * handl_o, char * sOut ) if( hb_comp_files.iFiles == 1 ) return 0; /* we have reached the main EOF */ else - { /* we close the currently include file and continue */ + { + /* Ron Pinkas added 2000-06-23 */ + /* Resumming Main PRG */ + if( hb_comp_files.iFiles == 2 ) + { + } + /* Save line number for the last #include line + hb_comp_iIncLine = hb_comp_files.pLast->iLine - 1; + */ + /* Ron Pinkas end 2000-06-23 */ + + /* we close the currently include file and continue */ fclose( hb_comp_files.pLast->handle ); hb_xfree( hb_comp_files.pLast->pBuffer ); hb_xfree( hb_comp_files.pLast->szFileName ); pFile = ( PFILE ) ( ( PFILE ) hb_comp_files.pLast )->pPrev; hb_xfree( hb_comp_files.pLast ); hb_comp_files.pLast = pFile; + + /* Ron Pinkas commented hb_comp_iLine = hb_comp_files.pLast->iLine; + */ + hb_comp_files.iFiles--; lLine = 1; - hb_pp_nEmptyStrings = 0; } /* Ron Pinkas added 2000-06-22 */ diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index c23bfc4ae7..98e56fb335 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -1241,11 +1241,11 @@ static int CommandStuff( char * ptrmp, char * inputLine, char * ptro, int * lenr } } */ - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 14:45 UTC-0800 */ } - /* Ron Pinkas added 2000-06-02 14:45 UTC-0800 */ - /* - else if( ipos && *ptrmp == '[' ) + /* Ron Pinkas added 2000-06-02 14:45 UTC-0800 */ + /* + else if( ipos && *ptrmp == '[' ) { ptr = strtopti+ipos; while ( ptr > strtopti && *(--ptr) != ']' ) ; @@ -1268,7 +1268,7 @@ static int CommandStuff( char * ptrmp, char * inputLine, char * ptro, int * lenr } } */ - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 14:45 UTC-0800 */ } switch( *ptrmp ) { case '[': @@ -1611,13 +1611,13 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO int StBr1 = 0, StBr2 = 0, StBr3 = 0; BOOL rez = FALSE; - /* Ron Pinkas Begin 2000-06-02 */ + /* Ron Pinkas added 2000-06-02 */ BOOL bMacro = FALSE; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 */ - /* Ron Pinkas Begin 2000-06-17 */ + /* Ron Pinkas added 2000-06-17 */ char cLastChar = '\0'; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-17 */ HB_TRACE(HB_TR_DEBUG, ("getExpReal(%s, %p, %d, %d, %d)", expreal, ptri, prlist, maxrez, bStrict)); @@ -1678,7 +1678,7 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO { State = STATE_QUOTE3; } - /* Ron Pinkas added 2000-06-17 */ + /* Ron Pinkas end 2000-06-17 */ /* Ron Pinkas commented 2000-06-17 StBr2++; @@ -1737,7 +1737,7 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO } else if( IsInStr( **ptri, sZnaki ) ) { - /* Ron Pinkas Begin 2000-06-02 */ + /* Ron Pinkas added 2000-06-02 */ if( **ptri=='.' && bMacro ) { /* Macro terminator '.' */ @@ -1747,7 +1747,7 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO bMacro = FALSE; } else - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 */ State = STATE_EXPRES; } else if( **ptri == '(' ) @@ -1779,18 +1779,18 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO State = STATE_BRACKET; StBr3 = 1; } - /* Ron Pinkas Begin 2000-06-02 */ + /* Ron Pinkas added 2000-06-02 */ else if( **ptri == '&' ) { bMacro = TRUE; } - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 */ else if( **ptri == ' ' ) { State = STATE_ID_END; - /* Ron Pinkas Begin 2000-06-02 */ + /* Ron Pinkas added 2000-06-02 */ bMacro = FALSE; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-02 */ } break; @@ -1842,7 +1842,7 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO { rez = TRUE; } - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-14 */ else if( **ptri == '(' ) { StBr1++; @@ -1908,10 +1908,6 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO } *expreal = '\0'; - - #if 0 - printf( "\nLen=%i >%s<\n", lens, expreal-lens ); - #endif } /* Ron Pinkas added 2000-06-21 */ @@ -1926,7 +1922,12 @@ static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BO lens = 0; } } - /* Ron Pinkas added 2000-06-21 */ + /* Ron Pinkas end 2000-06-21 */ + + #if 0 + if( lens ) + printf( "\nLen=%i >%s<\n", lens, expreal-lens ); + #endif return lens; } @@ -2430,9 +2431,9 @@ int hb_pp_RdStr( FILE * handl_i, char * buffer, int maxlen, BOOL lDropSpaces, ch int State = 0; char cha, cLast = '\0', symbLast = '\0'; - /* Ron Pinkas Begin 2000-06-04 */ + /* Ron Pinkas added 2000-06-04 */ BOOL bNewLine = TRUE; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-04 */ HB_TRACE(HB_TR_DEBUG, ("hb_pp_RdStr(%p, %s, %d, %d, %s, %p, %p)", handl_i, buffer, maxlen, lDropSpaces, sBuffer, lenBuffer, iBuffer)); @@ -2499,7 +2500,7 @@ int hb_pp_RdStr( FILE * handl_i, char * buffer, int maxlen, BOOL lDropSpaces, ch } else if( !State ) maxlen = readed = 0; break; - /* Ron Pinkas Begin 2000-06-01 */ + /* Ron Pinkas added 2000-06-01 */ case ';': bNewLine = TRUE; break; @@ -2511,12 +2512,12 @@ int hb_pp_RdStr( FILE * handl_i, char * buffer, int maxlen, BOOL lDropSpaces, ch cha = ' '; } break; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-01 */ } if( cha != ' ' && cha != ';' ) s_prevchar = cha; - /* Ron Pinkas Begin 2000-06-04 */ + /* Ron Pinkas added 2000-06-04 */ if( cha != ' ' && cha != '\t' && cha != ';' ) bNewLine = FALSE; - /* Ron Pinkas End */ + /* Ron Pinkas end 2000-06-04 */ } if( cha != ' ' && cha != '\t' ) State = 1; if( lDropSpaces && State ) lDropSpaces = 0; diff --git a/harbour/source/pp/pplib.c b/harbour/source/pp/pplib.c index f19ce68989..ceb8074342 100644 --- a/harbour/source/pp/pplib.c +++ b/harbour/source/pp/pplib.c @@ -89,14 +89,14 @@ HB_FUNC( __PREPROCESS ) { char * ptr = pText; int slen; - + /* hb_pp_Init(); */ - + slen = HB_MIN( hb_parclen( 1 ), HB_PP_STR_SIZE - 1 ); memcpy( pText, hb_parc( 1 ), slen ); pText[ slen ] = 0; /* Preprocessor expects null-terminated string */ memset( pOut, 0, HB_PP_STR_SIZE ); - + HB_SKIPTABSPACES( ptr ); if( hb_pp_ParseExpression( ptr, pOut ) > 0 )