diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aab662d36b..f4721360a1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,10 +1,15 @@ +20000514-18:57 GMT-8 Ron Pinkas + + * source/compiler/harbour.y + ! Corrected '@' to be accepted on any var in a Function Declaration. + ! Simplified rules of Function Declaration Parameter list. + 20000514-12:20 GMT-8 Ron Pinkas * source/compiler/harbour.y + Seperated the DECLARE... from Function, moved into a Declare, and Added Declare as type of Source. ! Added reset of hb_comp_iVarScope to DECLARE... to fix wrong "Statement not allowed outside of procedure or function" - * source/compiler/hbgenerr.c * Modified : "3Duplicate Declaration of %s \'%s\'" to accept 1st parameter type of redeclaration ( Function, Class, Method ). diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 7a55e35945..b9cc26daf0 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -491,7 +491,7 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) if ( hb_comp_iWarnings < 3 ) return; - //printf( "\nAdding parameter: %s Type: %c\n", szVarName, cValueType ); + printf( "\nAdding parameter: %s Type: %c\n", szVarName, cValueType ); hb_comp_pLastMethod->iParamCount++; @@ -556,7 +556,10 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) pVar->pClass = hb_compClassFind( hb_comp_szClass ); if( ! pVar->pClass ) + { hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_CLASS_NOT_FOUND, hb_comp_szClass, szVarName ); + pVar->cType = 'O'; + } } if ( hb_comp_iVarScope & VS_PARAMETER ) @@ -804,7 +807,7 @@ PCOMCLASS hb_compClassAdd( char * szClassName ) { PCOMCLASS pClass; - //printf( "\nDeclaring Class: %s\n", szClassName ); + printf( "\nDeclaring Class: %s\n", szClassName ); if ( hb_comp_iWarnings < 3 ) return NULL; @@ -857,7 +860,7 @@ PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * szMethodName ) { PCOMMETHOD pMethod; - //printf( "\nDeclaring Method: %s of Class: %s\n", szMethodName, pClass->szName ); + printf( "\nDeclaring Method: %s of Class: %s\n", szMethodName, pClass->szName ); if ( hb_comp_iWarnings < 3 ) return NULL; @@ -912,6 +915,8 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) if ( hb_comp_iWarnings < 3 ) return NULL; + printf( "\nDeclaring Function: %s\n", szDeclaredName, NULL ); + if ( ( pDeclared = hb_compDeclaredFind( szDeclaredName ) ) != NULL ) { hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, "Function", szDeclaredName ); diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 20479e6867..1b54a06e80 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -196,7 +196,7 @@ char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */ %type NUM_INTEGER %type NUM_LONG %type FunScope AsType AsArray -%type Params ParamList DecParams DecList FormalList OptList Optional +%type Params ParamList %type IfBegin VarList ExtVarList %type FieldList %type WhileBegin @@ -244,12 +244,12 @@ Source : Crlf { hb_comp_EOL = FALSE; } | FieldsDef { hb_comp_EOL = FALSE; } | MemvarDef { hb_comp_EOL = FALSE; } | Function { hb_comp_EOL = FALSE; } - | Declare { hb_comp_EOL = FALSE; } + | Declaration { hb_comp_EOL = FALSE; } | Statement { hb_comp_EOL = FALSE; } | Line { hb_comp_EOL = FALSE; } | Source Crlf { hb_comp_EOL = FALSE; } | Source Function { hb_comp_EOL = FALSE; } - | Source Declare { hb_comp_EOL = FALSE; } + | Source Declaration { hb_comp_EOL = FALSE; } | Source Statement { hb_comp_EOL = FALSE; } | Source VarDefs { hb_comp_EOL = FALSE; } | Source FieldsDef { hb_comp_EOL = FALSE; } @@ -266,7 +266,7 @@ Function : FunScope FUNCTION IdentName { hb_comp_cVarType = ' '; hb_compFunct | FunScope PROCEDURE IdentName { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, FUN_PROCEDURE ); } Params Crlf {} ; -Declare : DECLARE_FUN IdentName { hb_compDeclaredAdd( $2 ); hb_comp_szDeclaredFun = $2; } DecParams AsType Crlf { if( hb_comp_pLastDeclared ) +Declaration: DECLARE_FUN IdentName { hb_compDeclaredAdd( $2 ); hb_comp_szDeclaredFun = $2; } DecParams AsType Crlf { if( hb_comp_pLastDeclared ) hb_comp_pLastDeclared->cType = hb_comp_cVarType; hb_comp_szDeclaredFun = NULL; hb_comp_cVarType = ' '; @@ -304,26 +304,25 @@ Params : { $$ = 0; } | '(' { hb_comp_iVarScope = VS_PARAMETER; } ParamList ')' { $$ = $3; } ; -DecParams : { $$ = 0; } - | '(' DecList ')' { $$ = $2; } +DecParams : {} + | '(' DecList ')' ; -DecList : { $$ = 0; } +DecList : {} | FormalList | FormalList OptList ; -FormalList : IdentName AsType { hb_compVariableAdd( $1, hb_comp_cVarType ); $$ = 1; } - | '@' IdentName AsType { hb_compVariableAdd( $2, hb_comp_cVarType + VT_OFFSET_BYREF ); $$ = 2; } - | FormalList ',' IdentName AsType { hb_compVariableAdd( $3, hb_comp_cVarType ); $$++; } +FormalList : IdentName AsType { hb_compVariableAdd( $1, hb_comp_cVarType ); } + | '@' IdentName AsType { hb_compVariableAdd( $2, hb_comp_cVarType + VT_OFFSET_BYREF ); } + | FormalList ',' IdentName AsType { hb_compVariableAdd( $3, hb_comp_cVarType ); } + | FormalList ',' '@' IdentName AsType { hb_compVariableAdd( $4, hb_comp_cVarType ); } ; -OptList : Optional - | OptList Optional - ; - -Optional : ',' OPTIONAL IdentName AsType { hb_compVariableAdd( $3, hb_comp_cVarType + VT_OFFSET_OPTIONAL ); $$ = 3; } - | ',' OPTIONAL '@' IdentName AsType { hb_compVariableAdd( $4, hb_comp_cVarType + VT_OFFSET_OPTIONAL + VT_OFFSET_BYREF ); $$ = 4; } +OptList : ',' OPTIONAL IdentName AsType { hb_compVariableAdd( $3, hb_comp_cVarType + VT_OFFSET_OPTIONAL ); } + | ',' OPTIONAL '@' IdentName AsType { hb_compVariableAdd( $4, hb_comp_cVarType + VT_OFFSET_OPTIONAL + VT_OFFSET_BYREF ); } + | OptList ',' OPTIONAL IdentName AsType { hb_compVariableAdd( $4, hb_comp_cVarType + VT_OFFSET_OPTIONAL ); } + | OptList ',' OPTIONAL '@' IdentName AsType { hb_compVariableAdd( $5, hb_comp_cVarType + VT_OFFSET_OPTIONAL + VT_OFFSET_BYREF ); } ; AsType : /* not specified */ { hb_comp_cVarType = ' '; } diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 68ea39466c..21d082491f 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -49,26 +49,28 @@ #COMMAND DECLARE FUNCTION <*x*> => #endif -DECLARE FUNCTION nMyFunc( cVar AS STRING, nVar AS NUMERIC ) AS NUMERIC +//DECLARE Function nMyFunc AS NUMERIC -DECLARE FUNCTION cOtherFunc( @cVar as char, optional nVar as num, optional other as variant ) AS CHAR +DECLARE Function nMyFunc( cVar AS STRING, @nVar AS NUMERIC ) AS NUMERIC -DECLARE FUNCTION cOtherFunc( ) AS CHAR +DECLARE Function cOtherFunc( @cVar as char, optional nVar as num, optional other as variant ) AS CHAR -DECLARE FUNCTION seconds() AS NUM +DECLARE Function cOtherFunc( ) AS CHAR -DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC +DECLARE Function seconds() AS NUM -DECLARE FUNCTION TEST AS NUMERIC +DECLARE Function int( n AS NUMERIC ) AS NUMERIC -DECLARE CLASS MyClass ; - Has METHOD nMyFunc( nVal As Num ) As Num ; - Has METHOD nMyFunc( nVal As Num ) As Num ; - Has Data cMyData ; - Has Method FinalMethod +DECLARE Function TEST AS NUMERIC -DECLARE CLASS MyClass ; - Has METHOD nMyFunc( nVal As Num ) As Num +DECLARE Class MyClass ; + Has Method nMyFunc( nVal As Num ) As Num ; + Has Method nMyFunc( nVal As Num ) As Num ; + Has Data cMyData ; + Has Method FinalMethod + +DECLARE Class MyClass ; + Has Method nMyFunc( nVal As Num ) As Num FIELD a AS CHAR FIELD b AS CHAR