org.vishia.java2C
Class SecondPass

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

public class SecondPass
extends GenerateClass

This class handle the second pass of the translation. An instance is built only temporary to run the pass. All Data are stored in the ClassData. Instances of ClassData will be created while running the first pass, there are stored in the singleton AllData. Than they are used to run the Second Pass.


Field Summary
(package private)  boolean bUse_mtthis
          Stores the necessity of generating a mtthis reference for the own method table.
(package private)  boolean noStacktrace
          Stores the necessity of generating a STACKTRC_ENTRY and STACKTRC_LEAVE.
 
Fields inherited from class org.vishia.java2C.GenerateClass
classData, fileLevelIdents, log, parentGenerateFile, runRequiredFirstPass, sMethodNameCurrent, writeContent
 
Constructor Summary
SecondPass(iWriteContent writeContent, GenerateFile parentGenerateFile, LocalIdents fileLevelIdents, ClassData classData, RunRequiredFirstPass_ifc runRequiredFirstPass, Report log)
          Initializes an instance to run the second pass of a given class.
 
Method Summary
(package private)  void _assert(boolean cond)
           
 java.lang.String gen_for_statement(ZbnfParseResultItem itemStatement, int indent, StatementBlock parentStatementBlock, FieldData typeReturn)
           
 java.lang.String gen_statementBlock(ZbnfParseResultItem zbnfStatementBlock, int indent, StatementBlock parentBlock, FieldData typeReturn, char intension)
          Generates C-code from a parsed statement block.
(package private)  void runSecondPassClass(ZbnfParseResultItem itemClass, java.lang.String sOuterClassName)
          writes the constructor-, method-, static variable- definition and reflection into the C-File.
private  void write_constructorDefinition(ClassData.MethodWithZbnfItem methodDef, java.lang.String sClassName, boolean bArgumentSensitive)
          writes a constructor definition as C-method into the C-File.
 void write_finalizeDefinition(ZbnfParseResultItem zbnfClass, java.lang.String sClassName, LocalIdents idents)
           
 void write_methodDefinition(ClassData.MethodWithZbnfItem methodDef, java.lang.String sClassName, LocalIdents parentIdents)
          writes a method definition as C-method into the C-File.
private  void write_Reflections()
          Writes out the reflection inclusively the method table definition.
 
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

bUse_mtthis

boolean bUse_mtthis
Stores the necessity of generating a mtthis reference for the own method table. This variable is set to false on start of any write_methodDefinition(org.vishia.java2C.ClassData.MethodWithZbnfItem, String, LocalIdents) and set to true if any dynamic call with ythis-reference is generated. Depending on this, a line to prepare a mtthis variable: The reference to the own method table, is prepared.


noStacktrace

boolean noStacktrace
Stores the necessity of generating a STACKTRC_ENTRY and STACKTRC_LEAVE. This variable is set on start of any write_methodDefinition(org.vishia.java2C.ClassData.MethodWithZbnfItem, String, LocalIdents) depending on the Method.noStacktrace().

Constructor Detail

SecondPass

SecondPass(iWriteContent writeContent,
           GenerateFile parentGenerateFile,
           LocalIdents fileLevelIdents,
           ClassData classData,
           RunRequiredFirstPass_ifc runRequiredFirstPass,
           Report log)
Initializes an instance to run the second pass of a given class. The instance is generated only temporary to run the passes, see GenerateClass.

Parameters:
genClass.writeContent - Interface to write the content. Note: The content is not written immediately in a file, but temporary stored in some StringBuilder. The reason is the order of parts of C-File and H-File.
pkgIdents - singleton information of all classes there are knwon yet.
classData - The data of this class saves between parsing, first and second pass. This classData also contain the ZBNF parse result items.
runRequiredFirstPass - Interface to cause the parsing and running of a first pass of a up-to-now unknown class. This interface is implemented at the main level of the Java2C-translator
Method Detail

runSecondPassClass

void runSecondPassClass(ZbnfParseResultItem itemClass,
                        java.lang.String sOuterClassName)
                  throws java.io.IOException,
                         java.text.ParseException,
                         java.lang.IllegalArgumentException,
                         java.lang.IllegalAccessException,
                         java.lang.InstantiationException
writes the constructor-, method-, static variable- definition and reflection into the C-File. Inside it is written and called:

Parameters:
itemClass - The class start item of zbnf parse result.
sOuterClassName - Name of the environment class not used yet
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

write_Reflections

