Files
harbour-core/harbour/source/compiler/genjava.c
Ryszard Glab 912b301c85 2006-07-14 16:00 UTC+0100 Ryszard Glab <rglab//imid.med.pl>
* include/hbcomp.h
   * include/hberrors.h
   * include/hbexpra.c
   * include/hbexprb.c
   * include/hbexprc.c
   * include/hbmacro.h
   * include/hbpcode.h
   * include/hbpp.h
   * include/hbxvm.h
   * source/common/expropt1.c
   * source/compiler/cmdcheck.c
   * source/compiler/expropta.c
   * source/compiler/exproptb.c
   * source/compiler/exproptc.c
   * source/compiler/genc.c
   * source/compiler/gencc.c
   * source/compiler/gencli.c
   * source/compiler/genhrb.c
   * source/compiler/genjava.c
   * source/compiler/genobj32.c
   * source/compiler/harbour.c
   * source/compiler/harbour.l
   * source/compiler/harbour.y
   * source/compiler/hbdead.c
   * source/compiler/hbfix.c
   * source/compiler/hbfunchk.c
   * source/compiler/hbgenerr.c
   * source/compiler/hblbl.c
   * source/compiler/hbpcode.c
   * source/compiler/hbstripl.c
   * source/macro/macroa.c
   * source/macro/macrob.c
   * source/macro/macroc.c
   * source/vm/hvm.c
   * source/vm/macro.c
      * fixed compilation of code that uses '@' pass by
       reference. The following syntax is no longer supported:
       var := IIF( .T., @var, var )
       however you can still use the following:
       funcall( IIF( bPassbyRef, @someVar, someVar ) )
      +added support for the following statement:
         WITH OBJECT <objexpression>
            ...
         END
       inside this statement you can use simplified form of sending
       messages to the object specified by <objexpression>
         :message( )    instead objexpression:message()
         :property      instead objexpression:property
       The runtime error will be generated at the time of message
       sending (or property access/assign) if <objexpression>
       is not a value of type object.
       You can use the reserved property:
         :__withobject
       to access/assign the controlling object.
      *fixed support for command line response file (@file.clp)
       to be compatible with Clipper (Clipper genertes a single
       obj file)
      *fixed memory leaks when there is a fatal error in autoopened
       module (using DO ... statement)
      *implicit startup functions are removed from the list of
       functions before generation of output code

   * source/pp/ppcomp.c
   * source/pp/pplib.c
   * source/pp/ppcore.c
      * redefinition of #define no longer causes a memory leak
      * fixed repeatable optional clauses
         #xcommand SET <var1> [, <varN>] WITH <val> =>
          <var1>:=<val>[; <varN>:=<val>]
      * fixed compilation of optional clauses (when used in different
        order then declared) -this fixes the following long
        waiting bug:
         #command MYCOMMAND [<mylist,...>] [MYCLAUSE <myval>] => ;
            MyFunction( {<mylist>} [, <myval>] )
         MYCOMMAND MYCLAUSE 321 "HELLO"
      * fixed restricted macro match marker <x:&>

   * tests/Makefile
   - tests/pretest.prg
   + utils/hbpptest
   + utils/hbpptest/Makefile
   + utils/hbpptest/pretest.prg
      * moved file 'pretest.prg' from tests to separate directory
        to make easier validation of the preprocessor

   * TODO
      * added note to fix hb_objGetMethod() so it will not generate
        error if there is no method

   * doc/en/clipper.txt
      * added documentation for WITH OBJECT usage
2006-07-14 13:47:17 +00:00

