diff --git a/ChangeLog.txt b/ChangeLog.txt index 3c1c585bdf..efd3d4a601 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,20 @@ Entries may not always be in chronological/commit order. See license at the end of file. */ +2023-11-13 23:58 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbct/ctwin.c + ! typo in comment + + * include/hbexprb.c + * include/hbexprop.h + * src/common/expropt2.c + * src/harbour.def + * moved code for reducing NOT expression to new separate function + hb_compExprReduceNot() + ; added comments to mark places for possible compiletime warnings when + incompatible types are used inside in logical expressions + (.AND. / .OR. / .NOT.) + 2023-11-12 16:40 UTC+0100 Phil Krylov (phil a t krylov.eu) * .github/workflows/linux-ci.yml * .github/workflows/macos-ci.yml diff --git a/contrib/hbct/ctwin.c b/contrib/hbct/ctwin.c index 570b02013e..269d8bf4cc 100644 --- a/contrib/hbct/ctwin.c +++ b/contrib/hbct/ctwin.c @@ -1947,7 +1947,7 @@ static HB_BOOL hb_ctw_gt_PutChar( PHB_GT pGT, int iRow, int iCol, iWindow = pCTW->pWindowMap[ lIndex ]; #if 0 /* When window with shadow is closed CT3 restores attributes - * which existed before shadow was displayed. In some application + * which existed before shadow was displayed. In an application * which switches to window 0 for pass-throw output it causes that * wrong attributes appears after this operation. In Harbour it's * fixed so such problem do not exist. Anyhow some code may switch diff --git a/include/hbexprb.c b/include/hbexprb.c index efda8c8279..413ad63f3b 100644 --- a/include/hbexprb.c +++ b/include/hbexprb.c @@ -3407,30 +3407,10 @@ static HB_EXPR_FUNC( hb_compExprUseNot ) switch( iMessage ) { case HB_EA_REDUCE: - { - PHB_EXPR pExpr; - pSelf->value.asOperator.pLeft = HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_REDUCE ); - pExpr = pSelf->value.asOperator.pLeft; - - if( pExpr->ExprType == HB_ET_LOGICAL ) - { - pExpr->value.asLogical = ! pExpr->value.asLogical; - HB_COMP_EXPR_CLEAR( pSelf ); - pSelf = pExpr; - } - else if( pExpr->ExprType == HB_EO_NOT && HB_SUPPORT_EXTOPT ) - { - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - pExpr->ExprType = HB_ET_NONE; /* do not delete operator parameter - we are still using it */ - pExpr = pExpr->value.asOperator.pLeft; - HB_COMP_EXPR_FREE( pSelf ); - pSelf = pExpr; - } + pSelf = hb_compExprReduceNot( pSelf, HB_COMP_PARAM ); break; - } + case HB_EA_ARRAY_AT: HB_COMP_ERROR_TYPE( pSelf ); break; diff --git a/include/hbexprop.h b/include/hbexprop.h index 5de924e660..727736931a 100644 --- a/include/hbexprop.h +++ b/include/hbexprop.h @@ -179,6 +179,7 @@ extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceLT( PHB_EXPR pSelf, HB_COMP_DECL extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceEQ( PHB_EXPR pSelf, HB_COMP_DECL ); extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceAnd( PHB_EXPR pSelf, HB_COMP_DECL ); extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceOr( PHB_EXPR pSelf, HB_COMP_DECL ); +extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceNot( PHB_EXPR pSelf, HB_COMP_DECL ); extern HB_EXPORT_INT PHB_EXPR hb_compExprReduceIIF( PHB_EXPR, HB_COMP_DECL ); extern HB_EXPORT_INT HB_BOOL hb_compExprReduceAT( PHB_EXPR, HB_COMP_DECL ); diff --git a/src/common/expropt2.c b/src/common/expropt2.c index 240f0e9905..9865594722 100644 --- a/src/common/expropt2.c +++ b/src/common/expropt2.c @@ -967,6 +967,11 @@ PHB_EXPR hb_compExprReduceNegate( PHB_EXPR pSelf, HB_COMP_DECL ) HB_COMP_EXPR_FREE( pSelf ); pSelf = pExpr; } + /* TODO: add checking of incompatible types + else + { + } + */ return pSelf; } @@ -1798,6 +1803,11 @@ PHB_EXPR hb_compExprReduceAnd( PHB_EXPR pSelf, HB_COMP_DECL ) pSelf->value.asLogical = HB_FALSE; } } + /* TODO: add checking of incompatible types + else + { + } + */ return pSelf; } @@ -1866,6 +1876,42 @@ PHB_EXPR hb_compExprReduceOr( PHB_EXPR pSelf, HB_COMP_DECL ) pSelf = pLeft; } } + /* TODO: add checking of incompatible types + else + { + } + */ + return pSelf; +} + +PHB_EXPR hb_compExprReduceNot( PHB_EXPR pSelf, HB_COMP_DECL ) +{ + PHB_EXPR pExpr; + + pExpr = pSelf->value.asOperator.pLeft; + + if( pExpr->ExprType == HB_ET_LOGICAL ) + { + pExpr->value.asLogical = ! pExpr->value.asLogical; + HB_COMP_EXPR_CLEAR( pSelf ); /* suppress deletion of operator components */ + pSelf = pExpr; + } + else if( pExpr->ExprType == HB_EO_NOT && HB_SUPPORT_EXTOPT ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + pExpr->ExprType = HB_ET_NONE; /* suppress deletion of operator components */ + pExpr = pExpr->value.asOperator.pLeft; + HB_COMP_EXPR_FREE( pSelf ); + pSelf = pExpr; + } + /* TODO: add checking of incompatible types + else + { + } + */ + return pSelf; } diff --git a/src/harbour.def b/src/harbour.def index a6ba1cc345..7f77d8e83a 100644 --- a/src/harbour.def +++ b/src/harbour.def @@ -2327,6 +2327,7 @@ hb_compExprReduceMod hb_compExprReduceMult hb_compExprReduceNE hb_compExprReduceNegate +hb_compExprReduceNot hb_compExprReduceOr hb_compExprReducePlus hb_compExprReducePower