private void write_Reflections()
Writes out the reflection inclusively the method table definition. A method table isn't need if the class is either a simple data class without virtual methods or if it is an interface: The method table refers the implementation methods of the instantiation, an interface hasn't an instantiation.


write_constructorDefinition

private void write_constructorDefinition(ClassData.MethodWithZbnfItem methodDef,
                                         java.lang.String sClassName,
                                         boolean bArgumentSensitive)
                                  throws java.io.IOException,
                                         java.text.ParseException,
                                         java.lang.IllegalArgumentException,
                                         java.lang.IllegalAccessException,
                                         java.lang.InstantiationException
writes a constructor definition as C-method into the C-File. The interface-method iWriteContent.writeClassC(String) is used to do it. The content isn't written directly in the file, because some include-lines generated while running any methods and constructors of second pass should be written before the text of this method.
Inside it is written and called: While generating the constructor it is possible that a type is used inside, which is unknown yet. Than an include is generated. Because the internal structure of the type should be known, the parsing of the Java Code and the run of its first pass is processed while running the method generation. The second pass of this file is running later. This actions are done using RunRequiredFirstPass_ifc#runRequestedFirstPass(String).

Parameters:
itemConstructor - Parse result of constructorDefinition::=... If it is null, than this method is used to create a default constructor with all initializations.
sClassName - Full Name of the class in C-Style where the constructor is member of. The class name is used as return type and as C-methodidentifier-postfix.
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

write_finalizeDefinition

public void write_finalizeDefinition(ZbnfParseResultItem zbnfClass,
                                     java.lang.String sClassName,
                                     LocalIdents idents)
                              throws java.text.ParseException,
                                     java.io.FileNotFoundException,
                                     java.lang.IllegalArgumentException,
                                     java.io.IOException,
                                     java.lang.IllegalAccessException,
                                     java.lang.InstantiationException
Throws:
java.text.ParseException
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

write_methodDefinition

public void write_methodDefinition(ClassData.MethodWithZbnfItem methodDef,
                                   java.lang.String sClassName,
                                   LocalIdents parentIdents)
                            throws java.io.IOException,
                                   java.text.ParseException,
                                   java.lang.IllegalArgumentException,
                                   java.lang.IllegalAccessException,
                                   java.lang.InstantiationException
writes a method definition as C-method into the C-File. The interface-method iWriteContent.writeClassC(String) is used to do it. The content isn't written directly in the file, because some include-lines generated while running any methods and constructors of second pass should be written before the text of this method.
Inside it is written or called: While generating the method it is possible that a type is used inside, which is unknown yet. Than an include-line is generated. Because the internal structure of the type should be known, the parsing of the Java Code and the run of its first pass is processed while running the method generation. The second pass of this file is running later. This actions are done using RunRequiredFirstPass_ifc#runRequestedFirstPass(String).

Parameters:
parent - Parse result of methodDefinition::=...
sClassName - Full Name of the class in C-Style where the method is member of. The class name is used as ythis-type and as C-method-identifier-postfix.
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

gen_statementBlock

public java.lang.String gen_statementBlock(ZbnfParseResultItem zbnfStatementBlock,
                                           int indent,
                                           StatementBlock parentBlock,
                                           FieldData typeReturn,
                                           char intension)
                                    throws java.text.ParseException,
                                           java.io.FileNotFoundException,
                                           java.lang.IllegalArgumentException,
                                           java.io.IOException,
                                           java.lang.IllegalAccessException,
                                           java.lang.InstantiationException
Generates C-code from a parsed statement block.

Parameters:
zbnfStatementBlock - The ZBNF parse result item which is a < statementBlock>
indent - number of indentation in the generated C-code. It is the level of blocks.
localIdentsP - The local identifiers of the parent block.
intension - Intension of call: 'c'-constructor body, 'm'-method body, 'b'internal block, 'f'-finalize body.
Returns:
The generated C-code for the block inclusive newlines, indentation and { }.
Throws:
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException

gen_for_statement

public java.lang.String gen_for_statement(ZbnfParseResultItem itemStatement,
                                          int indent,
                                          StatementBlock parentStatementBlock,
                                          FieldData typeReturn)
                                   throws java.text.ParseException,
                                          java.io.FileNotFoundException,
                                          java.lang.IllegalArgumentException,
                                          java.io.IOException,
                                          java.lang.IllegalAccessException,
                                          java.lang.InstantiationException
Throws:
java.text.ParseException
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

_assert

void _assert(boolean cond)