* harbour/tests/codebl.prg
* harbour/tests/langmsg.prg
* harbour/utils/hbpptest/pp_test.prg
* harbour/utils/hbpptest/pretest.prg
* harbour/samples/pe/license.txt
* removed carriage return (\r) characters
* harbour/include/hbcomp.h
* harbour/include/hbapi.h
* harbour/include/hbcompdf.h
* harbour/include/hbexprb.c
* harbour/include/hbexprop.h
* harbour/source/vm/macro.c
* harbour/source/compiler/hbcomp.c
* harbour/source/compiler/complex.c
* harbour/source/compiler/harbour.c
* harbour/source/compiler/harbour.l
* harbour/source/compiler/harbour.y
* harbour/source/compiler/genjava.c
* harbour/source/compiler/hbcomp.c
* harbour/source/compiler/hbident.c
* harbour/source/compiler/hbpcode.c
* harbour/source/compiler/ppcomp.c
* separated HB_COMP and HB_MACRO definitions and added HB_COMMON
structure used when HB_COMMON_SUPPORT macro is set
* hide HB_MACRO internal definitions in hbapi.h when HB_MACRO_SUPPORT
is not set
These modifications should help in future compiler and macro compiler
integration into single binary.
+ added clipper compatible error message in unclosed structures
In general we should cleanup rules to make error reporting more
user friendly and Clipper compatible
% eliminated unnecessary allocations
+ added int mode member to common part of HB_COMP and HB_MACRO
structure. It's initialized to HB_MODE_MACRO or HB_MODE_COMPILER
+ add TOFIX note about memory leaks in cParamTypes and pParamClasses
members of COMDECLARED structure. It's a part of unfinished strong
typing code. I do not know what Ryszard plan to do with it so I'm
leaving it as is. The part of strong typing which were operating
on emulated HVM stack has been removed.
* removed static variables from genjava.c. Also gencli.c and genobj32.c
should be fixed but this will not make this code working so I haven't
touched it.
* changed 3-rd parameter of hb_compIdentifierNew() from BOOL to int.
Now it can have the following values: HB_IDENT_STATIC, HB_IDENT_FREE,
HB_IDENT_COPY. This modification will allow in the future using common
for static and dynamic symbol hash table without additional source code
changes. I also plan to use identifier hash table in PP the reduce
number of memory allocations and speed-up preprocessing by using
second level hashing for hash keys.
* harbour/source/common/expropt1.c
* harbour/source/common/expropt2.c
* changed HB_MACRO_SUPPORT to HB_COMMON_SUPPORT to automatically detect
possible conflicts between compiler and macro compiler
! removed first detected conflict which existed for long time
+ added hb_compExprMacroAsAlias() function to convert HB_ET_VARIABLE
expression to HB_ET_ALIAS.
* harbour/source/macro/macro.y
! fixed using prefix¯o-> and ¯o.sufix-> when macro cannot be
substituted by compiler, f.e.:
M->v := NIL
x := "&v.1->fld"
M->v := "v"
M->v1:= "data"
? &x
! fixed memory leak in macro substituted expression compilation
* harbour/source/vm/macro.c
! fixed initialization of some HB_MACRO members
! fixed value returned for type("&V->F") when alias does not exist
- removed not longer used hb_comp_bShortCuts global variable
183 lines
5.6 KiB
C
183 lines
5.6 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 int hb_fputc( BYTE b, FILE * fOut, int nChar )
|
|
{
|
|
if( ++nChar > 1 )
|
|
fprintf( fOut, ", " );
|
|
|
|
if( nChar == 9 )
|
|
{
|
|
fprintf( fOut, "\n " );
|
|
nChar = 1;
|
|
}
|
|
|
|
fprintf( fOut, "0x%02X", ( int ) b );
|
|
|
|
return nChar;
|
|
}
|
|
|
|
static int hb_fputs( char * szName, FILE * fOut, int nChar )
|
|
{
|
|
unsigned int nPos = 0;
|
|
|
|
while( nPos < strlen( szName ) )
|
|
nChar = hb_fputc( szName[ nPos++ ], fOut, nChar );
|
|
|
|
return nChar;
|
|
}
|
|
|
|
void hb_compGenJava( HB_COMP_DECL, PHB_FNAME pFileName )
|
|
{
|
|
char szFileName[ _POSIX_PATH_MAX ], * szVer;
|
|
PFUNCTION pFunc /*= HB_COMP_PARAM->functions.pFirst */;
|
|
PCOMSYMBOL pSym = HB_COMP_PARAM->symbols.pFirst;
|
|
ULONG lPCodePos;
|
|
LONG lSymbols;
|
|
ULONG ulCodeLength;
|
|
FILE * fOut;
|
|
int nChar;
|
|
|
|
if( ! pFileName->szExtension )
|
|
pFileName->szExtension = ".java";
|
|
hb_fsFNameMerge( szFileName, pFileName );
|
|
|
|
fOut = fopen( szFileName, "wb" );
|
|
if( ! fOut )
|
|
{
|
|
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 );
|
|
}
|
|
|
|
nChar = 0;
|
|
szVer = hb_verHarbour();
|
|
fprintf( fOut, "/*\n * %s\n * Generated JAVA source code\n */\n\n", szVer );
|
|
hb_xfree( szVer );
|
|
|
|
fprintf( fOut, "public class %s\n", pFileName->szName );
|
|
fprintf( fOut, "{\n" );
|
|
fprintf( fOut, " public static int[] pCode =\n" );
|
|
fprintf( fOut, " {\n" );
|
|
fprintf( fOut, " " );
|
|
|
|
/* writes the symbol table */
|
|
|
|
lSymbols = 0; /* Count number of symbols */
|
|
while( pSym )
|
|
{
|
|
lSymbols++;
|
|
pSym = pSym->pNext;
|
|
}
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols ) & 255 ), fOut, nChar ); /* Write number symbols */
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 8 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 16 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 24 ) & 255 ), fOut, nChar );
|
|
|
|
pSym = HB_COMP_PARAM->symbols.pFirst;
|
|
while( pSym )
|
|
{
|
|
nChar = hb_fputs( pSym->szName, fOut, nChar );
|
|
nChar = hb_fputc( 0, fOut, nChar );
|
|
nChar = hb_fputc( pSym->cScope, fOut, nChar );
|
|
|
|
/* 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 ? */
|
|
nChar = hb_fputc( SYM_FUNC, fOut, nChar );
|
|
else
|
|
{
|
|
if( hb_compFunCallFind( HB_COMP_PARAM, pSym->szName ) )
|
|
nChar = hb_fputc( SYM_EXTERN, fOut, nChar );
|
|
else
|
|
nChar = hb_fputc( SYM_NOLINK, fOut, nChar );
|
|
}
|
|
pSym = pSym->pNext;
|
|
}
|
|
|
|
pFunc = HB_COMP_PARAM->functions.pFirst;
|
|
|
|
lSymbols = 0; /* Count number of symbols */
|
|
while( pFunc )
|
|
{
|
|
lSymbols++;
|
|
pFunc = pFunc->pNext;
|
|
}
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols ) & 255 ), fOut, nChar ); /* Write number symbols */
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 8 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 16 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( lSymbols >> 24 ) & 255 ), fOut, nChar );
|
|
|
|
/* Generate functions data
|
|
*/
|
|
pFunc = HB_COMP_PARAM->functions.pFirst;
|
|
if( ! HB_COMP_PARAM->fStartProc )
|
|
pFunc = pFunc->pNext;
|
|
|
|
while( pFunc )
|
|
{
|
|
nChar = hb_fputs( pFunc->szName, fOut, nChar );
|
|
nChar = hb_fputc( 0, fOut, nChar );
|
|
ulCodeLength = pFunc->lPCodePos;
|
|
nChar = hb_fputc( ( BYTE ) ( ( ulCodeLength ) & 255 ), fOut, nChar ); /* Write size */
|
|
nChar = hb_fputc( ( BYTE ) ( ( ulCodeLength >> 8 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( ulCodeLength >> 16 ) & 255 ), fOut, nChar );
|
|
nChar = hb_fputc( ( BYTE ) ( ( ulCodeLength >> 24 ) & 255 ), fOut, nChar );
|
|
|
|
lPCodePos = 0;
|
|
while( lPCodePos < pFunc->lPCodePos )
|
|
nChar = hb_fputc( pFunc->pCode[ lPCodePos++ ], fOut, nChar );
|
|
|
|
pFunc = pFunc->pNext;
|
|
}
|
|
|
|
fprintf( fOut, "\n };\n\n" );
|
|
fprintf( fOut, " static public void main( String argv[] )\n" );
|
|
fprintf( fOut, " {\n" );
|
|
fprintf( fOut, " Harbour.Run( %s.pCode ); \n", pFileName->szName );
|
|
fprintf( fOut, " }\n\n" );
|
|
fprintf( fOut, "}\n" );
|
|
|
|
fclose( fOut );
|
|
|
|
if( ! HB_COMP_PARAM->fQuiet )
|
|
printf( "Done.\n" );
|
|
}
|