* harbour/include/hbapi.h
* harbour/include/hbcomp.h
+ harbour/include/hbcompdf.h
* harbour/include/hberrors.h
* harbour/include/hbexpra.c
* harbour/include/hbexprb.c
* harbour/include/hbexprc.c
* harbour/include/hbexprop.h
* harbour/include/hbmacro.h
* harbour/include/hbpp.h
* harbour/include/hbvm.h
* harbour/source/common/expropt1.c
* harbour/source/common/expropt2.c
* harbour/source/compiler/Makefile
* harbour/source/compiler/cmdcheck.c
* harbour/source/compiler/complex.c
* harbour/source/compiler/genc.c
* harbour/source/compiler/gencc.c
* harbour/source/compiler/gencli.c
* harbour/source/compiler/gencobj.c
* harbour/source/compiler/genhrb.c
* harbour/source/compiler/genjava.c
* harbour/source/compiler/genobj32.c
* harbour/source/compiler/harbour.c
* harbour/source/compiler/harbour.l
* harbour/source/compiler/harbour.y
* harbour/source/compiler/hbcomp.c
* harbour/source/compiler/hbdead.c
* harbour/source/compiler/hbfix.c
* harbour/source/compiler/hbfunchk.c
* harbour/source/compiler/hbgenerr.c
* harbour/source/compiler/hbident.c
* harbour/source/compiler/hbpcode.c
* harbour/source/compiler/ppcomp.c
* harbour/source/macro/macro.y
* harbour/source/pp/ppcore.c
* harbour/source/pp/ppgen.c
* harbour/source/pp/pplib.c
* harbour/source/vm/cmdarg.c
* harbour/source/vm/estack.c
* harbour/source/vm/fm.c
* harbour/source/vm/macro.c
* harbour/utils/hbpp/hbpp.c
* harbour/utils/hbpp/hbpp.h
* harbour/utils/hbpp/hbppcomp.c
* harbour/utils/hbpp/hbppcore.c
* harbour/utils/hbpp/hbpplib.c
* harbour/utils/hbpp/pragma.c
* changed the internal compiler API to be MT safe.
All global and static non constant variables replaced by
HB_COMP structure which have all compiler context settings.
It's possible to allocate simultaneously many compiler contexts
and compile code. Only constant/read only variables are shared.
In macro compiler HB_COMP is replaced by HB_MACRO.
In source code I everywhere used to macros: HB_COMP_DECL and
HB_COMP_PARAM which are equivalents of old HB_MACRO_DECL and
HB_MACRO_PARAM definitions.
We will only have to change compiler FATAL errors support to
not execute exit() for non batch systems.
* make macro compiler fully MT safe
* removed not longer used definitions and variables
! add direct accessing to PP line number information - it fixes missing
line numbers reported recently
! added generating .ppo files when tokens are teken directly by compiler
- it fixes empty .ppo file problem
! clear hb_stack internall variables after removing hb_stack to avoid
possible GPF if application still works and try to access unexsiting
hb_stack
! do not allocate new memory block when final FM statistic report is
generated - it fixes problem with GPF when application compiled with
FM statistic exits and CLIPPER envvar is set.
! fixed memory leak hb_cmdargCheck()
! added to harbour.y symbol destructors - it should fixes memory leaks
in syntax errors but it uses quite new bison feature which is not
fully supported yet. Unfortunately it's also not MT safe and the
destructors implementation in 1.875c does not respect %parse-param.
Bison documentation says that it should so I hope it will be fixed
soon (or maybe even already is in the newest bison versions) before
I'll add multi context compilation support. If not then I will have
to add some workaround. I can pass compiler context pointer inside
YYSTYPE using hack in a lexer but it will force really huge number
modifications in existing bison rules so probably it will be much
easier to fix bison or write a small tool to update generated parser.
* other modifications - the total size of patch is nearly 1MB and
detail description will have to take me few days.
184 lines
5.2 KiB
C
184 lines
5.2 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( HB_COMP_DECL, PHB_FNAME pFileName )
|
|
{
|
|
char szFileName[ _POSIX_PATH_MAX ];
|
|
PFUNCTION pFunc /*= HB_COMP_PARAM->functions.pFirst */;
|
|
PCOMSYMBOL pSym = HB_COMP_PARAM->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_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL );
|
|
return;
|
|
}
|
|
|
|
if( ! HB_COMP_PARAM->fQuiet )
|
|
{
|
|
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_PARAM->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( HB_COMP_PARAM, pSym->szName ) ) /* is it a defined function ? */
|
|
hb_fputc( SYM_FUNC );
|
|
else
|
|
{
|
|
if( hb_compFunCallFind( HB_COMP_PARAM, pSym->szName ) )
|
|
hb_fputc( SYM_EXTERN );
|
|
else
|
|
hb_fputc( SYM_NOLINK );
|
|
}
|
|
pSym = pSym->pNext;
|
|
}
|
|
|
|
pFunc = HB_COMP_PARAM->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_PARAM->functions.pFirst;
|
|
if( ! HB_COMP_PARAM->fStartProc )
|
|
pFunc = pFunc->pNext;
|
|
|
|
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_PARAM->fQuiet )
|
|
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++ ] );
|
|
}
|