20000514-22:25 GMT-8 Ron Pinkas <Ron@Profit-Master.com>

* source/compiler/harbour.l
    - Removed: not needed states
    - Removed "class method" "class data"
    + Added rules for "declare""

  * source/compiler/harbour.y
    * Changed rules for DECLARE FUNCTION as per Ryszard suhhestion, New Sysntax is simply:
        DECLARE FunName([...]) [As ...]
    * Changed rules for DECLARE CLASS as per Ryszard suhhestion, New Sysntax is simply:
        DECLARE ClassName MethodName([...]) [As ...] DataVar [As ...]

  * source/compiler/harbour.c
    ! Minor correction to allow final declaration to override previous declaration of same function.

  * tests/testwarn.prg
    * Modified code to demonstrate syntax functions, classes and objects of a declared class declarations.
This commit is contained in:
Ron Pinkas
2000-05-15 05:35:04 +00:00
parent 7733005732
commit 4eb57576a2
5 changed files with 115 additions and 90 deletions

View File

@@ -1,3 +1,22 @@
20000514-22:25 GMT-8 Ron Pinkas <Ron@Profit-Master.com>
* source/compiler/harbour.l
- Removed: not needed states
- Removed "class method" "class data"
+ Added rules for "declare""
* source/compiler/harbour.y
* Changed rules for DECLARE FUNCTION as per Ryszard suhhestion, New Sysntax is simply:
DECLARE FunName([...]) [As ...]
* Changed rules for DECLARE CLASS as per Ryszard suhhestion, New Sysntax is simply:
DECLARE ClassName MethodName([...]) [As ...] DataVar [As ...]
* source/compiler/harbour.c
! Minor correction to allow final declaration to override previous declaration of same function.
* tests/testwarn.prg
* Modified code to demonstrate syntax functions, classes and objects of a declared class declarations.
20000514-19:17 GMT-8 Ron Pinkas <Ron@Profit-Master.com>
* source/compiler/harbour.y

View File

@@ -920,6 +920,12 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName )
if ( ( pDeclared = hb_compDeclaredFind( szDeclaredName ) ) != NULL )
{
hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, "Function", szDeclaredName );
/* Last declaration will take effect. */
pDeclared->cType = ' '; /* Not known yet */
pDeclared->cParamTypes = NULL;
pDeclared->iParamCount = 0;
return pDeclared;
}

View File

