From 65cd98cadba9b496e66d330d792c0845128d38f6 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Sat, 4 Aug 2001 14:19:29 +0000 Subject: [PATCH] ChangeLog 2001-08-04 15:15 UTC+0100 --- harbour/ChangeLog | 66 ++++ harbour/doc/en/compiler.txt | 29 +- harbour/doc/en/macro.txt | 77 +++++ harbour/include/hbapi.h | 1 + harbour/include/hbcomp.h | 15 + harbour/include/hbexpra.c | 4 +- harbour/include/hbexprb.c | 510 +++++++++++++++++------------ harbour/include/hbmacro.h | 9 + harbour/include/hbsetup.h | 64 +++- harbour/include/set.ch | 9 + harbour/source/compiler/cmdcheck.c | 49 +++ harbour/source/compiler/expropta.c | 2 +- harbour/source/compiler/exproptb.c | 2 +- harbour/source/compiler/harbour.c | 17 +- harbour/source/compiler/harbour.y | 12 +- harbour/source/compiler/hbfunchk.c | 15 +- harbour/source/compiler/hbusage.c | 22 ++ harbour/source/macro/macro.y | 21 +- harbour/source/macro/macroa.c | 2 +- harbour/source/macro/macrob.c | 2 +- harbour/source/rdd/dblist.prg | 46 +-- harbour/source/vm/asort.c | 11 +- harbour/source/vm/macro.c | 159 +++++++-- 23 files changed, 835 insertions(+), 309 deletions(-) create mode 100644 harbour/doc/en/macro.txt diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b00e4a1e93..a103bf4e43 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,69 @@ +2001-08-04 15:15 UTC+0100 Ryszard Glab + + * doc/en/compiler.txt + * include/hbapi.h + * include/hbcomp.h + * include/hbexpra.c + * include/hbexprb.c + * include/hbmacro.h + * source/compiler/cmdcheck.c + * source/compiler/expropta.c + * source/compiler/exproptb.c + * source/compiler/harbour.c + * source/compiler/harbour.y + * source/compiler/hbfunchk.c + * source/compiler/hbusage.c + * added command line switch which controls a compilation + compatibility level -k + Currently supported modes (can be joined): + -kc ==> 100% Clipper compatible (with some obvious bugs fixed) + -kh ==> harbour extensions enabled (default) + -kx ==> other xbase dialects extensions + * new macro HB_COMP_ISSUPPORTED() to check if a feature + is enabled. Currently supported modes (defined in hbcomp.h): + HB_COMPFLAG_HARBOUR ==> -kh + HB_COMPFLAG_XBASE ==> -kx + * extended macro support for expression lists is disabled by + default (latest Ron's additions) - use -kx switch to enable + + * include/set.ch + * source/vm/macro.c + * source/macro/macro.y + * source/macro/macroa.c + * source/macro/macrob.c + * added HB_SETMACRO() function to control various compatibility + issues at the runtime. + HB_SETMACRO( , ) + This controls the macro compiler's features. The feature can + be either enabled (.T.) or disabled (.F.) + Currently available features (defined in set.ch file) + HB_SM_HARBOUR => (enabled by default) + enable/disable harbour extensions + HB_SM_XBASE => (disaled by default) + enable/disable xbase dialects extensions + HB_SM_SHORTCUTS => (enabled by default) + enable/disable shortcut evaluation of logical expressions + HB_SM_PREPROC => + enable/disable preprocessing (if harbour is build with + HB_MACRO_STATEMENTS option) + + * source/rdd/dblist.prg + * the array of expressions is scanned for extended macro lists + when xbase compatibility is enabled (see HB_SETMACRO()) + + * source/vm/asort.c + * moved HB_ASORT_OPT_ITEMCOPY setting to hbsetup.h + + * include/hbsetup.h + * updated/added descriptions of all #ifdef settings used + in the harbour code + (Please keep updated this file (and hbsetup.ch) if a new + setting is used) + + + doc/en/macro.txt + * initial documentation for macro compiler + * documentation of HB_SETMACRO() function + 2001-08-04 00:06 GMT Dave Pearson * doc/whatsnew.txt * Brought the document up to date. diff --git a/harbour/doc/en/compiler.txt b/harbour/doc/en/compiler.txt index be6905fd53..1d28cac928 100644 --- a/harbour/doc/en/compiler.txt +++ b/harbour/doc/en/compiler.txt @@ -54,25 +54,20 @@ * /es2 = all warnings are treated as errors and no output * file is created. The exit code is set to a non=zero * value. - * - * /g output type generated is - * ================= - * - * /gc output type: C source (.c) (default) - * - * /gf output type: Windows/DOS OBJ32 (.obj) - * - * /gh output type: Harbour Portable Object (.hrb) - * - * /gj output type: Java source (.java) - * - * /gp output type: Pascal source (.pas) - * - * /gr output type: Windows resource (.rc) - * * /i add #include file search path * ================= * + * /k enable compatibility mode + * ================= + * + * /kc strict Clipper compatibility + * + * /kh Harbour extensions (default) + * + * /kx other xbase dialects extensions + * + * /k? invoke help information + * * /l suppress line number information * ================= * @@ -193,7 +188,7 @@ * * NOTE: * - * If you want a 100% compatible compile and runtime libraries then + * If you want a 100% compatible runtime libraries then * you have to define HARBOUR_STRICT_CLIPPER_COMPATIBILITY. This * option should be defined in the file include/hbsetup.h (in fact this * option is placed in a comment by default = you need to remove the diff --git a/harbour/doc/en/macro.txt b/harbour/doc/en/macro.txt new file mode 100644 index 0000000000..f58c2f6266 --- /dev/null +++ b/harbour/doc/en/macro.txt @@ -0,0 +1,77 @@ +/* + * $Id$ + */ + +/* $DOC$ + * $FUNCNAME$ + * Macro compiler + * $CATEGORY$ + * Document + * $ONELINER$ + * Macro compiler + * $DESCRIPTION$ + * + * Invoking the macro compiler: + * ============================== + * + * &variable + * or + * &( expression ) + * or + * &variable.text + * + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * HB_SETMACRO() + * $CATEGORY$ + * Macro compiler + * $ONELINER$ + * Enable/disable the macro compiler runtime features. + * $SYNTAX$ + * HB_SETMACRO( [, ]) --> + * $ARGUMENTS$ + * A constant defined in set.ch. + .T. to enable or .F. to disable a feature + * $RETURNS$ + * The old state of requested feature. + * $DESCRIPTION$ + * This function enables or disables some features of the macro + * compiler. The Harbour is extending the macro features compared + * to an original set available in Clipper. Enabling/disabling + * some of them allows to keep strict Clipper compatibility. + * + * Available features are: + * HB_SM_HARBOUR - enables harbour extensions: + * operators: ++, --, +=, -=, *=, /=, ^= + * objects: assigments to an instance variable + * HB_SM_XBASE - enables other xbase dialects extensions: + * expanding of expresions lists + * HB_SM_SHORTCUTS - enables optimized evaluation of + * logical operators (.and., .or.) + * HB_SM_PREPROC - enables preprocessing of commands + * This is meaningfull if Harbour is compiled with + * HB_MACRO_STATEMENTS flag + * + * $EXAMPLES$ + * INIT PROCEDURE IWANTCLIPPER() + * HB_SETMACRO( HB_SM_HARBOUR, .F. ) + * HB_SETMACRO( HB_SM_XBASE, .F. ) + * RETURN + * + * + * $STATUS$ + * R + * $COMPLIANCE$ + * This function is Harbour extension. + * $PLATFORMS$ + * All + * $FILES$ + * Library is macro + * $SEEALSO$ + * + * $END$ + */ + diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 5eaf485eda..572b2f154f 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -518,6 +518,7 @@ typedef struct HB_MACRO_ /* a macro compiled pcode container */ ULONG pos; /* current position inside of compiled string */ int Flags; /* some flags we may need */ int status; /* status of compilation */ + ULONG supported; /* various flags for supported capabilities */ int FlexState; /* internal flex state during parsing */ HB_PCODE_INFO_PTR pCodeInfo; /* pointer to pcode buffer and info */ void * pParseInfo; /* data needed by the parser - it should be 'void *' to allow different implementation of macr compiler */ diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 9149678286..fe6ef7e63a 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -386,6 +386,7 @@ extern void hb_compChkDefines( int iArg, char * Args[] ); extern void hb_compPrintUsage( char * ); extern void hb_compPrintCredits( void ); extern void hb_compPrintLogo( void ); +extern void hb_compPrintModes( void ); extern int hb_compCompile( char * szPrg, int argc, char * argv[] ); @@ -490,6 +491,8 @@ extern INLINES hb_comp_inlines; extern int hb_comp_iLineINLINE; extern int hb_comp_iLinePRG; +extern ULONG hb_comp_Supported; + /* /GC command line setting types */ #define HB_COMPGENC_COMPACT 0 #define HB_COMPGENC_NORMAL 1 @@ -500,6 +503,18 @@ extern int hb_comp_iLinePRG; #define HB_EXITLEVEL_SETEXIT 1 #define HB_EXITLEVEL_DELTARGET 2 +/* /kx command line setting types - compatibility modes + * (turn on a bit in ULONG word) +*/ +#define HB_COMPFLAG_HARBOUR 1 /* -kh */ +#define HB_COMPFLAG_XBASE 2 /* -kx */ + +#ifdef HB_MACRO_SUPPORT + #define HB_COMP_ISSUPPORTED(flag) ( HB_MACRO_DATA->supported & (flag) ) +#else + #define HB_COMP_ISSUPPORTED(flag) ( hb_comp_Supported & (flag) ) +#endif + #if defined(HB_EXTERN_C) } #endif diff --git a/harbour/include/hbexpra.c b/harbour/include/hbexpra.c index ab6ee88870..b4a9a5b90d 100644 --- a/harbour/include/hbexpra.c +++ b/harbour/include/hbexpra.c @@ -68,7 +68,6 @@ #define HB_XGRAB( size ) hb_xgrab( (size) ) #define HB_XFREE( pPtr ) hb_xfree( (void *)(pPtr) ) - /* Table with operators precedence * NOTE: * HB_ET_NIL is used for an ordinary values and post- operators @@ -329,7 +328,8 @@ HB_EXPR_PTR hb_compExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms ) HB_EXPR_PCODE1( hb_compExprDelete, pName ); } } - else if( ( strcmp( "__DBLIST", pName->value.asSymbol ) == 0 ) && iCount >= 10 ) + else if( HB_COMP_ISSUPPORTED( HB_COMPFLAG_XBASE ) && + (( strcmp( "__DBLIST", pName->value.asSymbol ) == 0 ) && iCount >= 10) ) { HB_EXPR_PTR pArray = pParms->value.asList.pExprList->pNext; diff --git a/harbour/include/hbexprb.c b/harbour/include/hbexprb.c index 900e4bd6ed..8b285d355a 100644 --- a/harbour/include/hbexprb.c +++ b/harbour/include/hbexprb.c @@ -80,6 +80,9 @@ void hb_compExprUseAliasMacro( HB_EXPR_PTR, BYTE, HB_MACRO_DECL ); void hb_compExprPushOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq, HB_MACRO_DECL ); ULONG hb_compExprReduceList( HB_EXPR_PTR, HB_MACRO_DECL ); + + #define HB_SUPPORT_XBASE ( HB_COMP_ISSUPPORTED(HB_SM_XBASE) ) + #define HB_SUPPORT_HARBOUR ( HB_COMP_ISSUPPORTED(HB_SM_HARBOUR) ) #else void hb_compExprDelOperator( HB_EXPR_PTR ); void hb_compExprUseOperEq( HB_EXPR_PTR, BYTE ); @@ -89,8 +92,12 @@ void hb_compExprUseAliasMacro( HB_EXPR_PTR, BYTE ); void hb_compExprPushOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ); ULONG hb_compExprReduceList( HB_EXPR_PTR ); + + #define HB_SUPPORT_XBASE ( HB_COMP_ISSUPPORTED(HB_COMPFLAG_XBASE) ) + #define HB_SUPPORT_HARBOUR ( HB_COMP_ISSUPPORTED(HB_COMPFLAG_HARBOUR) ) #endif + HB_EXPR_PTR hb_compExprReduceMod( HB_EXPR_PTR pSelf, HB_MACRO_DECL ); HB_EXPR_PTR hb_compExprReduceDiv( HB_EXPR_PTR pSelf, HB_MACRO_DECL ); HB_EXPR_PTR hb_compExprReduceMult( HB_EXPR_PTR pSelf, HB_MACRO_DECL ); @@ -396,6 +403,15 @@ static HB_EXPR_FUNC( hb_compExprUseCodeblock ) pPrev = &pSelf->value.asList.pExprList; while( pExpr ) { + if( pExpr->ExprType == HB_ET_MACRO ) + { + /* Clipper allows for list expressions in a codeblock + * macro := "1,2" + * EVAL( {|| ¯o} ) + */ + pExpr->value.asMacro.SubType |= HB_ET_MACRO_PARE; + } + /* store next expression in case the current will be reduced * NOTE: During reduction the expression can be replaced by the * new one - this will break the linked list of expressions. @@ -531,14 +547,17 @@ static HB_EXPR_FUNC( hb_compExprUseArray ) BOOL bMacroList = FALSE; /* Find out if macro is used as on of the elements- if so generate a prefix HB_P_MACROLIST. */ - while( pElem ) + if( HB_SUPPORT_XBASE ) { - if( pElem->ExprType == HB_ET_MACRO ) + while( pElem ) { - pElem->value.asMacro.SubType |= HB_ET_MACRO_LIST; - bMacroList = TRUE; + if( pElem->ExprType == HB_ET_MACRO ) + { + pElem->value.asMacro.SubType |= HB_ET_MACRO_LIST; + bMacroList = TRUE; + } + pElem = pElem->pNext; } - pElem = pElem->pNext; } if( bMacroList ) @@ -738,11 +757,14 @@ static HB_EXPR_FUNC( hb_compExprUseList ) { case HB_EA_REDUCE: { - if( hb_compExprListLen( pSelf ) == 1 ) + if( HB_SUPPORT_XBASE ) { - if( pSelf->value.asList.pExprList->ExprType == HB_ET_MACRO ) + if( hb_compExprListLen( pSelf ) == 1 ) { - pSelf->value.asList.pExprList->value.asMacro.SubType |= HB_ET_MACRO_PARE; + if( pSelf->value.asList.pExprList->ExprType == HB_ET_MACRO ) + { + pSelf->value.asList.pExprList->value.asMacro.SubType |= HB_ET_MACRO_PARE; + } } } @@ -784,9 +806,12 @@ static HB_EXPR_FUNC( hb_compExprUseList ) { while( pExpr ) { - if( pExpr->ExprType == HB_ET_MACRO ) + if( HB_SUPPORT_XBASE ) { - pExpr->value.asMacro.SubType |= HB_ET_MACRO_PARE; + if( pExpr->ExprType == HB_ET_MACRO ) + { + pExpr->value.asMacro.SubType |= HB_ET_MACRO_PARE; + } } if( pExpr->pNext ) @@ -809,9 +834,12 @@ static HB_EXPR_FUNC( hb_compExprUseList ) while( pExpr ) { - if( pExpr->ExprType == HB_ET_MACRO ) + if( HB_SUPPORT_XBASE ) { - pExpr->value.asMacro.SubType |= HB_ET_MACRO_PARE; + if( pExpr->ExprType == HB_ET_MACRO ) + { + pExpr->value.asMacro.SubType |= HB_ET_MACRO_PARE; + } } HB_EXPR_USE( pExpr, HB_EA_PUSH_POP ); @@ -968,9 +996,12 @@ static HB_EXPR_FUNC( hb_compExprUseArrayAt ) { HB_EXPR_USE( pSelf->value.asList.pExprList, HB_EA_PUSH_PCODE ); - if( pSelf->value.asList.pIndex->ExprType == HB_ET_MACRO ) + if( HB_SUPPORT_XBASE ) { - pSelf->value.asList.pIndex->value.asMacro.SubType |= HB_ET_MACRO_INDEX; + if( pSelf->value.asList.pIndex->ExprType == HB_ET_MACRO ) + { + pSelf->value.asList.pIndex->value.asMacro.SubType |= HB_ET_MACRO_INDEX; + } } HB_EXPR_USE( pSelf->value.asList.pIndex, HB_EA_PUSH_PCODE ); @@ -1051,23 +1082,32 @@ static HB_EXPR_FUNC( hb_compExprUseMacro ) { if( pSelf->value.asMacro.SubType & HB_ET_MACRO_ARGLIST ) { + /* funCall( ¯o ) + */ HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_MACROPUSHARG ); HB_EXPR_USE( pSelf->value.asMacro.pFunCall->value.asFunCall.pFunName, HB_EA_PUSH_PCODE ); } else if( pSelf->value.asMacro.SubType & HB_ET_MACRO_LIST ) { + /* { ¯o } + */ HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_MACROPUSHLIST ); } else if( pSelf->value.asMacro.SubType & HB_ET_MACRO_INDEX ) { + /* var[ ¯o ] */ HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_MACROPUSHINDEX ); } else if( pSelf->value.asMacro.SubType & HB_ET_MACRO_PARE ) { + /* var := (somevalue, ¯o) - in xbase compatibility mode + * EVAL( {|| ¯o} ) - in all cases + */ HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_MACROPUSHPARE ); } else { + /* usual ¯o */ HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_MACROPUSH ); } } @@ -1171,16 +1211,19 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) --usCount; if( usCount ) { - /* check if ¯o is used as a function call argument */ - HB_EXPR_PTR pExpr = pSelf->value.asFunCall.pParms->value.asList.pExprList; - while( pExpr ) + if( HB_SUPPORT_XBASE ) { - if( pExpr->ExprType == HB_ET_MACRO ) - { - pExpr->value.asMacro.SubType |= HB_ET_MACRO_ARGLIST; - pExpr->value.asMacro.pFunCall = pSelf; - } - pExpr = pExpr->pNext; + /* check if ¯o is used as a function call argument */ + HB_EXPR_PTR pExpr = pSelf->value.asFunCall.pParms->value.asList.pExprList; + while( pExpr ) + { + if( pExpr->ExprType == HB_ET_MACRO ) + { + pExpr->value.asMacro.SubType |= HB_ET_MACRO_ARGLIST; + pExpr->value.asMacro.pFunCall = pSelf; + } + pExpr = pExpr->pNext; + } } HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); } @@ -1213,17 +1256,20 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) --usCount; if( usCount ) { - HB_EXPR_PTR pExpr = pSelf->value.asFunCall.pParms->value.asList.pExprList; - /* check if ¯o is used as a function call argument */ - while( pExpr ) + if( HB_SUPPORT_XBASE ) { - if( pExpr->ExprType == HB_ET_MACRO ) - { - /* ¯o was passed - handle it differently then in a normal statement */ - pExpr->value.asMacro.SubType |= HB_ET_MACRO_ARGLIST; - pExpr->value.asMacro.pFunCall = pSelf; - } - pExpr = pExpr->pNext; + HB_EXPR_PTR pExpr = pSelf->value.asFunCall.pParms->value.asList.pExprList; + /* check if ¯o is used as a function call argument */ + while( pExpr ) + { + if( pExpr->ExprType == HB_ET_MACRO ) + { + /* ¯o was passed - handle it differently then in a normal statement */ + pExpr->value.asMacro.SubType |= HB_ET_MACRO_ARGLIST; + pExpr->value.asMacro.pFunCall = pSelf; + } + pExpr = pExpr->pNext; + } } HB_EXPR_USE( pSelf->value.asFunCall.pParms, HB_EA_PUSH_PCODE ); } @@ -2140,16 +2186,19 @@ static HB_EXPR_FUNC( hb_compExprUseOr ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2209,16 +2258,19 @@ static HB_EXPR_FUNC( hb_compExprUseAnd ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2274,15 +2326,18 @@ static HB_EXPR_FUNC( hb_compExprUseNot ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2396,16 +2451,19 @@ static HB_EXPR_FUNC( hb_compExprUseEqual ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2473,16 +2531,19 @@ static HB_EXPR_FUNC( hb_compExprUseEQ ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2528,16 +2589,19 @@ static HB_EXPR_FUNC( hb_compExprUseLT ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2583,16 +2647,19 @@ static HB_EXPR_FUNC( hb_compExprUseGT ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2639,16 +2706,19 @@ static HB_EXPR_FUNC( hb_compExprUseLE ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2695,16 +2765,19 @@ static HB_EXPR_FUNC( hb_compExprUseGE ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2751,16 +2824,19 @@ static HB_EXPR_FUNC( hb_compExprUseNE ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2808,16 +2884,19 @@ static HB_EXPR_FUNC( hb_compExprUseIN ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2863,16 +2942,19 @@ static HB_EXPR_FUNC( hb_compExprUsePlus ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2918,16 +3000,19 @@ static HB_EXPR_FUNC( hb_compExprUseMinus ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -2973,16 +3058,19 @@ static HB_EXPR_FUNC( hb_compExprUseMult ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -3028,16 +3116,19 @@ static HB_EXPR_FUNC( hb_compExprUseDiv ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -3083,16 +3174,19 @@ static HB_EXPR_FUNC( hb_compExprUseMod ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else - /* NOTE: This will not generate a runtime error if incompatible - * data type is used - */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + if( HB_SUPPORT_HARBOUR ) + { + /* NOTE: This will not generate a runtime error if incompatible + * data type is used + */ + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -3135,16 +3229,19 @@ static HB_EXPR_FUNC( hb_compExprUsePower ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else + if( HB_SUPPORT_HARBOUR ) + { /* NOTE: This will not generate a runtime error if incompatible * data type is used */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); - HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); -#endif + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: @@ -3202,15 +3299,18 @@ static HB_EXPR_FUNC( hb_compExprUseNegate ) break; case HB_EA_PUSH_POP: -#ifdef HB_C52_STRICT - HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); - HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); -#else + if( HB_SUPPORT_HARBOUR ) + { /* NOTE: This will not generate a runtime error if incompatible * data type is used */ - HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); -#endif + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_POP ); + } + else + { + HB_EXPR_USE( pSelf, HB_EA_PUSH_PCODE ); + HB_EXPR_GENPCODE1( hb_compGenPCode1, HB_P_POP ); + } break; case HB_EA_STATEMENT: diff --git a/harbour/include/hbmacro.h b/harbour/include/hbmacro.h index 69c8146290..bbf90afb52 100644 --- a/harbour/include/hbmacro.h +++ b/harbour/include/hbmacro.h @@ -84,6 +84,7 @@ extern "C" { #define HB_MACRO_GEN_ALIASED 4 /* force aliased variable */ #define HB_MACRO_GEN_TYPE 8 /* check the type of expression (from TYPE() function) */ #define HB_MACRO_GEN_PARE 16 /* generate parentesized list */ +#define HB_MACRO_GEN_LIST 32 /* generate push operation for every comma separated expressions */ #define HB_MACRO_DEALLOCATE 128 /* macro structure is allocated on the heap */ /* values returned from compilation process @@ -99,12 +100,20 @@ extern "C" { #define HB_MACRO_UNKN_SYM 8 /* requested symbol was not found in runtime symbol table */ #define HB_MACRO_UNKN_VAR 16 /* requested variable doesn't exist */ +/* runtime settings for macro compiler */ +#define HB_SM_HARBOUR 1 /* extended Harbour features */ +#define HB_SM_XBASE 2 /* extended xbase compatibility */ +#define HB_SM_PREPROC 4 /* enable/disable commands preprocessing */ +#define HB_SM_SHORTCUTS 8 /* enable/disable sortcuts for logical operators */ +#define HB_SM_PARSER 128 /* address of macro parser (TODO) */ + /* Global functions */ extern void hb_macroError( int iError, HB_BISON_PTR pMacro ); extern int hb_macroYYParse( HB_MACRO_PTR pMacro ); +extern ULONG hb_macroSetMacro( BOOL bSet, ULONG ulFlag ); extern void hb_compGenPCode1( BYTE byte, HB_BISON_PTR pMacro ); extern void hb_compGenPCode2( BYTE byte1, BYTE byte2, HB_BISON_PTR pMacro ); diff --git a/harbour/include/hbsetup.h b/harbour/include/hbsetup.h index 33dc9c5f48..89ba01a7c5 100644 --- a/harbour/include/hbsetup.h +++ b/harbour/include/hbsetup.h @@ -55,11 +55,15 @@ #include -/* Include settings common for .PRG and .C files */ +/* *********************************************************************** + * Include settings common for .PRG and .C files +*/ #include "hbsetup.ch" -/* NOTE: You can select the default language modul used by Harbour, by - defining this to a valid language modul identifier. */ +/* *********************************************************************** + * NOTE: You can select the default language modul used by Harbour, by + * defining this to a valid language modul identifier. +*/ #ifndef HB_LANG_DEFAULT #define HB_LANG_DEFAULT EN @@ -146,7 +150,6 @@ * * By default this value is 63 */ - #ifndef HB_SYMBOL_NAME_LEN /* NOTE: For complete CA-Cl*pper compatibility you can set the maximum symbol name to 10. Sometimes this can be useful for compiling legacy @@ -162,8 +165,52 @@ */ #endif -/* Detect GCC/OS2 */ +/* *********************************************************************** + * You can select here, if the preprocessor should be linked + * for commands preprocessing passed to the macro compiler. + * (Note, that if it is linked then commands preprocessing can be + * disabled/enabled at runtime using HB_SETMACRO() function + * + * By default we do not support commands in the macro compiler. +*/ +/* #define HB_MACRO_STATEMENTS */ + +/* *********************************************************************** + * This fixes a bug in Clipper that allowed for copy array elements + * beyond the destination array size + * + * By default we are 100% Clipper compatible +*/ +/* #define HB_FIX_ACOPY_BUG */ + +/* *********************************************************************** + * This controls an optimisation in ASORT() function + * + * If this is defined the item copying is optimized, in a way that + * instead of calling the official hb_itemCopy(), the item structures + * will be directly copied with memcpy(), this means that the related + * data areas (string space for example) will never be moved. This can be + * safely done here, because it's guaranteed by the nature of sorting + * that the set of items doesn't change (there're no deleted or new + * items, just swapping) in this functions. + * Using this option makes sorting *much* faster, but if you have a + * problem, or the low level stuff changes, turn it off. [vszakats] +*/ +#define HB_ASORT_OPT_ITEMCOPY + +/* *********************************************************************** + * You can select here faster but less secure behaviour of STOD() function + * There is no data validation if this is enabled. + * + * By default we are using secure method. +*/ +/* #define HB_FAST_STOD */ + + +/* *********************************************************************** + * Detect GCC/OS2 +*/ #if defined(__EMX__) && ! defined(__RSXNT__) #define HARBOUR_GCC_OS2 #endif @@ -261,6 +308,13 @@ #endif #endif +/* *********************************************************************** + * See also the following files for task specific definitions/settings + * + * hbmath.h - math errors handling +*/ + + /* *********************************************************************** * Extern "C" detection */ diff --git a/harbour/include/set.ch b/harbour/include/set.ch index 9eacf3811a..898b6024fa 100644 --- a/harbour/include/set.ch +++ b/harbour/include/set.ch @@ -121,3 +121,12 @@ #define HB_SET_COUNT 2 #endif /* _SET_CH */ + +/* runtime settings for macro compiler (HB_SETMACRO() function) +*/ +#define HB_SM_HARBOUR 1 /* extended Harbour compatibility */ +#define HB_SM_XBASE 2 /* extended xbase compatibility */ +#define HB_SM_PREPORC 4 /* enable/disable commands preprocessing */ +#define HB_SM_SHORTCUTS 8 /* enable/disable sortcuts for logical operators */ +#define HB_SM_PARSER 128 /* address of macro parser (TODO) */ + diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index a25ae019fc..708fd15621 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -287,6 +287,15 @@ void hb_compChkCompilerSwitch( int iArg, char * Args[] ) j = strlen( Args[i] ); continue; + case 'k' : + case 'K' : + Args[i] += ( j - 1 ); + hb_compChkEnvironVar( Args[i] ); + + /* Accept rest as part of #define and continue with next Args[]. */ + j = strlen( Args[i] ); + continue; + case 'o' : case 'O' : Args[i] += (j - 1); @@ -564,6 +573,7 @@ void hb_compChkEnvironVar( char * szSwitch ) hb_comp_iLanguage = LANG_PORT_OBJ; break; + case 'o': case 'O': hb_comp_iLanguage = LANG_OBJ_MODULE; @@ -608,6 +618,45 @@ void hb_compChkEnvironVar( char * szSwitch ) } break; + case 'k': + case 'K': + { + int i = 1; + while( s[ i ] ) + { + switch( s[ i++ ] ) + { + case '?': + hb_compPrintLogo(); + hb_compPrintModes(); + hb_comp_bLogo = FALSE; + hb_comp_bQuiet = TRUE; + break; + + case 'h': + case 'H': + /* default Harbour mode */ + hb_comp_Supported |= HB_COMPFLAG_HARBOUR; + break; + + case 'c': + case 'C': + hb_comp_Supported &= ~HB_COMPFLAG_HARBOUR; + break; + + case 'x': + case 'X': + hb_comp_Supported |= HB_COMPFLAG_XBASE; + break; + + default: + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); + break; + } + } + } + break; + case 'l': case 'L': if( *( s + 1 ) == '-' ) diff --git a/harbour/source/compiler/expropta.c b/harbour/source/compiler/expropta.c index 13543c4818..0e75fa056e 100644 --- a/harbour/source/compiler/expropta.c +++ b/harbour/source/compiler/expropta.c @@ -5,6 +5,6 @@ /* hbexpra.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 6 - ignore this magic number - this is used to force compilation + * 7 - ignore this magic number - this is used to force compilation */ #include "hbexpra.c" diff --git a/harbour/source/compiler/exproptb.c b/harbour/source/compiler/exproptb.c index 934192ad68..315a3c2f2b 100644 --- a/harbour/source/compiler/exproptb.c +++ b/harbour/source/compiler/exproptb.c @@ -5,6 +5,6 @@ /* hbexprb.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1 - ignore this magic number - this is used to force compilation + * 8 - ignore this magic number - this is used to force compilation */ #include "hbexprb.c" diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index c32db17207..b145978b41 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -141,6 +141,9 @@ int hb_comp_iLineINLINE = 0; int hb_comp_iLinePRG; INLINES hb_comp_inlines; +/* various compatibility flags (-k switch) */ +ULONG hb_comp_Supported = HB_COMPFLAG_HARBOUR; + /* EXTERNAL statement can be placed into any place in a function - this flag is * used to suppress error report generation */ @@ -243,7 +246,7 @@ int main( int argc, char * argv[] ) hb_compIdentifierClose(); - if( ! bAnyFiles ) + if( (! bAnyFiles ) && (! hb_comp_bQuiet) ) { hb_compPrintUsage( argv[ 0 ] ); iStatus = EXIT_FAILURE; @@ -2222,16 +2225,18 @@ void hb_compLinePushIfInside( void ) /* generates the pcode with the currently c */ static void hb_compGenVariablePCode( BYTE bPCode, char * szVarName ) { + BOOL bGenCode; /* * NOTE: * Clipper always assumes a memvar variable if undeclared variable * is popped (a value is asssigned to a variable). */ -#if defined( HB_C52_STRICT ) - if( hb_comp_bForceMemvars || bPCode == HB_P_POPVARIABLE ) -#else - if( hb_comp_bForceMemvars ) -#endif + if( HB_COMP_ISSUPPORTED( HB_COMPFLAG_HARBOUR ) ) + bGenCode = hb_comp_bForceMemvars; /* harbour compatibility */ + else + bGenCode = ( hb_comp_bForceMemvars || bPCode == HB_P_POPVARIABLE ); + + if( bGenCode ) { /* -v switch was used -> assume it is a memvar variable */ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 75fb48681f..341829a6f7 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -325,8 +325,16 @@ Statement : ExecFlow CrlfStmnt { } | FunCall CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | AliasExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | ObjectMethod CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } - | MacroVar CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } - | MacroExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } + | MacroVar CrlfStmnt { if( HB_COMP_ISSUPPORTED( HB_COMPFLAG_XBASE ) ) + hb_compExprDelete( hb_compExprGenStatement( $1 ) ); + else + hb_compExprDelete( hb_compErrorSyntax( $1 ) ); + } + | MacroExpr CrlfStmnt { if( HB_COMP_ISSUPPORTED( HB_COMPFLAG_XBASE ) ) + hb_compExprDelete( hb_compExprGenStatement( $1 ) ); + else + hb_compExprDelete( hb_compErrorSyntax( $1 ) ); + } | PareExpList CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | ExprPreOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | ExprPostOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } diff --git a/harbour/source/compiler/hbfunchk.c b/harbour/source/compiler/hbfunchk.c index 0130b78306..6148bcb7a5 100644 --- a/harbour/source/compiler/hbfunchk.c +++ b/harbour/source/compiler/hbfunchk.c @@ -135,10 +135,8 @@ void hb_compFunCallCheck( char * szFuncCall, int iArgs ) { if( iArgs < f[ iPos ].iMinParam || ( f[ iPos ].iMaxParam != -1 && iArgs > f[ iPos ].iMaxParam ) ) { -#if defined( HB_C52_STRICT ) - /* Clipper way */ - hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_CHECKING_ARGS, szFuncCall, NULL ); -#else + if( HB_COMP_ISSUPPORTED( HB_COMPFLAG_HARBOUR ) ) + { char szMsg[ 40 ]; if( f[ iPos ].iMaxParam == -1 ) @@ -149,8 +147,13 @@ void hb_compFunCallCheck( char * szFuncCall, int iArgs ) sprintf( szMsg, "\nPassed: %i, expected: %i - %i", iArgs, f[ iPos ].iMinParam, f[ iPos ].iMaxParam ); hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_CHECKING_ARGS, szFuncCall, szMsg ); -#endif - } + } + else + { + /* Clipper way */ + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_CHECKING_ARGS, szFuncCall, NULL ); + } + } } } diff --git a/harbour/source/compiler/hbusage.c b/harbour/source/compiler/hbusage.c index 044fc9f4fe..a68eb58834 100644 --- a/harbour/source/compiler/hbusage.c +++ b/harbour/source/compiler/hbusage.c @@ -71,6 +71,7 @@ void hb_compPrintUsage( char * szSelf ) "\n %cgh output type: Harbour Portable Object (.hrb)", "\n %cgj output type: Java source (.java)", "\n %ci #include file search path", + "\n %ck compilation mode (type -k? for more data)", "\n %cl suppress line number information", "\n %cm compile module only", "\n %cn no implicit starting procedure", @@ -102,6 +103,27 @@ void hb_compPrintUsage( char * szSelf ) printf( szOptions[ iLine ], OS_OPT_DELIMITER_LIST[ 0 ] ); } +/* + * List of compatybility/features modes + */ +void hb_compPrintModes( void ) +{ + static const char * szOptions [] = + { + "\nOptions: c strict Clipper mode", + "\n h Harbour mode (default)", + "\n x extended xbase mode", + "\n ? this info", + "\n" + }; + int iLine; + + printf( "\nCompatybility flags: -k[options]\n" ); + + for( iLine = 0; iLine < ( sizeof( szOptions ) / sizeof( char * ) ); iLine++ ) + printf( szOptions[ iLine ] ); +} + /* * Prints credits */ diff --git a/harbour/source/macro/macro.y b/harbour/source/macro/macro.y index 4d3abd7002..a682464dcf 100644 --- a/harbour/source/macro/macro.y +++ b/harbour/source/macro/macro.y @@ -103,6 +103,15 @@ extern void yyerror( char * ); /* parsing error management function */ YYABORT; \ } +#define HB_MACRO_IFENABLED( pSet, pExpr, flag ) \ + if( HB_MACRO_DATA->supported & (flag) ) \ + { pSet = (pExpr); }\ + else \ + { \ + hb_compExprDelete( (pExpr), HB_MACRO_PARAM ); \ + YYABORT; \ + } + %} %union /* special structure used by lex and yacc to share info */ @@ -456,9 +465,9 @@ SimpleExpression : | ObjectMethod { $$ = $1; } | AliasExpr { $$ = $1; } | ExprAssign { $$ = $1; } - | ExprOperEq { $$ = $1; } - | ExprPostOp { $$ = $1; } - | ExprPreOp { $$ = $1; } + | ExprOperEq { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); } + | ExprPostOp { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); } + | ExprPreOp { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); } | ExprUnary { $$ = $1; } | ExprMath { $$ = $1; } | ExprBool { $$ = $1; } @@ -469,8 +478,8 @@ Expression : SimpleExpression { $$ = $1; HB_MACRO_CHECK( $$ ); } | PareExpList { $$ = $1; HB_MACRO_CHECK( $$ ); } ; -RootParamList : EmptyExpression ',' { /* AsParamList only acceptable for HB_P_MACROPUSHARG in which case iListElements == 0 */ - if( HB_MACRO_DATA->iListElements != 0 ) +RootParamList : EmptyExpression ',' { + if( !(HB_MACRO_DATA->Flags & HB_MACRO_GEN_LIST) ) { HB_TRACE(HB_TR_DEBUG, ("macro -> invalid expression: %s", HB_MACRO_DATA->string)); hb_macroError( EG_SYNTAX, HB_MACRO_PARAM ); @@ -548,7 +557,7 @@ ExprAssign : NumValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $ | PareExpList INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } | IfInline INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } | FunCall INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } - | ObjectData INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } + | ObjectData INASSIGN Expression { HB_MACRO_IFENABLED( $$, hb_compExprAssign( $1, $3 ), HB_SM_HARBOUR ); } | ObjectMethod INASSIGN Expression { $$ = hb_compExprAssign( $1, $3 ); } ; diff --git a/harbour/source/macro/macroa.c b/harbour/source/macro/macroa.c index 31119a8208..109e1e2f96 100644 --- a/harbour/source/macro/macroa.c +++ b/harbour/source/macro/macroa.c @@ -5,7 +5,7 @@ /* hbexpra.c is also included from ../compiler/expropta.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 6 - ignore this magic number - this is used to force compilation + * 7 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/macro/macrob.c b/harbour/source/macro/macrob.c index c54b1e0508..8b0b4caae1 100644 --- a/harbour/source/macro/macrob.c +++ b/harbour/source/macro/macrob.c @@ -5,7 +5,7 @@ /* hbexprb.c is also included from ../compiler/exproptb.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 2 - ignore this magic number - this is used to force compilation + * 3 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/rdd/dblist.prg b/harbour/source/rdd/dblist.prg index 09ad43d01e..ecc2b98309 100644 --- a/harbour/source/rdd/dblist.prg +++ b/harbour/source/rdd/dblist.prg @@ -59,6 +59,8 @@ /* NOTE: lAll is basically a dummy parameter, nothing really depends on it. [vszakats] */ +#include "set.ch" + FUNCTION __dbList( lOff, abEval, lAll, bFor, bWhile, nNext, nRecord, lRest, lToPrint, cToFileName ) LOCAL lOldPrinter @@ -74,31 +76,33 @@ FUNCTION __dbList( lOff, abEval, lAll, bFor, bWhile, nNext, nRecord, lRest, lToP LOCAL nLen := Len( abEval ), nIndex, asMacros, nMacros, nMacroIndex - // Scan for strings instead of blocks - These are macros that need to be compiled into blocks. - FOR nIndex := 1 TO nLen - IF ValType( abEval[ nIndex ] ) == 'C' - //? abEval[ nIndex ] - // Macro may be a comma seperated list. - asMacros := HB_aExpressions( abEval[ nIndex ] ) - nMacros := Len( asMacros ) + IF( HB_SETMACRO( HB_SM_XBASE ) ) + // Scan for strings instead of blocks - These are macros that need to be compiled into blocks. + FOR nIndex := 1 TO nLen + IF ValType( abEval[ nIndex ] ) == 'C' + //? abEval[ nIndex ] + // Macro may be a comma seperated list. + asMacros := HB_aExpressions( abEval[ nIndex ] ) + nMacros := Len( asMacros ) - // Array has to be sized to allow dor the extra blocks - nLen += ( nMacros - 1 ) - aSize( abEval, nLen ) + // Array has to be sized to allow dor the extra blocks + nLen += ( nMacros - 1 ) + aSize( abEval, nLen ) - // We will use the place holder of the string for the first new block. - abEval[ nIndex ] := &( "{||" + asMacros[ 1 ] + "}" ) + // We will use the place holder of the string for the first new block. + abEval[ nIndex ] := &( "{||" + asMacros[ 1 ] + "}" ) - // We will now push all subsequent blocks 1 at a time and insert the new block inplace. - FOR nMacroIndex := 2 TO nMacros - aIns( abEval, nIndex + nMacroIndex - 1 ) - abEval[ nIndex + nMacroIndex - 1 ] := &( "{||" + asMacros[ nMacroIndex ] + "}" ) - NEXT + // We will now push all subsequent blocks 1 at a time and insert the new block inplace. + FOR nMacroIndex := 2 TO nMacros + aIns( abEval, nIndex + nMacroIndex - 1 ) + abEval[ nIndex + nMacroIndex - 1 ] := &( "{||" + asMacros[ nMacroIndex ] + "}" ) + NEXT - // The loop counter should skip the new elements. - nIndex += ( nMacros - 1 ) - ENDIF - NEXT + // The loop counter should skip the new elements. + nIndex += ( nMacros - 1 ) + ENDIF + NEXT + ENDIF /* Choose the output style */ IF lOff diff --git a/harbour/source/vm/asort.c b/harbour/source/vm/asort.c index 1a5e96f865..e741ccdbe6 100644 --- a/harbour/source/vm/asort.c +++ b/harbour/source/vm/asort.c @@ -62,16 +62,7 @@ #include "hbvm.h" #include "hbstack.h" -/* NOTE: If this is defined the item copying is optimized, in a way that - instead of calling the official hb_itemCopy(), the item structures - will be directly copied with memcpy(), this means that the related - data areas (string space for example) will never be moved. This can be - safely done here, because it's guaranteed by the nature of sorting - that the set of items doesn't change (there're no deleted or new - items, just swapping) in this functions. - Using this option makes sorting *much* faster, but if you have a - problem, or the low level stuff changes, turn it off. [vszakats] */ -#define HB_ASORT_OPT_ITEMCOPY +/* #define HB_ASORT_OPT_ITEMCOPY - use hbsetup.h to enable/disable it*/ static BOOL hb_itemIsLess( PHB_ITEM pItem1, PHB_ITEM pItem2 ) { diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index 094a00084d..c826b134a8 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -63,10 +63,13 @@ #include "hbpp.h" #endif -/* TODO: - * include this variable in SET subsystem ? +/* .and. & .or. expressions shortcuts - the expression optimiser needs + * a global variable */ -BOOL hb_comp_bShortCuts = TRUE; /* .and. & .or. expressions shortcuts */ +BOOL hb_comp_bShortCuts = TRUE; + +/* various flags for macro compiler */ +static ULONG s_macroFlags = (HB_SM_SHORTCUTS | HB_SM_HARBOUR); static void hb_macroUseAliased( HB_ITEM_PTR, HB_ITEM_PTR, int ); static void hb_compMemvarCheck( char * szVarName, HB_MACRO_DECL ); @@ -83,10 +86,15 @@ static void hb_compMemvarCheck( char * szVarName, HB_MACRO_DECL ); */ static int hb_macroParse( HB_MACRO_PTR pMacro, char * szString ) { + /* update the current status for logical shortcuts */ + hb_comp_bShortCuts = s_macroFlags & HB_SM_SHORTCUTS; + /* initialize the input buffer - it will be scanned by lex */ pMacro->string = szString; pMacro->length = strlen( szString ); pMacro->pos = 0; + pMacro->supported = s_macroFlags; + pMacro->bShortCuts = hb_comp_bShortCuts; HB_TRACE(HB_TR_DEBUG, ("hb_macroParse(%p, %s)", pMacro, szString)); @@ -424,9 +432,20 @@ char * hb_macroTextSubst( char * szString, ULONG *pulStringLen ) * placed on the right side of the assignment or when it is used as * a parameter. * PUSH operation + * iContext contains additional info when HB_SM_XBASE is enabled + * = 0 - in Clipper strict compatibility mode + * = HB_P_MACROPUSHARG - in xbase compatibility mode + * = HB_P_MACROPUSHLIST + * = HB_P_MACROPUSHINDEX + * = HB_P_MACROPUSHPARE + * + * iContext contains HB_P_MACROPUSHPARE if a macro is used inside a codeblock + * EVAL( {|| ¯o} ) + * */ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext ) { + /* TODO: remove these externals */ extern int hb_vm_aiExtraParams[HB_MAX_MACRO_ARGS], hb_vm_iExtraParamsIndex; extern int hb_vm_aiExtraElements[HB_MAX_MACRO_ARGS], hb_vm_iExtraElementsIndex; extern int hb_vm_iExtraIndex; @@ -440,26 +459,46 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext ) HB_MACRO struMacro; int iStatus; char * szString = pItem->item.asString.value; - - #ifdef HB_MACRO_STATEMENTS - char * pText = ( char * ) hb_xgrab( HB_PP_STR_SIZE ); - char * pOut = ( char * ) hb_xgrab( HB_PP_STR_SIZE ); - char * ptr = pText; - int slen; - #endif - +#ifdef HB_MACRO_STATEMENTS + char * pText; + char * pOut; +#endif struMacro.Flags = HB_MACRO_GEN_PUSH; - struMacro.bShortCuts = hb_comp_bShortCuts; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; - struMacro.iListElements = ( iContext ? 0 : -1 ); + struMacro.iListElements = 0; - if( iContext == HB_P_MACROPUSHPARE ) + if( iContext != 0 ) { - struMacro.Flags |= HB_MACRO_GEN_PARE; + /* + * If compiled in xbase compatibility mode: + * macro := "1,2" + * funCall( ¯o ) ==> funCall( 1, 2 ) + * { ¯o } ==> { 1, 2 } + * var[ ¯o ] ==> var[ 1, 2 ] + * var := (somevalue, ¯o) ==> var := 2 + * + * Always: + * macro := "1,2" + * EVAL( {|| ¯o} ) + * + */ + struMacro.Flags |= HB_MACRO_GEN_LIST; + if( iContext == HB_P_MACROPUSHPARE ) + { + struMacro.Flags |= HB_MACRO_GEN_PARE; + } } - #ifdef HB_MACRO_STATEMENTS +#ifdef HB_MACRO_STATEMENTS + if( s_macroFlags & HB_SM_PREPROC ) + { + char * ptr; + int slen; + + pText = ( char * ) hb_xgrab( HB_PP_STR_SIZE ); + pOut = ( char * ) hb_xgrab( HB_PP_STR_SIZE ); + ptr = pText; slen = HB_MIN( strlen( szString ), HB_PP_STR_SIZE - 1 ); memcpy( pText, szString, slen ); pText[ slen ] = 0; @@ -474,7 +513,8 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext ) hb_pp_ParseExpression( ptr, pOut ); szString = pText; - #endif + } +#endif iStatus = hb_macroParse( &struMacro, szString ); @@ -483,10 +523,13 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext ) hb_macroSyntaxError( &struMacro ); } - #ifdef HB_MACRO_STATEMENTS +#ifdef HB_MACRO_STATEMENTS + if( s_macroFlags & HB_SM_PREPROC ) + { hb_xfree( pText ); hb_xfree( pOut ); - #endif + } +#endif hb_stackPop(); /* remove compiled string */ if( iStatus == HB_MACRO_OK && ( struMacro.status & HB_MACRO_CONT ) ) @@ -495,7 +538,6 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext ) if( iContext && struMacro.iListElements > 0 ) { - if( iContext == HB_P_MACROPUSHARG ) { hb_vm_aiExtraParams[hb_vm_iExtraParamsIndex] = struMacro.iListElements; @@ -532,7 +574,6 @@ void hb_macroSetValue( HB_ITEM_PTR pItem ) int iStatus; struMacro.Flags = HB_MACRO_GEN_POP; - struMacro.bShortCuts = hb_comp_bShortCuts; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; iStatus = hb_macroParse( &struMacro, szString ); @@ -602,7 +643,6 @@ static void hb_macroUseAliased( HB_ITEM_PTR pAlias, HB_ITEM_PTR pVar, int iFlag szString[ pAlias->item.asString.length + 2 + pVar->item.asString.length ] = '\0'; struMacro.Flags = iFlag; - struMacro.bShortCuts = hb_comp_bShortCuts; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; iStatus = hb_macroParse( &struMacro, szString ); @@ -629,7 +669,6 @@ static void hb_macroUseAliased( HB_ITEM_PTR pAlias, HB_ITEM_PTR pVar, int iFlag char * szString = pVar->item.asString.value; struMacro.Flags = iFlag | HB_MACRO_GEN_ALIASED; - struMacro.bShortCuts = hb_comp_bShortCuts; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; iStatus = hb_macroParse( &struMacro, szString ); @@ -676,7 +715,6 @@ HB_MACRO_PTR hb_macroCompile( char * szString ) pMacro = ( HB_MACRO_PTR ) hb_xgrab( sizeof( HB_MACRO ) ); pMacro->Flags = HB_MACRO_DEALLOCATE | HB_MACRO_GEN_PUSH; - pMacro->bShortCuts = hb_comp_bShortCuts; pMacro->uiNameLen = HB_SYMBOL_NAME_LEN; pMacro->status = HB_MACRO_CONT; iStatus = hb_macroParse( pMacro, szString ); @@ -774,7 +812,6 @@ char * hb_macroGetType( HB_ITEM_PTR pItem ) char * szString = pItem->item.asString.value; struMacro.Flags = HB_MACRO_GEN_PUSH | HB_MACRO_GEN_TYPE; - struMacro.bShortCuts = hb_comp_bShortCuts; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; iStatus = hb_macroParse( &struMacro, szString ); @@ -850,6 +887,78 @@ char * hb_macroGetType( HB_ITEM_PTR pItem ) return szType; } +/* + * Set macro capabilities if flag > 0 or get current macro capabilities + * if flag == 0 + */ +ULONG hb_macroSetMacro( BOOL bSet, ULONG flag ) +{ + ULONG ulCurrentFlags = s_macroFlags; + + if( flag > 0 ) + { + if( bSet ) + s_macroFlags |= flag; + else + s_macroFlags &= ~flag; + } + + return ulCurrentFlags; +} + +HB_FUNC( HB_SETMACRO ) +{ + int iPrmCnt = hb_pcount(); + + if( iPrmCnt > 0 ) + { + ULONG ulFlags = ( ULONG ) hb_parnl( 1 ); + PHB_ITEM pValue; + + switch( ulFlags ) + { + case HB_SM_HARBOUR: + /* enable/disable extended Harbour compatibility */ + hb_retl( s_macroFlags & ulFlags ); + pValue = hb_param( 2, HB_IT_LOGICAL ); + if( pValue ) + hb_macroSetMacro( hb_itemGetL( pValue ), ulFlags ); + break; + + case HB_SM_XBASE: + /* enable/disable extended xbase compatibility */ + hb_retl( s_macroFlags & ulFlags ); + pValue = hb_param( 2, HB_IT_LOGICAL ); + if( pValue ) + hb_macroSetMacro( hb_itemGetL( pValue ), ulFlags ); + break; + + case HB_SM_PREPROC : + /* enable/disable preprocessing before compilation */ + hb_retl( s_macroFlags & ulFlags ); + pValue = hb_param( 2, HB_IT_LOGICAL ); + if( pValue ) + hb_macroSetMacro( hb_itemGetL( pValue ), ulFlags ); + break; + + case HB_SM_SHORTCUTS: + /* enable/disable support for shortcut logical operators */ + hb_retl( s_macroFlags & ulFlags ); + pValue = hb_param( 2, HB_IT_LOGICAL ); + if( pValue ) + { + hb_macroSetMacro( hb_itemGetL( pValue ), ulFlags ); + hb_comp_bShortCuts = s_macroFlags & ulFlags; + } + break; + + default: + /* do nothing */ + } + } + else + hb_ret(); /* return NIL */ +} /* ************************************************************************* */