182 lines
5.0 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* Compiler Java source generation
*
* Copyright 1999 Matteo Baccan <baccan@isanet.it>
* Based on a work of Eddie Runia <eddie@runia.com>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
#include "hbcomp.h"
#define SYM_NOLINK 0 /* Symbol does not have to be linked */
#define SYM_FUNC 1 /* Defined function */
#define SYM_EXTERN 2 /* Previously defined function */
static void hb_fputc( BYTE b );
static void hb_fputs( char * szName );
static FILE * s_yyc;
static int s_nChar = 0;
void hb_compGenJava( PHB_FNAME pFileName )
{
char szFileName[ _POSIX_PATH_MAX ];
PFUNCTION pFunc /*= hb_comp_functions.pFirst */;
PCOMSYMBOL pSym = hb_comp_symbols.pFirst;
ULONG lPCodePos;
LONG lSymbols;
ULONG ulCodeLength;
if( ! pFileName->szExtension )
pFileName->szExtension = ".java";
hb_fsFNameMerge( szFileName, pFileName );
s_yyc = fopen( szFileName, "wb" );
if( ! s_yyc )
{
hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL );
return;
}
if( ! hb_comp_bQuiet )
{
printf( "Generating Java source output to \'%s\'... ", szFileName );
fflush( stdout );
}
s_nChar = 0;
fprintf( s_yyc, "/*\n * Harbour Compiler, Alpha build %d.%d (%s)\n",
HB_VER_MINOR, HB_VER_REVISION, HB_VER_LEX );
fprintf( s_yyc, " * Generated JAVA source code\n */\n\n" );
fprintf( s_yyc, "public class %s\n", pFileName->szName );
fprintf( s_yyc, "{\n" );
fprintf( s_yyc, " public static int[] pCode =\n" );
fprintf( s_yyc, " {\n" );
fprintf( s_yyc, " " );
/* writes the symbol table */
lSymbols = 0; /* Count number of symbols */
while( pSym )
{
lSymbols++;
pSym = pSym->pNext;
}
hb_fputc( ( BYTE ) ( ( lSymbols ) & 255 ) ); /* Write number symbols */
hb_fputc( ( BYTE ) ( ( lSymbols >> 8 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( lSymbols >> 16 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( lSymbols >> 24 ) & 255 ) );
pSym = hb_comp_symbols.pFirst;
while( pSym )
{
hb_fputs( pSym->szName );
hb_fputc( 0 );
hb_fputc( pSym->cScope );
/* specify the function address if it is a defined function or a
external called function */
if( hb_compFunctionFind( pSym->szName ) ) /* is it a defined function ? */
hb_fputc( SYM_FUNC );
else
{
if( hb_compFunCallFind( pSym->szName ) )
hb_fputc( SYM_EXTERN );
else
hb_fputc( SYM_NOLINK );
}
pSym = pSym->pNext;
}
pFunc = hb_comp_functions.pFirst;
lSymbols = 0; /* Count number of symbols */
while( pFunc )
{
lSymbols++;
pFunc = pFunc->pNext;
}
hb_fputc( ( BYTE ) ( ( lSymbols ) & 255 ) ); /* Write number symbols */
hb_fputc( ( BYTE ) ( ( lSymbols >> 8 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( lSymbols >> 16 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( lSymbols >> 24 ) & 255 ) );
/* Generate functions data
*/
pFunc = hb_comp_functions.pFirst;
while( pFunc )
{
hb_fputs( pFunc->szName );
hb_fputc( 0 );
ulCodeLength = pFunc->lPCodePos;
hb_fputc( ( BYTE ) ( ( ulCodeLength ) & 255 ) ); /* Write size */
hb_fputc( ( BYTE ) ( ( ulCodeLength >> 8 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( ulCodeLength >> 16 ) & 255 ) );
hb_fputc( ( BYTE ) ( ( ulCodeLength >> 24 ) & 255 ) );
lPCodePos = 0;
while( lPCodePos < pFunc->lPCodePos )
hb_fputc( pFunc->pCode[ lPCodePos++ ] );
pFunc = pFunc->pNext;
}
fprintf( s_yyc, "\n };\n\n" );
fprintf( s_yyc, " static public void main( String argv[] )\n" );
fprintf( s_yyc, " {\n" );
fprintf( s_yyc, " Harbour.Run( %s.pCode ); \n", pFileName->szName );
fprintf( s_yyc, " }\n\n" );
fprintf( s_yyc, "}\n" );
fclose( s_yyc );
if( ! hb_comp_bQuiet )
printf( "Done.\n" );
}
static void hb_fputc( BYTE b )
{
if( ++s_nChar > 1 )
fprintf( s_yyc, ", " );
if( s_nChar == 9 )
{
fprintf( s_yyc, "\n " );
s_nChar = 1;
}
fprintf( s_yyc, "0x%02X", ( int ) b );
}
static void hb_fputs( char * szName )
{
unsigned int nPos = 0;
while( nPos < strlen( szName ) )
hb_fputc( szName[ nPos++ ] );
}