diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0b375f1afb..530d73a77c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,32 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2004-03-18 12:45 UTC+0100 Ryszard Glab + * include/hberrors.h + * source/pp/ppcore.c + *fixed #define parsing of pseudofunctions in cases where + passed argument has the same name as declared parameter + *fixed #define parsing of pseudofunctions - the following + syntax is not allowed: + #define test(x,x) - duplicated parameters + #define test(x,) - missing parameter + #define test(x - missing parenthes + + * source/common/expropt1.c + * fixed generation of pcode for &(macro)->() syntax + + * source/compiler/harbour.l + * fixed GPF when string with unmatched terminator was used + + + * include/hbexprop.h + * source/compiler/harbour.y + * removed direct access to internals of expression + optimizer structure + + * source/debug/debugger.prg + * fixed checking of path separator + 2004-03-17 8:14 UTC-0800 Luis Krause Mantilla * contrib/rdd_sys/ads1.c * reuploaded to CVS (somehow it didn't get through the last time) diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index d79c43498a..5278ba50a4 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -166,6 +166,9 @@ extern "C" { #define HB_PP_ERR_BAD_RULES_FILE_NAME 16 #define HB_PP_ERR_TOO_MANY_INCLUDES 17 #define HB_PP_ERR_BUFFER_OVERFLOW 18 +#define HB_PP_ERR_LABEL_MISSING_IN_DEFINE 19 +#define HB_PP_ERR_PARE_MISSING_IN_DEFINE 20 +#define HB_PP_ERR_LABEL_DUPL_IN_DEFINE 21 #define HB_PP_WARN_DEFINE_REDEF 1 #define HB_PP_WARN_NO_DIRECTIVES 2 diff --git a/harbour/include/hbexprop.h b/harbour/include/hbexprop.h index a4713ca41d..e23b8ec42c 100644 --- a/harbour/include/hbexprop.h +++ b/harbour/include/hbexprop.h @@ -371,6 +371,9 @@ ULONG hb_compExprListLen( HB_EXPR_PTR ); void hb_compExprClear( HB_EXPR_PTR ); char * hb_compExprDescription( HB_EXPR_PTR ); int hb_compExprType( HB_EXPR_PTR ); +int hb_compExprIsInteger( HB_EXPR_PTR ); +int hb_compExprAsInteger( HB_EXPR_PTR ); +char *hb_compExprAsString( HB_EXPR_PTR ); void hb_compExprFree( HB_EXPR_PTR, HB_MACRO_DECL ); void hb_compExprErrorType( HB_EXPR_PTR, HB_MACRO_DECL ); diff --git a/harbour/source/common/expropt1.c b/harbour/source/common/expropt1.c index df01e144d9..4107a38e01 100644 --- a/harbour/source/common/expropt1.c +++ b/harbour/source/common/expropt1.c @@ -216,6 +216,30 @@ HB_EXPR_PTR hb_compExprNewLong( long lValue ) return pExpr; } +int hb_compExprIsInteger( HB_EXPR_PTR pExpr ) +{ + return ( pExpr->ExprType == HB_ET_NUMERIC && pExpr->value.asNum.NumType == HB_ET_LONG && + pExpr->value.asNum.lVal >= -32768 && pExpr->value.asNum.lVal <= 32767 ); +} + +int hb_compExprAsInteger( HB_EXPR_PTR pExpr ) +{ + if( pExpr->ExprType == HB_ET_NUMERIC && pExpr->value.asNum.NumType == HB_ET_LONG ) + return ( int ) pExpr->value.asNum.lVal; + else + return 0; +} + +char *hb_compExprAsString( HB_EXPR_PTR pExpr ) +{ + switch( pExpr->ExprType ) + { + case HB_ET_VARIABLE: + return pExpr->value.asSymbol ; + + } + return NULL; +} HB_EXPR_PTR hb_compExprNewCodeBlock( char *string, BOOL isMacro, BOOL lateEval ) { @@ -474,7 +498,8 @@ HB_EXPR_PTR hb_compExprNewAliasExpr( HB_EXPR_PTR pAlias, HB_EXPR_PTR pExpList ) if( pAlias->ExprType == HB_ET_MACRO ) { /* Is it a special case &variable->( expressionList ) */ - if( pAlias->value.asMacro.SubType == HB_ET_MACRO_VAR ) + if( pAlias->value.asMacro.SubType == HB_ET_MACRO_VAR || + pAlias->value.asMacro.SubType == HB_ET_MACRO_EXPR ) pAlias->value.asMacro.SubType = HB_ET_MACRO_ALIASED; } diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 7f96edefde..01e1f7ad5e 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -196,7 +196,7 @@ Separator {SpaceTab} hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); hb_comp_iState = LOOKUP; - return LITERAL; + return NIL; } [^'\n]*' { BEGIN 0; @@ -221,7 +221,7 @@ Separator {SpaceTab} hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); hb_comp_iState = LOOKUP; - return LITERAL; + return NIL; } .*\n { @@ -295,7 +295,7 @@ Separator {SpaceTab} hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); hb_comp_iState = LOOKUP; - return LITERAL; + return NIL; } .*\n { diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 4cc5040c20..094b390c4d 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -1546,22 +1546,17 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ if( $8 ) { - if( $8->ExprType == HB_ET_NUMERIC && $8->value.asNum.NumType == HB_ET_LONG && - $8->value.asNum.lVal >= -32768 && $8->value.asNum.lVal <= 32767 ) - { - iStep = ( short ) $8->value.asNum.lVal; - } + if( hb_compExprIsInteger($8) ) + iStep = hb_compExprAsInteger($8); else - { iStep = 0; - } } else { iStep = 1; } - if( iStep && ( iLocal = hb_compLocalGetPos( $2->value.asSymbol ) ) > 0 && iLocal < 256 ) + if( iStep && ( iLocal = hb_compLocalGetPos( hb_compExprAsString($2) ) ) > 0 && iLocal < 256 ) { hb_compGenPCode4( HB_P_LOCALNEARADDINT, ( BYTE ) iLocal, HB_LOBYTE( iStep ), HB_HIBYTE( iStep ), ( BOOL ) 0 ); } diff --git a/harbour/source/debug/debugger.prg b/harbour/source/debug/debugger.prg index 733fc0a309..14867b08da 100644 --- a/harbour/source/debug/debugger.prg +++ b/harbour/source/debug/debugger.prg @@ -509,7 +509,7 @@ return Self METHOD PathForFiles() CLASS TDebugger ::cPathForFiles := ::InputBox( "Search path for source files:", ::cPathForFiles ) - IF RIGHT(::cPathForFiles,1) $ HB_OSPATHDELIMITERS() + IF ! RIGHT(::cPathForFiles,1) $ HB_OSPATHDELIMITERS() ::cPathForFiles:=::cPathForFiles + HB_OSPATHSEPARATOR() ENDIF diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 9a7b8b2785..2ca83df1f3 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -217,7 +217,10 @@ char * hb_pp_szErrors[] = "Can\'t open command definitions file: \'%s\'", "Invalid command definitions file name: \'%s\'", "Too many nested #includes, can\'t open: \'%s\'", - "Input buffer overflow" + "Input buffer overflow", + "Label missing in #define '%s'", + "Comma or right parenthesis missing in #define '%s'", + "Label duplicated in #define '%s(%s)'", }; /* Table with warnings */ @@ -535,7 +538,7 @@ int hb_pp_ParseDirective( char * sLine ) int hb_pp_ParseDefine( char * sLine ) { - char defname[ MAX_NAME ], pars[ MAX_NAME ]; + char defname[ MAX_NAME ], pars[ MAX_NAME+1 ]; int i, npars = -1; DEFINES * lastdef; @@ -544,27 +547,103 @@ int hb_pp_ParseDefine( char * sLine ) HB_SKIPTABSPACES( sLine ); if( ISNAME( *sLine ) ) { + char *cParams = NULL; + NextName( &sLine, defname ); if( *sLine == '(' ) /* If pseudofunction was found */ { - sLine++; i = 0; + int iParLen = 0; + int iLen; + + sLine++; + HB_SKIPTABSPACES( sLine ); + + i = 0; npars = 0; - while( *sLine != '\0' && *sLine != ')') - { - if( *sLine == ',' ) npars++; - if( *sLine != ' ' && *sLine != '\t' ) *(pars+i++) = *sLine; - sLine++; - } - if( i > 0 ) npars++; - *(pars+i) = '\0'; + while( *sLine && *sLine != ')' ) + { + if( ISNAME(*sLine) ) + { + NextName( &sLine, pars ); + iLen = strlen( pars ); + if( cParams == NULL ) + { + /* 'xy0' -> '~xy0' */ + cParams = hb_xgrab( iLen+2 ); + } + else + { + /* '~xy0' -> '~xy,~ab0' */ + char *cPos; + cPos = strstr( cParams, pars ); + if( cPos && (cPos[iLen]==',' || cPos[iLen]=='\0') ) + { + cPos--; + if( *cPos == '\001' ) + hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_LABEL_DUPL_IN_DEFINE, defname, pars ); + } + cParams = hb_xrealloc( cParams, iParLen+iLen+3 ); + cParams[iParLen++] = ','; + cParams[iParLen] = '\0'; + } + cParams[iParLen] = '\001'; + strcpy( cParams+iParLen+1, pars ); + iParLen += iLen+1; + npars++; + HB_SKIPTABSPACES( sLine ); + } + else + hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_LABEL_MISSING_IN_DEFINE, defname, NULL ); + + if( *sLine == ',' ) + { + sLine++; + HB_SKIPTABSPACES( sLine ); + if( *sLine == ')' ) + hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_LABEL_MISSING_IN_DEFINE, defname, NULL ); + } + } sLine++; } + HB_SKIPTABSPACES(sLine); + if( *sLine == '\0' ) + hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_PARE_MISSING_IN_DEFINE, defname, NULL ); + if( cParams ) + { + char *tmp = cParams; + char *cPos; + int iPar, iLen, iPos, iOldPos; + + iLen = strlen( sLine ); + for(i=0; inpars = npars; - lastdef->pars = ( npars <= 0 ) ? NULL : hb_strdup( pars ); + lastdef->pars = cParams; } else hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_DEFINE_ABSENT, NULL, NULL );