org.vishia.java2C
Class Java2C_Main

java.lang.Object
  extended by org.vishia.java2C.Java2C_Main
All Implemented Interfaces:
RunRequiredFirstPass_ifc

public class Java2C_Main
extends java.lang.Object
implements RunRequiredFirstPass_ifc

This class is the main class of translation Java2C. It is used from the command line call-implementation class Java2C.


Nested Class Summary
static class Java2C_Main.CmdlineArgs
          The gotten arguments from the command line are hold in this extra static class.
private static class Java2C_Main.FileIn
          One file entry to translate.
static class Java2C_Main.InputFileParseResult
          The instance of this class is filled with the result of parsing an input file given with -if:INPFILE cmd line calling argument.
private static class Java2C_Main.ListFileIn
          Helper class to create instances of Java2C_Main.FileIn for each detect input file.
 
Field Summary
private  java.util.List<GenerateFile> allJavaFilesToRunSecondPass
          List of all files processed in the first pass to consider in the second pass.
private  Java2C_Main.CmdlineArgs args
           
(package private)  Report console
          Aggregation to the Console implementation class.
static LocalIdents externalTypes
          Contains all types which are searched but not found in the Java2C translation.
(package private)  java.io.BufferedWriter fileRef
          Writer for a file containing all enhanced references.
private  java.util.Map<java.lang.String,java.lang.String> importHeaders
          Assignment between an import statement and a Headerfile.
(package private)  ConfigSrcPathPkg_ifc inputCfg
          Access to the input configuration set with cmdLine option -if:INPUTCFG.
(package private)  JavaSources javaSources
           
private  Java2C_Main.ListFileIn listFileIn
          Instance of Java2C_Main.ListFileIn.
private  java.util.List<java.lang.String> listInputToTranslate
          List of all java sources which are to translate given either in command line option-i or in the input config file given with given with command line argument -if:INPFILE, see #setConfigFile(String).
private  java.util.List<java.lang.String> listJavaSrcpath
          List of all source pathes given either in command line option -srcpath: or in the input config file given with given with command line argument -if:INPFILE, see #setConfigFile(String).
 CCodeData localReferenceDummy
          A CCodeInfo instance useable as dummy for local variable.
(package private)  ZbnfParser parser
          The parser for *.java input files.
private  int recursion
          Recursion respectively deepness of recursive call of #runFirstPassFile(JavaSrcTreeFile, int).
static Java2C_Main singleton
          The singleton instance of this class.
private  java.lang.String spaces
           
 CRuntimeJavalikeClassData standardClassData
          Instance with all ClassData and LocalIdents for the classes appropriated in the CRuntimeJavalike C runtime environment.
 CCodeData staticReferenceDummy
          A CCodeInfo instance useable as dummy for static variable.
(package private)  java.util.TreeMap<java.lang.String,ClassData> xxxallClassData
          List of known types.
 
Constructor Summary
private Java2C_Main(Java2C_Main.CmdlineArgs args, Report report)
          Private Constructor for singleton.
 
Method Summary
 boolean addInputFilemask(java.lang.String sMask, java.lang.String sCPrefix, java.lang.String sCPostfix)
           
static ClassData createExternalType(java.lang.String name, java.lang.String pkg)
          Creates a external type because no informations are available.
private  void createJavaPkgFileTreeFromCfg(java.lang.String sPkgPath, ConfigSrcPathPkg_ifc.Set info)
          Creates the package tree for all package replacements found in the configuration file.
 void execute()
          Executes the translation for all files.
static JavaSrcTreePkg getOrAddRootPkg(java.lang.String sName)
          Creates or searches a package which is a root package.
(package private)  java.lang.String getPathOut()
           
static LocalIdents getRootLevelIdents()
          Gets the FileLevelidents of the root level.
static JavaSrcTreePkg getRootPkg(java.lang.String sName)
          Searches a package which is a root package.
(package private)  boolean initZbnfParser()
          Initializes before execute().
static void instanciateSingleton(Java2C_Main.CmdlineArgs args, Report report)
          The create routine for the singleton.
private static ConfigSrcPathPkg_ifc readConfigFile(Java2C_Main.ListFileIn listFileIn, java.lang.String sFileName, Report console)
          Parses the given File and build the input file information for translating.
private  GenerateFile runFirstPassFile(JavaSrcTreeFile javaSrc)
          parses and translates one java file.
 ClassData runRequestedFirstPass(JavaSrcTreeFile javaSrc, java.lang.String sPkgClassName)
          Runs the first pass.