@@ -113,7 +113,6 @@ Separator {SpaceTab}
%x FOR_ FUNCTION_ IIF_ IF_ IN_ INIT_ LOCAL_ LOOP_
%x MEMVAR_ PARAM_ PRIVATE_ PUBLIC_ STATIC_ RETURN_ RECOVER_
%x INVALIDNUM_ OTHERWISE_ PROCEDURE_
%x OPTIONAL_
%s INDEX
%%
@@ -351,16 +350,32 @@ Separator {SpaceTab}
%{
/* ************************************************************************ */
%}
"decl"("are"|"ar"|"a")? { BEGIN PRIVATE_;
yylval.string = hb_strupr( hb_strdup( yytext ) );
}
%{
/* ************************************************************************ */
%}
<INITIAL>"optional" { BEGIN OPTIONAL_; }
<INITIAL>"declare"{Separator}+"with"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
unput( ' ' );
unput( 'h' );
unput( 't' );
unput( 'i' );
unput( 'w' );
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
yylval.string = hb_strdup( "declare" );
hb_comp_iState = IDENTIFIER;
return IDENTIFIER;
}
<OPTIONAL_>{Separator}+"with"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
<INITIAL>"declare"{Separator}+"to"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
unput( ' ' );
unput( 'o' );
unput( 't' );
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
yylval.string = hb_strdup( "declare" );
hb_comp_iState = IDENTIFIER;
return IDENTIFIER;
}
<INITIAL>"declare"{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return DECLARE; }
<INITIAL>"optional"{Separator}+"with"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
unput( ' ' );
unput( 'h' );
unput( 't' );
@@ -372,7 +387,7 @@ Separator {SpaceTab}
return IDENTIFIER;
}
<OPTIONAL_>{Separator}+"to"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
<INITIAL>"optional"{Separator}+"to"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] );
unput( ' ' );
unput( 'o' );
unput( 't' );
@@ -382,15 +397,7 @@ Separator {SpaceTab}
return IDENTIFIER;
}
<OPTIONAL_>{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return OPTIONAL; }
<OPTIONAL_>{Separator}*(.|\n) { /* end of line or any operator */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
unput( yytext[ yyleng-1 ] );
yylval.string = hb_strdup( "OPTIONAL" );
hb_comp_iState = IDENTIFIER;
return IDENTIFIER;
}
<INITIAL>"optional"{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return OPTIONAL; }
"do" BEGIN DO_;
<DO_>{Separator}+"case" { /* DO CASE statement */
@@ -1363,12 +1370,7 @@ Separator {SpaceTab}
"as array of numeric" { return AS_NUMERIC_ARRAY; }
"as array of object" { return AS_OBJECT_ARRAY; }
"declare function" { return DECLARE_FUN; }
"declare class" { return DECLARE_CLASS; }
"has method" { return CLASS_METHOD; }
"has data" { return CLASS_DATA; }
"from class" { return FROMCLASS; }
"from class" { return FROMCLASS; }
%{
/* ************************************************************************ */

View File

@@ -161,9 +161,9 @@ char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */
%token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ EXITLOOP
%token PRIVATE BEGINSEQ BREAK RECOVER RECOVERUSING DO WITH SELF LINE
%token MACROVAR MACROTEXT
%token AS_ARRAY AS_BLOCK AS_CHARACTER AS_DATE AS_LOGICAL AS_NUMERIC AS_OBJECT AS_VARIANT DECLARE_FUN OPTIONAL
%token AS_ARRAY AS_BLOCK AS_CHARACTER AS_DATE AS_LOGICAL AS_NUMERIC AS_OBJECT AS_VARIANT DECLARE OPTIONAL
%token AS_ARRAY_ARRAY AS_BLOCK_ARRAY AS_CHARACTER_ARRAY AS_DATE_ARRAY AS_LOGICAL_ARRAY AS_NUMERIC_ARRAY AS_OBJECT_ARRAY
%token DECLARE_CLASS CLASS_METHOD CLASS_DATA FROMCLASS
%token FROMCLASS
/*the lowest precedence*/
/*postincrement and postdecrement*/
@@ -243,17 +243,17 @@ Source : Crlf { hb_comp_EOL = FALSE; }
| VarDefs { hb_comp_EOL = FALSE; }
| FieldsDef { hb_comp_EOL = FALSE; }
| MemvarDef { hb_comp_EOL = FALSE; }
| Function { hb_comp_EOL = FALSE; }
| Declaration { hb_comp_EOL = FALSE; }
| Function { 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 Declaration { hb_comp_EOL = FALSE; }
| Source Statement { hb_comp_EOL = FALSE; }
| Source VarDefs { hb_comp_EOL = FALSE; }
| Source FieldsDef { hb_comp_EOL = FALSE; }
| Source MemvarDef { hb_comp_EOL = FALSE; }
| Source Declaration { hb_comp_EOL = FALSE; }
| Source Line { hb_comp_EOL = FALSE; }
| Source error Crlf { hb_comp_EOL = FALSE; yyclearin; }
;
@@ -266,33 +266,6 @@ 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 {}
;
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 = ' ';
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
| DecData
| ClassInfo DecData
;
DecMethod : CLASS_METHOD IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $2 ); } DecParams AsType { if ( hb_comp_pLastMethod )
hb_comp_pLastMethod->cType = hb_comp_cVarType;
hb_comp_pLastMethod = NULL;
hb_comp_cVarType = ' '; }
;
DecData : CLASS_DATA IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $2 ); } AsType { if ( hb_comp_pLastMethod )
hb_comp_pLastMethod->cType = hb_comp_cVarType;
hb_comp_pLastMethod = NULL;
hb_comp_cVarType = ' '; }
;
FunScope : { $$ = HB_FS_PUBLIC; }
| STATIC { $$ = HB_FS_STATIC; }
| INIT { $$ = HB_FS_INIT; }
@@ -304,27 +277,6 @@ Params : { $$ = 0; }
| '(' { hb_comp_iVarScope = VS_PARAMETER; } ParamList ')' { $$ = $3; }
;
DecParams : {}
| '(' DecList ')'
;
DecList : {}
| FormalList
| FormalList OptList
;
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 + VT_OFFSET_BYREF ); }
;
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 = ' '; }
| AS_NUMERIC { hb_comp_cVarType = 'N'; }
| AS_CHARACTER { hb_comp_cVarType = 'C'; }
@@ -1185,6 +1137,52 @@ MemvarList : IdentName AsType { hb_compVariableAdd( $1, hb_c
| MemvarList ',' IdentName AsType { hb_compVariableAdd( $3, hb_comp_cVarType ); }
;
Declaration: DECLARE IdentName '(' { hb_compDeclaredAdd( $2 ); hb_comp_szDeclaredFun = $2; } DecList ')' AsType Crlf { if( hb_comp_pLastDeclared )
hb_comp_pLastDeclared->cType = hb_comp_cVarType;
hb_comp_szDeclaredFun = NULL;
hb_comp_cVarType = ' ';
hb_comp_iVarScope = VS_NONE;
}
| DECLARE IdentName { hb_comp_pLastClass = hb_compClassAdd( $2 ); } ClassInfo Crlf { hb_comp_iVarScope = VS_NONE; }
;
ClassInfo : DecMethod
| ClassInfo DecMethod
| DecData
| ClassInfo DecData
;
DecMethod : IdentName '(' { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $1 ); } DecList ')' AsType { if ( hb_comp_pLastMethod )
hb_comp_pLastMethod->cType = hb_comp_cVarType;
hb_comp_pLastMethod = NULL;
hb_comp_cVarType = ' ';
}
;
DecData : IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $1 ); } AsType { if ( hb_comp_pLastMethod )
hb_comp_pLastMethod->cType = hb_comp_cVarType;
hb_comp_pLastMethod = NULL;
hb_comp_cVarType = ' ';
}
;
DecList : {}
| FormalList
| FormalList OptList
;
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 + VT_OFFSET_BYREF ); }
;
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 ); }
;
ExecFlow : IfEndif
| DoCase
| DoWhile

View File

@@ -51,26 +51,26 @@
//DECLARE Function nMyFunc AS NUMERIC
DECLARE Function nMyFunc( cVar AS STRING, @nVar AS NUMERIC ) AS NUMERIC
DECLARE nMyFunc( cVar AS STRING, @nVar AS NUMERIC ) AS NUMERIC
DECLARE Function cOtherFunc( @cVar as char, optional nVar as num, optional other as variant ) AS CHAR
DECLARE cOtherFunc( @cVar as char, optional nVar as num, optional other as variant ) AS CHAR
DECLARE Function cOtherFunc( ) AS CHAR
DECLARE cOtherFunc( ) AS CHAR
DECLARE Function seconds() AS NUM
DECLARE seconds() AS NUM
DECLARE Function int( n AS NUMERIC ) AS NUMERIC
DECLARE int( n AS NUMERIC ) AS NUMERIC
DECLARE Function TEST AS NUMERIC
DECLARE TEST() 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 MyClass ;
nMyFunc( nVal As Num ) As Num ;
nMyFunc( nVal As Num ) As Num ;
cMyData ;
FinalMethod
DECLARE Class MyClass ;
Has Method nMyFunc( nVal As Num ) As Num
DECLARE MyClass ;
nMyFunc( nVal As Num ) As Num
FIELD a AS CHAR
FIELD b AS CHAR