2012-10-07 14:40 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* harbour/include/hbcomp.h
  * harbour/src/compiler/hbmain.c
  * harbour/src/compiler/hbstripl.c
    % eliminate repeated HB_P_LINE pcodes bound by unconditional jump
      This optimization is not enabled when debug mode (-b) is used.

  * harbour/include/hberrors.h
  * harbour/src/compiler/hbgenerr.c
  * harbour/src/compiler/harbour.y
  * harbour/src/compiler/harbour.yyc
    + added new compile time error: "Duplicate case value"
This commit is contained in:
Przemyslaw Czerpak
2012-10-07 12:41:26 +00:00
parent 5a6f0fc81f
commit d4f903942a
8 changed files with 96 additions and 14 deletions

View File

@@ -16,6 +16,19 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-10-07 14:40 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/hbcomp.h
* harbour/src/compiler/hbmain.c
* harbour/src/compiler/hbstripl.c
% eliminate repeated HB_P_LINE pcodes bound by unconditional jump
This optimization is not enabled when debug mode (-b) is used.
* harbour/include/hberrors.h
* harbour/src/compiler/hbgenerr.c
* harbour/src/compiler/harbour.y
* harbour/src/compiler/harbour.yyc
+ added new compile time error: "Duplicate case value"
2012-10-06 17:20 UTC+0200 Viktor Szakats (harbour syenar.net)
* src/rtl/checkbox.prg
! another very old visual bug on the appearance of non-checked

View File

@@ -324,7 +324,7 @@ extern void hb_compCodeTraceMarkDead( HB_COMP_DECL, PFUNCTION pFunc );
extern void hb_compOptimizePCode( HB_COMP_DECL, PFUNCTION pFunc );
extern void hb_compPCodeTraceOptimizer( HB_COMP_DECL );
/* Misc functions defined in hbstripl.c */
extern void hb_compStripFuncLines( PFUNCTION pFunc );
extern void hb_compStripFuncLines( HB_COMP_DECL, PFUNCTION pFunc );
/* output related functions defined in gen*.c */
extern void hb_compGenCCode( HB_COMP_DECL, PHB_FNAME ); /* generates the C language output */

View File

@@ -129,10 +129,11 @@ HB_EXTERN_BEGIN
#define HB_COMP_ERR_OPEN_CFG 67
#define HB_COMP_ERR_ALWAYS_AFTER_EXIT 68
#define HB_COMP_ERR_FILE_WRITE 69
#define HB_COMP_ERR_HISTORICAL_1 70
#define HB_COMP_ERR_HISTORICAL_2 71
#define HB_COMP_ERR_HISTORICAL_3 72
#define HB_COMP_ERR_HISTORICAL_4 73
#define HB_COMP_ERR_DUPL_CASE 70
#define HB_COMP_ERR_HISTORICAL_1 71
#define HB_COMP_ERR_HISTORICAL_2 72
#define HB_COMP_ERR_HISTORICAL_3 73
#define HB_COMP_ERR_HISTORICAL_4 74
#define HB_COMP_WARN_AMBIGUOUS_VAR 1
#define HB_COMP_WARN_MEMVAR_ASSUMED 2

View File