private  java.io.File searchFileStc(java.lang.String sFileNameStc)
          Searches a class in any *.stc-File.
(package private)  void stop()
          It's a debug helper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

console

Report console
Aggregation to the Console implementation class.


args

private final Java2C_Main.CmdlineArgs args

listFileIn

private final Java2C_Main.ListFileIn listFileIn
Instance of Java2C_Main.ListFileIn.


listJavaSrcpath

private java.util.List<java.lang.String> listJavaSrcpath
List of all source pathes given either in command line option -srcpath: or in the input config file given with given with command line argument -if:INPFILE, see #setConfigFile(String).


listInputToTranslate

private java.util.List<java.lang.String> listInputToTranslate
List of all java sources which are to translate given either in command line option-i or in the input config file given with given with command line argument -if:INPFILE, see #setConfigFile(String).
It is possible to declare whole packages or singe files to translate. Packages have / as separator and on end.


javaSources

final JavaSources javaSources

parser

final ZbnfParser parser
The parser for *.java input files. The parser is initialized with syntax from file Java2C.zbnf in directory given with cmd line args -syntax:SYNTAXDIR in the routine #init() called in execute().


fileRef

java.io.BufferedWriter fileRef
Writer for a file containing all enhanced references.


xxxallClassData

final java.util.TreeMap<java.lang.String,ClassData> xxxallClassData
List of known types.


allJavaFilesToRunSecondPass

private final java.util.List<GenerateFile> allJavaFilesToRunSecondPass
List of all files processed in the first pass to consider in the second pass.


inputCfg

ConfigSrcPathPkg_ifc inputCfg
Access to the input configuration set with cmdLine option -if:INPUTCFG. @Uml=aggregate.


importHeaders

private java.util.Map<java.lang.String,java.lang.String> importHeaders
Assignment between an import statement and a Headerfile.


externalTypes

public static final LocalIdents externalTypes
Contains all types which are searched but not found in the Java2C translation. If a type is necessary but not known, a unknown type is created. It is possible that the type isn't known in the given pool of Java files. Typically it may be a Type which may existent at the C-side because it is manually written. Another problem may be, it is an unregistered standard type.

This types are automatic created and are accessible in all scopes. The reportfile contains the list of all here registered types.


standardClassData

public CRuntimeJavalikeClassData standardClassData
Instance with all ClassData and LocalIdents for the classes appropriated in the CRuntimeJavalike C runtime environment. All this ClassData are stored in #stdTypes, which is the base of all LocalIdents, therefore this types are accessible in all scopes.
The content of this class is used directly if ClassData of this standard types are need, the access is done via the singleton.standardClassData.


localReferenceDummy

public final CCodeData localReferenceDummy
A CCodeInfo instance useable as dummy for local variable. There havn't a reference.


staticReferenceDummy

public final CCodeData staticReferenceDummy
A CCodeInfo instance useable as dummy for static variable. There havn't a reference.


recursion

private int recursion
Recursion respectively deepness of recursive call of #runFirstPassFile(JavaSrcTreeFile, int).


spaces

private java.lang.String spaces

singleton

public static Java2C_Main singleton
The singleton instance of this class.

Constructor Detail

Java2C_Main

private Java2C_Main(Java2C_Main.CmdlineArgs args,
                    Report report)
             throws java.io.FileNotFoundException,
                    java.lang.IllegalArgumentException,
                    java.io.IOException,
                    java.lang.IllegalAccessException,
                    java.lang.InstantiationException,
                    java.text.ParseException
Private Constructor for singleton.

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
java.text.ParseException
Method Detail

addInputFilemask

public boolean addInputFilemask(java.lang.String sMask,
                                java.lang.String sCPrefix,
                                java.lang.String sCPostfix)

instanciateSingleton

public static void instanciateSingleton(Java2C_Main.CmdlineArgs args,
                                        Report report)
The create routine for the singleton.


readConfigFile

private static ConfigSrcPathPkg_ifc readConfigFile(Java2C_Main.ListFileIn listFileIn,
                                                   java.lang.String sFileName,
                                                   Report console)
                                            throws java.text.ParseException
Parses the given File and build the input file information for translating. This method is called in the phase of evaluating the calling parameters. The content of the file will be parsed with ZBNF parsing with the fix syntax:
 input::={ translate:  ;}. 
 set::=<* ;=?inputpath>[ =: [*<* ;?Cname_prefix>|<**?Cname_postfix>*]].
