From cd9e54dc06bcb8b3a54c18c1ef6b95f6f1b4785d Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Sun, 14 May 2000 19:22:22 +0000 Subject: [PATCH] 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 ). * source/compiler/harbour.c * Modified calls to hb_compGenWarning() to use additional parameter of redclaration type. --- harbour/ChangeLog | 13 +++++++++++++ harbour/source/compiler/harbour.c | 6 +++--- harbour/source/compiler/harbour.y | 18 ++++++++++++------ harbour/source/compiler/hbgenerr.c | 2 +- harbour/tests/testwarn.prg | 9 ++++++--- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aad96249df..aab662d36b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,16 @@ +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 ). + + * source/compiler/harbour.c + * Modified calls to hb_compGenWarning() to use additional parameter of redclaration type. + 20000514-10:07 GMT-8 Ron Pinkas * source/compiler/harbour.l diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index fe66697ca2..7a55e35945 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -811,7 +811,7 @@ PCOMCLASS hb_compClassAdd( char * szClassName ) if ( ( pClass = hb_compClassFind( szClassName ) ) != NULL ) { - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, szClassName, NULL ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, "Class", szClassName ); return pClass; } @@ -864,7 +864,7 @@ PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * szMethodName ) if ( ( pMethod = hb_compMethodFind( pClass, szMethodName ) ) != NULL ) { - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, szMethodName, NULL ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, "Method", szMethodName ); return pMethod; } @@ -914,7 +914,7 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) if ( ( pDeclared = hb_compDeclaredFind( szDeclaredName ) ) != NULL ) { - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, szDeclaredName, NULL ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, "Function", szDeclaredName ); return pDeclared; } diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index df4421fb9c..20479e6867 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -244,10 +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; } | 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 Statement { hb_comp_EOL = FALSE; } | Source VarDefs { hb_comp_EOL = FALSE; } | Source FieldsDef { hb_comp_EOL = FALSE; } @@ -262,12 +264,16 @@ Line : LINE NUM_INTEGER LITERAL Crlf Function : FunScope FUNCTION IdentName { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, 0 ); } Params Crlf {} | FunScope PROCEDURE IdentName { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, FUN_PROCEDURE ); } Params Crlf {} - | DECLARE_FUN IdentName { hb_compDeclaredAdd( $2 ); hb_comp_szDeclaredFun = $2; } DecParams AsType Crlf { if( hb_comp_pLastDeclared ) + ; + +Declare : 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 = ' '; } - | DECLARE_CLASS IdentName { hb_comp_pLastClass = hb_compClassAdd( $2 ); } ClassInfo Crlf {} - ; + hb_comp_cVarType = ' '; + hb_comp_iVarScope = VS_NONE; + } + | DECLARE_CLASS IdentName { hb_comp_pLastClass = hb_compClassAdd( $2 ); } ClassInfo Crlf { hb_comp_iVarScope = VS_NONE; } + ; ClassInfo : DecMethod | ClassInfo DecMethod @@ -1165,7 +1171,7 @@ DimIndex : '[' Expression { $$ = hb_compExprNewArgList( $2 ); } ; -FieldsDef : FIELD { hb_comp_iVarScope = VS_FIELD; } FieldList Crlf +FieldsDef : FIELD { hb_comp_iVarScope = VS_FIELD; } FieldList Crlf { hb_comp_cVarType = ' '; } ; FieldList : IdentName AsType { $$=hb_compFieldsCount(); hb_compVariableAdd( $1, hb_comp_cVarType ); } @@ -1173,7 +1179,7 @@ FieldList : IdentName AsType { $$=hb_compFieldsCount(); hb_compVa | FieldList IN IdentName { hb_compFieldSetAlias( $3, $1 ); } ; -MemvarDef : MEMVAR { hb_comp_iVarScope = VS_MEMVAR; } MemvarList Crlf +MemvarDef : MEMVAR { hb_comp_iVarScope = VS_MEMVAR; } MemvarList Crlf { hb_comp_cVarType = ' '; } ; MemvarList : IdentName AsType { hb_compVariableAdd( $1, hb_comp_cVarType ); } diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index cc7ed839e5..119e5964d0 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -107,7 +107,7 @@ char * hb_comp_szWarnings[] = "3Incompatible return type: \'%s\' expected: \'%s\'", "3Invalid number of parameters: %s expected: %s", "3Incompatible parameter # %s expected: \'%s\'", - "3Duplicate Declaration of Function %s", + "3Duplicate Declaration of %s \'%s\'", "3Function \'%s\' conflicting with its declaration", "3Variable \'%s\' used but never initialized", "3Value of Variable \'%s\' never used", diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 33a2ca6b26..68ea39466c 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -67,6 +67,9 @@ DECLARE CLASS MyClass ; 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 @@ -89,9 +92,9 @@ PROCEDURE THEMAIN( optional ) PRIVATE TEST AS CHAR - DO Proc WITH - - DO Optional WITH + DO Optional WITH Var1 + DO Optional WITH 1 + DO Optional WITH "something" FOR Conter := Optional TO 10 ? "For with End"