@@ -2584,11 +2584,35 @@ static void hb_compSwitchAdd( HB_COMP_DECL, HB_EXPR_PTR pExpr )
pCase = (HB_SWITCHCASE_PTR) hb_xgrab( sizeof( HB_SWITCHCASE ) );
pCase->nOffset = pFunc->nPCodePos;
pCase->pNext = NULL;
pExpr = hb_compExprReduce( pExpr, HB_COMP_PARAM );
pCase->pExpr = pExpr = hb_compExprReduce( pExpr, HB_COMP_PARAM );
if( !( hb_compExprIsLong( pExpr ) || hb_compExprIsString( pExpr ) ) )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_NOT_LITERAL_CASE, NULL, NULL );
else if( pFunc->pSwitch->pCases )
{
HB_SWITCHCASE_PTR pCases = pFunc->pSwitch->pCases;
while( pCases )
{
HB_BOOL fEqual = HB_FALSE;
if( hb_compExprIsLong( pExpr ) )
{
if( hb_compExprIsLong( pCases->pExpr ) )
fEqual = hb_compExprAsLongNum( pExpr ) == hb_compExprAsLongNum( pCases->pExpr );
}
else
{
if( hb_compExprIsString( pCases->pExpr ) )
fEqual = hb_compExprAsStringLen( pExpr ) == hb_compExprAsStringLen( pCases->pExpr ) &&
memcmp( hb_compExprAsString( pExpr ),
hb_compExprAsString( pCases->pExpr ),
hb_compExprAsStringLen( pExpr ) ) == 0;
}
if( fEqual )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_DUPL_CASE, NULL, NULL );
pCases = pCases->pNext;
}
}
pCase->pExpr = pExpr;
if( pFunc->pSwitch->pLast )
{

View File

@@ -8487,11 +8487,35 @@ static void hb_compSwitchAdd( HB_COMP_DECL, HB_EXPR_PTR pExpr )
pCase = (HB_SWITCHCASE_PTR) hb_xgrab( sizeof( HB_SWITCHCASE ) );
pCase->nOffset = pFunc->nPCodePos;
pCase->pNext = NULL;
pExpr = hb_compExprReduce( pExpr, HB_COMP_PARAM );
pCase->pExpr = pExpr = hb_compExprReduce( pExpr, HB_COMP_PARAM );
if( !( hb_compExprIsLong( pExpr ) || hb_compExprIsString( pExpr ) ) )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_NOT_LITERAL_CASE, NULL, NULL );
else if( pFunc->pSwitch->pCases )
{
HB_SWITCHCASE_PTR pCases = pFunc->pSwitch->pCases;
while( pCases )
{
HB_BOOL fEqual = HB_FALSE;
if( hb_compExprIsLong( pExpr ) )
{
if( hb_compExprIsLong( pCases->pExpr ) )
fEqual = hb_compExprAsLongNum( pExpr ) == hb_compExprAsLongNum( pCases->pExpr );
}
else
{
if( hb_compExprIsString( pCases->pExpr ) )
fEqual = hb_compExprAsStringLen( pExpr ) == hb_compExprAsStringLen( pCases->pExpr ) &&
memcmp( hb_compExprAsString( pExpr ),
hb_compExprAsString( pCases->pExpr ),
hb_compExprAsStringLen( pExpr ) ) == 0;
}
if( fEqual )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_DUPL_CASE, NULL, NULL );
pCases = pCases->pNext;
}
}
pCase->pExpr = pExpr;
if( pFunc->pSwitch->pLast )
{

View File

@@ -100,6 +100,7 @@ const char * const hb_comp_szErrors[] =
"Can't find %s file",
"Invalid ALWAYS after %s in RECOVER code",
"File write error",
"Duplicate case value",
/* Some historical, funny sounding error messages from original CA-Cl*pper.
They serve no purpose whatsoever. [vszakats] */
"END wreaks terrible vengeance on control stack",

View File

@@ -1346,7 +1346,7 @@ static void hb_compOptimizeJumps( HB_COMP_DECL )
if( iPass == 3 && fLineStrip )
{
hb_compStripFuncLines( HB_COMP_PARAM->functions.pLast );
hb_compStripFuncLines( HB_COMP_PARAM, HB_COMP_PARAM->functions.pLast );
fLineStrip = HB_FALSE;
}
@@ -1501,7 +1501,7 @@ static void hb_compOptimizeJumps( HB_COMP_DECL )
if( iPass == 0 )
continue;
if( fLineStrip )
hb_compStripFuncLines( HB_COMP_PARAM->functions.pLast );
hb_compStripFuncLines( HB_COMP_PARAM, HB_COMP_PARAM->functions.pLast );
if( HB_COMP_PARAM->functions.pLast->nNOOPs == 0 )
return;
}

View File

@@ -66,12 +66,31 @@ HB_EXTERN_END
static HB_STRIP_FUNC( hb_p_line )
{
HB_SYMBOL_UNUSED( cargo );
switch( pFunc->pCode[ nPCodePos + 3 ] )
{
case HB_P_LINE:
case HB_P_MODULENAME:
hb_compNOOPfill( pFunc, nPCodePos, 3, HB_FALSE, HB_FALSE );
break;
default:
if( !( ( HB_COMP_PTR ) cargo )->fDebugInfo )
{
HB_SIZE nNewPos = nPCodePos;
switch( pFunc->pCode[ nPCodePos + 3 ] )
{
case HB_P_JUMPNEAR:
nNewPos += 3 + ( signed char ) pFunc->pCode[ nPCodePos + 4 ];
break;
case HB_P_JUMP:
nNewPos += 3 + HB_PCODE_MKSHORT( &pFunc->pCode[ nPCodePos + 4 ] );
break;
case HB_P_JUMPFAR:
nNewPos += 3 + HB_PCODE_MKINT24( &pFunc->pCode[ nPCodePos + 4 ] );
break;
}
if( nNewPos != nPCodePos && pFunc->pCode[ nNewPos ] == HB_P_LINE )
hb_compNOOPfill( pFunc, nPCodePos, 3, HB_FALSE, HB_FALSE );
}
}
return 3;
@@ -268,9 +287,9 @@ static const PHB_STRIP_FUNC s_stripLines_table[] =
NULL /* HB_P_PUSHAPARAMS */
};
void hb_compStripFuncLines( PFUNCTION pFunc )
void hb_compStripFuncLines( HB_COMP_DECL, PFUNCTION pFunc )
{
assert( HB_P_LAST_PCODE == sizeof( s_stripLines_table ) / sizeof( PHB_STRIP_FUNC ) );
hb_compPCodeEval( pFunc, s_stripLines_table, NULL );
hb_compPCodeEval( pFunc, s_stripLines_table, ( void * ) HB_COMP_PARAM );
}