org.vishia.java2C
Class GenerateFile

java.lang.Object
  extended by org.vishia.java2C.GenerateFile
All Implemented Interfaces:
iWriteContent

public class GenerateFile
extends java.lang.Object
implements iWriteContent

This class processes the first and second pass of translating Java to C of a java file. Parsing the content of the java file is done before it processed, see Java2C_Main.


Field Summary
private  LocalIdents fileLevelIdents
          All Type identifier (ClassData which are visible at file level.
private  java.io.File fileStruct
          The file descriptor for the structure file.
private  java.util.TreeMap<java.lang.String,java.lang.String> imports
           
private  java.util.TreeMap<java.lang.String,java.lang.String> includes
          All include declarations necessary in the C-file of this java file.
private  JavaSources javaSources
          lines for c file mapping the class content.
(package private)  JavaSrcTreeFile javaSrc
           
(package private)  java.util.List<ClassData> listAllClassesForSecondPath
          List of all classes found in this file.
private  java.util.List<ClassData> listClassInFile
          List of all classes in the file.
private  LocalIdents pkgIdents
          Copy of the reference from javaSrc.
private  Report report
           
(package private)  RunRequiredFirstPass_ifc runRequiredFirstPass
          The interface to call a firstpass run of a needed type.
(package private)  java.lang.String sFileNameC
          Name without path and extension of the c- and h-file from java file.
(package private)  java.lang.String sPkgIdent
          Package where the Java file is stored, with / as separators and at end.
private  java.lang.StringBuilder uFileCDefinitions
          lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.
private  java.lang.StringBuilder uFileCSecondPath
          lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.
private  java.lang.StringBuilder uFileHDefinitions
          lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.
private  java.util.Map<java.lang.String,java.lang.Object> usedEnhancedRefTypes
          Index of all classes from which an enhanced reference is need in this compilation unit.
private  java.util.Map<java.lang.String,java.lang.Object> usedMtblRefTypesC
          Index of all classes from which an method-table reference is need in this compilation unit.
private  java.util.Map<java.lang.String,java.lang.Object> usedMtblRefTypesH
          Index of all classes from which an method-table reference is need in the header file.
 
Constructor Summary
GenerateFile(JavaSources javaSources, JavaSrcTreeFile javaSrc, RunRequiredFirstPass_ifc runRequiredFirstPass, java.io.File fileStruct, Report report)
          initializes the instances with the given associations.
 
Method Summary
 void addEnhancedRefType(java.lang.String sRefType)
          If a type is used as enhanced reference in the code of the class, it is noted here.
 void addIncludeC(java.lang.String sFileName, java.lang.String comment)
          Adds a type to include the type-correspondent h-file in the c-file.
 void addIncludeH(java.lang.String sFileName, java.lang.String comment)
          Adds a type to include the type-correspondent h-file in the h-file.
 void addMtblRefType(java.lang.String sRefType, char intension)
          If a type is used as method-table- reference in the code of the class, it is noted here.
(package private)  void evaluateImports(ZbnfParseResultItem resultFile)
           
(package private)  void registerClassInFile(ClassData classData)
           
(package private)  void runFirstPassFile(ZbnfParseResultItem resultItem, java.lang.String sPrefixClassCname, java.lang.String sSuffixClassCname, java.lang.String sPathOut)
          Generates the content of all classes in the h-file with given ZBNF parse result item of the class.
(package private)  void runSecondPassFile()
          Generates the content of a class in the c-file.
(package private)  void stop()
          It's a debug helper.
 java.lang.String toString()
           
private  java.lang.String unusedyet_getImport(java.lang.String sType)
           
 void writeCdefs(java.lang.StringBuilder content)
          Adds a text to the C-definition-code
 void writeClassC(java.lang.String content)
          Adds a text to the C-code
 void writeClassC(java.lang.StringBuilder content)
          Adds a text to the C-code
 void writeClassH(java.lang.String line)
          Adds a text to the Headerfile-code
 void writeHdefs(java.lang.StringBuilder content)
          Adds a text to the H-code
(package private) static void writeStructure(java.io.File fileStructP, java.lang.String sFilePathNameC, java.util.List<ClassData> listClassInFile, java.lang.String sPkgIdent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

report

private Report report

sFileNameC

final java.lang.String sFileNameC
Name without path and extension of the c- and h-file from java file.


javaSrc

final JavaSrcTreeFile javaSrc

sPkgIdent

java.lang.String sPkgIdent
Package where the Java file is stored, with / as separators and at end. This information is got in #runFirstPass(ZbnfParseResultItem, LocalIdents, String, File) from the package-declaration in the Java file. The dots . in Java file are translated to slash / here.


uFileCDefinitions

private final java.lang.StringBuilder uFileCDefinitions
lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.


uFileCSecondPath

private final java.lang.StringBuilder uFileCSecondPath
lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.


uFileHDefinitions

private final java.lang.StringBuilder uFileHDefinitions
lines for c file mapping the definitions in the C-file before the content of the bodies, see sClassC.


javaSources

private final JavaSources javaSources
lines for c file mapping the class content.


pkgIdents

private final LocalIdents pkgIdents
Copy of the reference from javaSrc.JavaSrcTreeFile.itsPkg.JavaSrcTreePkg.pkgIdents for faster access.


fileLevelIdents

private final LocalIdents fileLevelIdents
All Type identifier (ClassData which are visible at file level. It contains all classes which are imported in this file. It doesn't contain the package visible identifier, see


usedEnhancedRefTypes

private final java.util.Map<java.lang.String,java.lang.Object> usedEnhancedRefTypes
Index of all classes from which an enhanced reference is need in this compilation unit. Enhanced references are used for backward references for garbage collection and to store an index to the method table. NOTE: the second part of Map, the Object, isn't necessary. Only the unique registering is necessary.


usedMtblRefTypesH

private final java.util.Map<java.lang.String,java.lang.Object> usedMtblRefTypesH
Index of all classes from which an method-table reference is need in the header file. Method-table-references are used to work with dynamic call, the method table pointer and the instance pointer are contained there. NOTE: the second part of Map, the Object, isn't necessary. Only the unique registering is necessary.


usedMtblRefTypesC

private final java.util.Map<java.lang.String,java.lang.Object> usedMtblRefTypesC
Index of all classes from which an method-table reference is need in this compilation unit. Method-table-references are used to work with dynamic call, the method table pointer and the instance pointer are contained there. NOTE: the second part of Map, the Object, isn't necessary. Only the unique registering is necessary.


fileStruct

private java.io.File fileStruct
The file descriptor for the structure file.


listClassInFile

private final java.util.List<ClassData> listClassInFile
List of all classes in the file. Inner classes are not stored here. Typically only one class is found in file. This information is used locally only at example to write all structure informations of classes in file


runRequiredFirstPass

final RunRequiredFirstPass_ifc runRequiredFirstPass
The interface to call a firstpass run of a needed type.


includes

private final java.util.TreeMap<java.lang.String,java.lang.String> includes
All include declarations necessary in the C-file of this java file. The list will be filled also while running the second path.


imports

private final java.util.TreeMap<java.lang.String,java.lang.String> imports

listAllClassesForSecondPath

final java.util.List<ClassData> listAllClassesForSecondPath
List of all classes found in this file. This list is used to control, for which classes the second path is to be run. The list contains inner classes also. That is because inner classes are translated to plain typedef struct... and plan C-routines.

Constructor Detail

GenerateFile

GenerateFile(JavaSources javaSources,
             JavaSrcTreeFile javaSrc,
             RunRequiredFirstPass_ifc runRequiredFirstPass,
             java.io.File fileStruct,
             Report report)
initializes the instances with the given associations.

Method Detail

writeCdefs

public void writeCdefs(java.lang.StringBuilder content)
Adds a text to the C-definition-code

Specified by:
writeCdefs in interface iWriteContent
Parameters:
content - the content with the necessary line feeds.

writeHdefs

public void writeHdefs(java.lang.StringBuilder content)
Adds a text to the H-code

Specified by:
writeHdefs in interface iWriteContent
Parameters:
content - the content with the necessary line feeds.

writeClassC

public void writeClassC(java.lang.String content)
Adds a text to the C-code

Specified by:
writeClassC in interface iWriteContent
See Also:
iWriteContent.writeClassC(java.lang.String)

writeClassC

public void writeClassC(java.lang.StringBuilder content)
Adds a text to the C-code

Specified by:
writeClassC in interface iWriteContent
See Also:
iWriteContent.writeClassC(java.lang.StringBuilder)

writeClassH

public void writeClassH(java.lang.String line)
Adds a text to the Headerfile-code

Specified by:
writeClassH in interface iWriteContent
See Also:
iWriteContent.writeClassH(java.lang.String)

addIncludeC

public void addIncludeC(java.lang.String sFileName,
                        java.lang.String comment)
Adds a type to include the type-correspondent h-file in the c-file.

Specified by:
addIncludeC in interface iWriteContent
Parameters:
sFileName - The file path without .h
comment - a commment written after the include line.

addIncludeH

public void addIncludeH(java.lang.String sFileName,
                        java.lang.String comment)
Adds a type to include the type-correspondent h-file in the h-file.

Specified by:
addIncludeH in interface iWriteContent

unusedyet_getImport

private java.lang.String unusedyet_getImport(java.lang.String sType)

runFirstPassFile

void runFirstPassFile(ZbnfParseResultItem resultItem,
                      java.lang.String sPrefixClassCname,
                      java.lang.String sSuffixClassCname,
                      java.lang.String sPathOut)
                throws java.io.IOException,
                       java.text.ParseException,
                       java.lang.IllegalArgumentException,
                       java.lang.IllegalAccessException,
                       java.lang.InstantiationException
Generates the content of all classes in the h-file with given ZBNF parse result item of the class. This routine is called from Java2C_Main.
First the h-file-content of all classes are generated into StringBuffer. If all runFirstPass of all found classes are done, the file will be written. First the necessary includes will be written in the destination h-file. Therefore the runFirstPass of all classes should be done before.

Parameters:
resultItem - The first result item of ZBNF parsing of the whole java-File.
pkgIdents - Global map of all classes of the whole translating process.
sPathOut - output path for the h- and c-file, with slash on end
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

registerClassInFile

void registerClassInFile(ClassData classData)

runSecondPassFile

void runSecondPassFile()
                 throws java.io.IOException,
                        java.text.ParseException,
                        java.lang.IllegalArgumentException,
                        java.lang.IllegalAccessException,
                        java.lang.InstantiationException
Generates the content of a class in the c-file. The class field listAllClassesForSecondPath is filled while running the first pass and contains all classes found in the java file. The ZBNF parse result item of each class is stored there. This routine is called from Java2C_Main.
First the c-file-content of all classes are generated into the StringBuffer sClassC. If all runSecondPass of all found classes are done, the file will be written. First the necessary includes will be written in the destination c-file. Therefore the runSecondPass of all classes should be done before.

Parameters:
pkgIdents - Global map of all classes of the whole translating process.
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

addEnhancedRefType

public void addEnhancedRefType(java.lang.String sRefType)
If a type is used as enhanced reference in the code of the class, it is noted here. The information will be used to define the enhanced references in the Headerfile, it is also transformed to the stc file. (?)

Parameters:
sRefType - The referenced type.

addMtblRefType

public void addMtblRefType(java.lang.String sRefType,
                           char intension)
If a type is used as method-table- reference in the code of the class, it is noted here. The information will be used to define the enhanced references in the Headerfile, it is also transformed to the stc file. (?)

Parameters:
sRefType - The referenced type.

writeStructure

static void writeStructure(java.io.File fileStructP,
                           java.lang.String sFilePathNameC,
                           java.util.List<ClassData> listClassInFile,
                           java.lang.String sPkgIdent)
                    throws java.io.IOException
Parameters:
fileStructP -
sFilePathNameC - Path and name for C,without extension
listClassInFile -
sPkgIdent -
Throws:
java.io.IOException

evaluateImports

void evaluateImports(ZbnfParseResultItem resultFile)
               throws java.io.IOException,
                      java.lang.IllegalArgumentException,
                      java.lang.IllegalAccessException,
                      java.lang.InstantiationException,
                      java.text.ParseException
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

stop

void stop()
It's a debug helper. The method is empty, but it is a mark to set a breakpoint.