A example of file content:
 srcJava/org/vishia/exampleJava2C/java4c/*.java = *_PosCtrl; //the files for position control
 ..//TODO
 

Parameters:
sFileName -
Returns:
true if successful, false if any error.
Throws:
java.text.ParseException

execute

public void execute()
             throws java.text.ParseException,
                    java.io.FileNotFoundException,
                    java.lang.IllegalArgumentException,
                    java.io.IOException,
                    java.lang.IllegalAccessException,
                    java.lang.InstantiationException
Executes the translation for all files.

Throws:
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException

createJavaPkgFileTreeFromCfg

private void createJavaPkgFileTreeFromCfg(java.lang.String sPkgPath,
                                          ConfigSrcPathPkg_ifc.Set info)
Creates the package tree for all package replacements found in the configuration file. It is assumed firstly, that a java-file isn't existing. Therefore the stc-file should be used.

If a java-file is found later in the java-source-path, it is replaced.

Parameters:
sPkgPath - The path given in config-file replace:-statement. The pathes can be separated with / or dot.

getPathOut

java.lang.String getPathOut()

initZbnfParser

boolean initZbnfParser()
                 throws java.text.ParseException,
                        java.io.FileNotFoundException,
                        java.io.IOException,
                        java.lang.IllegalArgumentException,
                        java.lang.IllegalAccessException,
                        java.lang.InstantiationException
Initializes before execute().

Returns:
true if successful.
Throws:
java.text.ParseException
java.io.FileNotFoundException
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

runFirstPassFile

private GenerateFile runFirstPassFile(JavaSrcTreeFile javaSrc)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException,
                                      java.text.ParseException,
                                      java.lang.IllegalArgumentException,
                                      java.lang.IllegalAccessException,
                                      java.lang.InstantiationException
parses and translates one java file. It is called The following actions are done:

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
java.io.IOException
java.text.ParseException

createExternalType

public static final ClassData createExternalType(java.lang.String name,
                                                 java.lang.String pkg)
Creates a external type because no informations are available.

Parameters:
name -
pkg -
Returns:
the created type. It is put also in the global userTypes:

getOrAddRootPkg

public static final JavaSrcTreePkg getOrAddRootPkg(java.lang.String sName)
Creates or searches a package which is a root package. Inside the returned package, the method JavaSrcTreePkg#getOrAddPkg(String, String) can be invoked to get or add a sub package or the method {@link JavaSrcTreePkg#setFileJava(String, File, String, String, String, String, String, String, boolean) can be invoked.

Parameters:
sName - The name of the root package
Returns:
The root package management instance.

getRootPkg

public static final JavaSrcTreePkg getRootPkg(java.lang.String sName)
Searches a package which is a root package.

Parameters:
sName - The name of the root package
Returns:
The root package management instance.

getRootLevelIdents

public static final LocalIdents getRootLevelIdents()
Gets the FileLevelidents of the root level. It are such as the packages "org" or "java".

Returns:
The fileLevelIdents for the root level.

stop

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


runRequestedFirstPass

public ClassData runRequestedFirstPass(JavaSrcTreeFile javaSrc,
                                       java.lang.String sPkgClassName)
                                throws java.io.FileNotFoundException,
                                       java.lang.IllegalArgumentException,
                                       java.io.IOException,
                                       java.lang.IllegalAccessException,
                                       java.lang.InstantiationException,
                                       java.text.ParseException
Runs the first pass. Searches the file and build the ClassData parsing and converting the file. This method is called if an unknown type is used yet.

Specified by:
runRequestedFirstPass in interface RunRequiredFirstPass_ifc
Parameters:
sClassName - The name of the type in Java. The filename should be the same. The file is searched in any package given as input parameter calling java2C.
Returns:
null if no file found. Otherwise the built ClassData. This ClassData are registered in the list Java2C_Main#userTypes.
Throws:
java.text.ParseException
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
See Also:
org.vishia.java2C.RunRequiredFirstPass_ifc#runRequestedFirstPass(java.lang.String)

searchFileStc

private java.io.File searchFileStc(java.lang.String sFileNameStc)
Searches a class in any *.stc-File. This method is called if a yet translated ClassData isn't found and a source to runfirstpass isn't found too.

Parameters:
sClassName -
Returns: