org.vishia.java2C
Class FirstPass

java.lang.Object
  extended by org.vishia.java2C.GenerateClass
      extended by org.vishia.java2C.FirstPass

public class FirstPass
extends GenerateClass

This class processes the first pass of translating Java to C of a detect class in a java file. Parsing the content of the java file is done before, see GenerateFile. In the first pass all declared elements of a class are captured and store in the ClassData.


Field Summary
(package private)  boolean bDontWriteCtor
           
private  java.util.List<FirstPass> innerClasses
           
private  ZbnfParseResultItem zbnfClass
           
 
Fields inherited from class org.vishia.java2C.GenerateClass
classData, fileLevelIdents, log, parentGenerateFile, runRequiredFirstPass, sMethodNameCurrent, writeContent
 
Constructor Summary
FirstPass(iWriteContent writeContent, GenerateFile parentGenerateFile, LocalIdents fileLevelIdents, RunRequiredFirstPass_ifc runRequiredFirstPass, Report log)
          initializes the instances with the given associations.
 
Method Summary
(package private)  ClassData buildType(java.lang.StringBuilder uResult, java.lang.String sourceOfClassDataP, GenerateFile fileContainsClass, java.lang.String sFileNameC, java.lang.String sPkgIdent, java.lang.String sPrefixClassCname, java.lang.String sSuffixClassCname, ZbnfParseResultItem zbnfClass, boolean bDontWriteCtor, java.lang.String sOuterClassName, ClassData outerClassData, java.util.List<ClassData> listAllClassesForSecondPath, boolean bInterface, ClassData classBase, char intension)
           
(package private)  java.lang.String gen_methodArguments(ZbnfParseResultItem zbnfMethod, LocalIdents localIdents, char intension, java.lang.String[] retArgSensitiveName, java.util.List<FieldData> retArgTypes)
          Generates the formal argument list of a method used both by generating method declaration or method definition.
(package private)  Method gen_methodHeadAndRegisterMethod(ZbnfParseResultItem zbnfMethod, int modeCtor, ClassData classOfMethod, java.lang.String sMethodNameJava, FieldData typeReturn, FieldData[] argTypes, boolean bArgumentSensitive)
          Generates a method head with syntax methodDefinition::= from given ZBNF parse result item and registers the method in the classData.
(package private)  void runFirstPass2(java.lang.StringBuilder uResult)
          Generates the content of a class in the h-file with given ZBNF parse result item of the class.
private  void write_ClassCpp(java.lang.StringBuilder uHeader)
           
private  void write_HeaderContent(java.lang.StringBuilder uHeader, GenerateFile fileContainsClass, ZbnfParseResultItem zbnfClass, boolean bDontWriteCtor, java.lang.String XXXsClassNameC, ClassData superClazz, ClassData[] ifcClassData)
          Write out the header part of the class.
(package private)  void write_Interface(ZbnfParseResultItem itemClass, java.lang.String sOuterClassName, ClassData outerClassData, java.lang.StringBuilder uHeader)
          Generates the content of an interface in c- and h-file.
 void write_methodDeclaration(ZbnfParseResultItem zbnfMethod, java.lang.String sClassName, LocalIdents localIdents, java.lang.StringBuilder uHeader)
          writes a method-forward-declaration in Headerfile and registers the method to generate definition.
private  void write_Mtbl(java.lang.StringBuilder uHeader)
           
private  void writeCtor(ZbnfParseResultItem zbnfClass, ClassData outerClass, java.lang.StringBuilder uHeader)
           
private  ClassData[] zbnfResultInterfaces(ZbnfParseResultItem zbnfClass, ZbnfParseResultItem zbnfDescription, LocalIdents localIdentsIfcType, ClassData firstInterface)
          Gets the interfaces from ZBNF parse result item.
(package private)  ClassData zbnfResultSuperclass(ZbnfParseResultItem zbnfClass, ZbnfParseResultItem zbnfDescription, ClassData outerClassData)
          Gets the superClass from ZBNF parse result item.
 
Methods inherited from class org.vishia.java2C.GenerateClass
createFieldDataNewObject, createFieldInfo, gen_AnonymousClass, gen_variableDefinition, genConstantValue, genIndent, get_shortDescription, getDimensionsArray, getType, getTypeInfoArray, getTypeInfoSimple, setStop, stop, stopCond, write_Description
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

innerClasses

private java.util.List<FirstPass> innerClasses

zbnfClass

private ZbnfParseResultItem zbnfClass

bDontWriteCtor

boolean bDontWriteCtor
Constructor Detail

FirstPass

FirstPass(iWriteContent writeContent,
          GenerateFile parentGenerateFile,
          LocalIdents fileLevelIdents,
          RunRequiredFirstPass_ifc runRequiredFirstPass,
          Report log)
initializes the instances with the given associations.

Method Detail

buildType

ClassData buildType(java.lang.StringBuilder uResult,
                    java.lang.String sourceOfClassDataP,
                    GenerateFile fileContainsClass,
                    java.lang.String sFileNameC,
                    java.lang.String sPkgIdent,
                    java.lang.String sPrefixClassCname,
                    java.lang.String sSuffixClassCname,
                    ZbnfParseResultItem zbnfClass,
                    boolean bDontWriteCtor,
                    java.lang.String sOuterClassName,
                    ClassData outerClassData,
                    java.util.List<ClassData> listAllClassesForSecondPath,
                    boolean bInterface,
                    ClassData classBase,
                    char intension)
              throws java.io.IOException,
                     java.text.ParseException,
                     java.lang.IllegalArgumentException,
                     java.lang.IllegalAccessException,
                     java.lang.InstantiationException
Parameters:
uResult -
sourceOfClassDataP -
fileContainsClass -
sFileNameC -
sPkgIdent -
sPrefixClassCname -
sSuffixClassCname -
zbnfClass -
bDontWriteCtor -
sOuterClassName -
outerClassData -
listAllClassesForSecondPath -
bInterface -
classBase -
intension - C: inner class, P: file-level (primary) class, Y: class level anonymous, other: anonymous inner class at statement block level
Returns:
Throws:
java.io.IOException
java.text.ParseException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.InstantiationException

runFirstPass2

void runFirstPass2(java.lang.StringBuilder uResult)
             throws java.lang.IllegalArgumentException,
                    java.io.IOException,
                    java.text.ParseException,
                    java.lang.IllegalAccessException,
                    java.lang.InstantiationException
Generates the content of a class in the h-file with given ZBNF parse result item of the class. This is the second part of the first pass of translation. This routine is called from GenerateFile. For fields, the initial values are detected and stored in ClassData#listVariablesToInit. This action is done inside the called routine GenerateClass#gen_variableDefinition(ZbnfParseResultItem, LocalIdents, List, char, ClassData[]).
The method heads are generated calling #write_methodDeclaration(ZbnfParseResultItem, String, LocalIdents).

Parameters:
uResult -
Throws:
java.lang.IllegalArgumentException
java.io.IOException
java.text.ParseException
java.lang.IllegalAccessException
java.lang.InstantiationException

zbnfResultSuperclass

ClassData zbnfResultSuperclass(ZbnfParseResultItem zbnfClass,
                               ZbnfParseResultItem zbnfDescription,
                               ClassData outerClassData)
                         throws java.io.FileNotFoundException,
                                java.lang.IllegalArgumentException,
                                java.io.IOException,
                                java.lang.IllegalAccessException,
                                java.lang.InstantiationException,
                                java.text.ParseException
Gets the superClass from ZBNF parse result item.

Parameters:
zbnfClass - The parse result item of classDefinition::=...
zbnfDescription - The parse result item of < description>... test_description::= inside the classDefinition::=...
outerClassData - a given outerclass
Returns:
The ClassData of the superClass. It is Java2C_Main.CRuntimeJavalikeClassData#clazzObjectJc if no superclass is given in Java-code (no extends ...). It is null if the description contains @java2c=noObject. and no other superclass is given.
Throws:
java.io.FileNotFoundException - The Superclass may be translated yet nested, it may be cause some errors.
java.lang.IllegalArgumentException - Errors see #runFirstPassClass(GenerateFile, String, String, String, String, ZbnfParseResultItem, String, ClassData, List, boolean, LocalIdents).
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

zbnfResultInterfaces

private ClassData[] zbnfResultInterfaces(ZbnfParseResultItem zbnfClass,
                                         ZbnfParseResultItem zbnfDescription,
                                         LocalIdents localIdentsIfcType,
                                         ClassData firstInterface)
                                  throws java.io.FileNotFoundException,
                                         java.lang.IllegalArgumentException,
                                         java.io.IOException,
                                         java.lang.IllegalAccessException,
                                         java.lang.InstantiationException,
                                         java.text.ParseException
Gets the interfaces from ZBNF parse result item.

Parameters:
zbnfClass - The parse result item of classDefinition::=...
zbnfDescription - The parse result item of < description>... test_description::= inside the classDefinition::=...
outerClassData - a given outerclass
sFirstInterface - name of the interface for anonymous classes
Returns:
Array of ClassData[] of all Interfaces. If the class hasn't interfaces, it is null.
Throws:
java.io.FileNotFoundException - The Superclass may be translated yet nested, it may be cause some errors.
java.lang.IllegalArgumentException - Errors see #runFirstPassClass(GenerateFile, String, String, String, String, ZbnfParseResultItem, String, ClassData, List, boolean, LocalIdents).
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

write_HeaderContent

private void write_HeaderContent(java.lang.StringBuilder uHeader,
                                 GenerateFile fileContainsClass,
                                 ZbnfParseResultItem zbnfClass,
                                 boolean bDontWriteCtor,
                                 java.lang.String XXXsClassNameC,
                                 ClassData superClazz,
                                 ClassData[] ifcClassData)
                          throws java.io.FileNotFoundException,
                                 java.lang.IllegalArgumentException,
                                 java.text.ParseException,
                                 java.io.IOException,
                                 java.lang.IllegalAccessException,
                                 java.lang.InstantiationException
