diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0186a48d4b..298e3a8396 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,7 +1,17 @@ +20000519-10:17 GMT-8 Ron Pinkas + + * source/compiler/harbour.y + * source/compiler/harbour.c + * source/compiler/hbpcode.c + + Added support for AS Array Of Objects FROM CLASS ClassName syntax and type checking. + + * tests/testwarn.prg + + Added code to demonstrate syntax and warnings for AS Array Of Objects FROM CLASS ClassName syntax and type checking. + 20000519-02:05 GMT-8 Ron Pinkas * include/hbcomp.h - ! Consoldated COMDECLARED and COMMETHOD into COMDECLARED + ! Consolidated COMDECLARED and COMMETHOD into COMDECLARED + Added member pClass to COMDECLARED + Added member pLast to COMCLASS diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index ad0d442adc..84336edfff 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -550,7 +550,7 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) pVar->pNext = NULL; pVar->iDeclLine = hb_comp_iLine; - if ( cValueType == '+' ) + if ( toupper( cValueType ) == 'S' ) { /*printf( "\nVariable %s is of Class: %s\n", szVarName, hb_comp_szClass );*/ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index c0b079a94c..69540049fa 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -277,23 +277,24 @@ Params : { $$ = 0; } | '(' { hb_comp_iVarScope = VS_PARAMETER; } ParamList ')' { $$ = $3; } ; -AsType : /* not specified */ { hb_comp_cVarType = ' '; } - | AS_NUMERIC { hb_comp_cVarType = 'N'; } - | AS_CHARACTER { hb_comp_cVarType = 'C'; } - | AS_DATE { hb_comp_cVarType = 'D'; } - | AS_LOGICAL { hb_comp_cVarType = 'L'; } - | AS_ARRAY { hb_comp_cVarType = 'A'; } - | AS_BLOCK { hb_comp_cVarType = 'B'; } - | AS_OBJECT { hb_comp_cVarType = 'O'; } - | AS_OBJECT FROMCLASS IdentName { hb_comp_cVarType = '+'; hb_comp_szClass = $3 } - | AS_VARIANT { hb_comp_cVarType = ' '; } - | AS_NUMERIC_ARRAY { hb_comp_cVarType = 'n'; } - | AS_CHARACTER_ARRAY { hb_comp_cVarType = 'c'; } - | AS_DATE_ARRAY { hb_comp_cVarType = 'd'; } - | AS_LOGICAL_ARRAY { hb_comp_cVarType = 'l'; } - | AS_ARRAY_ARRAY { hb_comp_cVarType = 'a'; } - | AS_BLOCK_ARRAY { hb_comp_cVarType = 'b'; } - | AS_OBJECT_ARRAY { hb_comp_cVarType = 'o'; } +AsType : /* not specified */ { hb_comp_cVarType = ' '; } + | AS_NUMERIC { hb_comp_cVarType = 'N'; } + | AS_CHARACTER { hb_comp_cVarType = 'C'; } + | AS_DATE { hb_comp_cVarType = 'D'; } + | AS_LOGICAL { hb_comp_cVarType = 'L'; } + | AS_ARRAY { hb_comp_cVarType = 'A'; } + | AS_BLOCK { hb_comp_cVarType = 'B'; } + | AS_OBJECT { hb_comp_cVarType = 'O'; } + | AS_OBJECT FROMCLASS IdentName { hb_comp_cVarType = 'S'; hb_comp_szClass = $3 } + | AS_VARIANT { hb_comp_cVarType = ' '; } + | AS_NUMERIC_ARRAY { hb_comp_cVarType = 'n'; } + | AS_CHARACTER_ARRAY { hb_comp_cVarType = 'c'; } + | AS_DATE_ARRAY { hb_comp_cVarType = 'd'; } + | AS_LOGICAL_ARRAY { hb_comp_cVarType = 'l'; } + | AS_ARRAY_ARRAY { hb_comp_cVarType = 'a'; } + | AS_BLOCK_ARRAY { hb_comp_cVarType = 'b'; } + | AS_OBJECT_ARRAY { hb_comp_cVarType = 'o'; } + | AS_OBJECT_ARRAY FROMCLASS IdentName { hb_comp_cVarType = 's'; hb_comp_szClass = $3 } ; AsArray : AS_ARRAY { hb_comp_cVarType = 'A'; } @@ -1155,13 +1156,13 @@ ClassInfo : DecMethod DecMethod : IdentName '(' { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $1 ); } DecList ')' AsType { if ( hb_comp_pLastMethod ) { hb_comp_pLastMethod->cType = hb_comp_cVarType; - if ( hb_comp_cVarType == '+' ) + if ( toupper( hb_comp_cVarType ) == 'S' ) { hb_comp_pLastMethod->pClass = hb_compClassFind( hb_comp_szClass ); if( ! hb_comp_pLastMethod->pClass ) { hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_CLASS_NOT_FOUND, hb_comp_szClass, hb_comp_pLastMethod->szName ); - hb_comp_pLastMethod->cType = 'O'; + hb_comp_pLastMethod->cType = ( isupper( hb_comp_cVarType ) ? 'O' :'o' ); } } } @@ -1173,13 +1174,13 @@ DecMethod : IdentName '(' { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLa DecData : IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $1 ); } AsType { if ( hb_comp_pLastMethod ) { hb_comp_pLastMethod->cType = hb_comp_cVarType; - if ( hb_comp_cVarType == '+' ) + if ( toupper( hb_comp_cVarType ) == 'S' ) { hb_comp_pLastMethod->pClass = hb_compClassFind( hb_comp_szClass ); if( ! hb_comp_pLastMethod->pClass ) { hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_CLASS_NOT_FOUND, hb_comp_szClass, hb_comp_pLastMethod->szName ); - hb_comp_pLastMethod->cType = 'O'; + hb_comp_pLastMethod->cType = ( isupper( hb_comp_cVarType ) ? 'O' :'o' ); } } } diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index 1447038f80..74d0438d4a 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -394,7 +394,7 @@ void hb_compStrongType( int iSize ) { /* The Object is not declared. */ } - else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == '+' ) + else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == 'S' ) { pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); @@ -437,7 +437,7 @@ void hb_compStrongType( int iSize ) if ( pFunc->iStackIndex < ( wVar + 1 ) ) break; - if ( pFunc->pStack[ pFunc->iStackIndex - ( wVar + 1 ) ] == '+' ) + if ( pFunc->pStack[ pFunc->iStackIndex - ( wVar + 1 ) ] == 'S' ) { if ( pFunc->iStackFunctions > 0 && pFunc->pStackFunctions[ --pFunc->iStackFunctions ] ) { @@ -509,13 +509,13 @@ void hb_compStrongType( int iSize ) /* Removing all the parameters.*/ pFunc->iStackIndex -= wVar; - if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == '+' && pFunc->pStackFunctions[ pFunc->iStackFunctions ] ) + if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == 'S' && pFunc->pStackFunctions[ pFunc->iStackFunctions ] ) { pFunc->pStack[ pFunc->iStackIndex - 1 ] = pFunc->pStackFunctions[ pFunc->iStackFunctions ]->cType; /*printf( "\nDeclared Method!!! Stack: %i Type: %c\n", pFunc->iStackIndex, pFunc->pStack[ pFunc->iStackIndex - 1 ] );*/ - if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == '+' && pFunc->iStackClasses < 8 ) + if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == 'S' && pFunc->iStackClasses < 8 ) { /*printf( "\nNested CLASS!!! Stack: %i Type: %c Class Pointer: %i\n", pFunc->iStackIndex, pFunc->pStack[ pFunc->iStackIndex - 1 ], pFunc->pStackFunctions[ pFunc->iStackFunctions ]->pClass );*/ pFunc->pStackClasses[ pFunc->iStackClasses++ ] = pFunc->pStackFunctions[ pFunc->iStackFunctions ]->pClass; @@ -1143,11 +1143,11 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - if ( pVar->cType == '+' && pFunc->iStackClasses < 8 ) + if ( pVar->cType == 'S' && pFunc->iStackClasses < 8 ) { /* Object of declared class */ pFunc->pStackClasses[ pFunc->iStackClasses++ ] = pVar->pClass; - pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + pFunc->pStack[ pFunc->iStackIndex++ ] = 'S'; } else if ( pFunc->pCode[ ulPos ] == HB_P_PUSHLOCALREF ) pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType + VT_OFFSET_BYREF; @@ -1187,11 +1187,11 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - if ( pVar->cType == '+' && pFunc->iStackClasses < 8 ) + if ( pVar->cType == 'S' && pFunc->iStackClasses < 8 ) { /* Object of declared class */ pFunc->pStackClasses[ pFunc->iStackClasses++ ] = pVar->pClass; - pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + pFunc->pStack[ pFunc->iStackIndex++ ] = 'S'; } if ( pFunc->pCode[ ulPos ] == HB_P_PUSHSTATICREF ) pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType + VT_OFFSET_BYREF; @@ -1275,11 +1275,11 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - if ( pVar->cType == '+' && pFunc->iStackClasses < 8 ) + if ( pVar->cType == 'S' && pFunc->iStackClasses < 8 ) { /* Object of declared class */ pFunc->pStackClasses[ pFunc->iStackClasses++ ] = pVar->pClass; - pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + pFunc->pStack[ pFunc->iStackIndex++ ] = 'S'; } else if ( pFunc->pCode[ ulPos ] == HB_P_PUSHMEMVARREF ) pFunc->pStack[ pFunc->iStackIndex - 1 ] = pVar->cType + VT_OFFSET_BYREF; @@ -1476,7 +1476,7 @@ void hb_compStrongType( int iSize ) case HB_P_POPVARIABLE : pFunc->iStackIndex--; - if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' && pFunc->iStackClasses > 0 ) + if ( pFunc->pStack[ pFunc->iStackIndex ] == 'S' && pFunc->iStackClasses > 0 ) { /* Object of declared class */ pFunc->pStackClasses[ --pFunc->iStackClasses ] = NULL; @@ -1488,7 +1488,7 @@ void hb_compStrongType( int iSize ) /* TODO: check what is aliasedvar? */ pFunc->iStackIndex--; - if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' && pFunc->iStackClasses > 0 ) + if ( pFunc->pStack[ pFunc->iStackIndex ] == 'S' && pFunc->iStackClasses > 0 ) { /* Object of declared class */ pFunc->pStackClasses[ --pFunc->iStackClasses ] = NULL; @@ -1538,7 +1538,7 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' && pFunc->iStackClasses > 0 ) + if ( pFunc->pStack[ pFunc->iStackIndex ] == 'S' && pFunc->iStackClasses > 0 ) { /* Object of declared class */ pFunc->pStackClasses[ --pFunc->iStackClasses ] = NULL; @@ -1678,7 +1678,7 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' && pFunc->iStackClasses > 0 ) + if ( pFunc->pStack[ pFunc->iStackIndex ] == 'S' && pFunc->iStackClasses > 0 ) { /* Object of declared class */ pFunc->pStackClasses[ --pFunc->iStackClasses ] = NULL; @@ -1752,7 +1752,7 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' && pFunc->iStackClasses > 0 ) + if ( pFunc->pStack[ pFunc->iStackIndex ] == 'S' && pFunc->iStackClasses > 0 ) { /* Object of declared class */ pFunc->pStackClasses[ --pFunc->iStackClasses ] = NULL;