Write out the header part of the class. It writes:
 /*@CLASS_C NAME @@@@@@@@@@@@@@@@@@@@@* /
 typedef struct NAME_t
 { union base_{ ObjectJc object; SUPER super; IFC IFC; } base
   VARIABLETYPE VARIABLENAME;
 } NAME_s;
 
 typedef struct NAME_Y_t { ObjectArrayJc head; " + NAME + "_s data[50]; } NAME_Y;");
 
 extern struct ClassJc_t const reflection_NAME_s;

 extern STATICVARIABLEDEF NAME;
 
 ...etc TODO  
 

Parameters:
uHeader - The buffer for output.
fileContainsClass - The calling instance.
zbnfClass - The parse result item of the class definition.
bDontWriteCtor - if it is an interface or anonymous class.
sClassNameC - The name, it is dissolved already from zbnfClass
superClazz - The superclass or ObjectJc or null
ifcClassData - null or interfaces
Throws:
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.text.ParseException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

writeCtor

private void writeCtor(ZbnfParseResultItem zbnfClass,
                       ClassData outerClass,
                       java.lang.StringBuilder uHeader)
                throws java.lang.IllegalArgumentException,
                       java.io.IOException,
                       java.text.ParseException,
                       java.lang.IllegalAccessException,
                       java.lang.InstantiationException
Parameters:
zbnfClass -
outerClass -
uHeader -
Throws:
java.lang.IllegalArgumentException
java.io.IOException
java.text.ParseException
java.lang.IllegalAccessException
java.lang.InstantiationException

write_Mtbl

private void write_Mtbl(java.lang.StringBuilder uHeader)

write_ClassCpp

private void write_ClassCpp(java.lang.StringBuilder uHeader)

write_Interface

void write_Interface(ZbnfParseResultItem itemClass,
                     java.lang.String sOuterClassName,
                     ClassData outerClassData,
                     java.lang.StringBuilder uHeader)
               throws java.io.IOException,
                      java.text.ParseException,
                      java.lang.IllegalArgumentException,
                      java.lang.IllegalAccessException,
                      java.lang.InstantiationException
Generates the content of an interface in c- and h-file.

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

write_methodDeclaration

public void write_methodDeclaration(ZbnfParseResultItem zbnfMethod,
                                    java.lang.String sClassName,
                                    LocalIdents localIdents,
                                    java.lang.StringBuilder uHeader)
                             throws java.io.IOException,
                                    java.text.ParseException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.IllegalAccessException,
                                    java.lang.InstantiationException
writes a method-forward-declaration in Headerfile and registers the method to generate definition. It calls

Parameters:
zbnfMethod - with syntax methodDefinition::=.
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

gen_methodHeadAndRegisterMethod

Method gen_methodHeadAndRegisterMethod(ZbnfParseResultItem zbnfMethod,
                                       int modeCtor,
                                       ClassData classOfMethod,
                                       java.lang.String sMethodNameJava,
                                       FieldData typeReturn,
                                       FieldData[] argTypes,
                                       boolean bArgumentSensitive)
                                 throws java.io.IOException,
                                        java.text.ParseException,
                                        java.lang.IllegalArgumentException,
                                        java.lang.IllegalAccessException,
                                        java.lang.InstantiationException
Generates a method head with syntax methodDefinition::= from given ZBNF parse result item and registers the method in the classData. The ambiguousness of the method should be tested before this call, but the unambiguous method name for C is built here: Methods with equal names but different parameter types are different methods.

Parameters:
zbnfMethod - Zbnf item defined in <methodDefinition> or <constructorDefinition>. The head hasn't an own zbnf-result item. The following contained elements are tested: If this argument is null, a default constructor is generated.
ctor - '.' if it isn't a ctor, 'C'-static ctor of class 'n'-ctor of non-static inner class. 'y'-ctor of anonymous class
classOfMethod - environment class, for non-static constructors the outer class.
sMethodNameJava - Name of the method, "ctorO" if a constructor from given ObjectJc should be generated.
typeReturn - Type of the method, get outside because this routine is also used to generate constructors. On constructor generation this argument should be equal the environment class type.
bArgumentSensitive - true than more as one method with the same Java-name exists. It is tested before calling ClassData.isAmbiguousnessMethod(String). The C-name of the method is built regarding the type of the arguments.
Returns:
The created Method. It contains the head definition in one line in its private attribute Method.sMethodFormalListDefiniton promoted in Method.gen_MethodForwardDeclaration() and Method.gen_MethodHeadDefinition().
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

gen_methodArguments

java.lang.String gen_methodArguments(ZbnfParseResultItem zbnfMethod,
                                     LocalIdents localIdents,
                                     char intension,
                                     java.lang.String[] retArgSensitiveName,
                                     java.util.List<FieldData> retArgTypes)
                               throws java.text.ParseException,
                                      java.io.FileNotFoundException,
                                      java.lang.IllegalArgumentException,
                                      java.io.IOException,
                                      java.lang.IllegalAccessException,
                                      java.lang.InstantiationException
Generates the formal argument list of a method used both by generating method declaration or method definition.

Parameters:
zbnfMethod - Zbnf item defined in argumentList::=....
localIdents - The known identificators of the calling environment, the type identificators are used especially. This parameter is used calling #gen_variableDefinition(ZbnfParseResultItem, LocalIdents, List, char intension, ClassData[]) inside with the parameters of the head. If the intension=='a' (Method definition in C-File),the parameter-variables are added to the localIdents.
intension - Intension of call: 'A'-declaration in h-File, 'a'-definition in c-file, passing on gen_variableDefinition().
retArgSensitiveName - [0] is filled with the short name of arg types if not null.
retArgTypes - The list is filled with the detect argument types, used for argument sensitive method call.
Returns:
String of formal arguments.
Throws:
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException