org.vishia.java2C
Class GenerateClass

java.lang.Object
  extended by org.vishia.java2C.GenerateClass
Direct Known Subclasses:
FirstPass, SecondPass

 class GenerateClass
extends java.lang.Object

This is the superclass for FirstPass and SecondPass. It contains commonly methods used in both passes and commonly data for both passes. This class isn't store as instance between both passes, elsewhere the ClassData to store are stored in the instance of ClassData, all the ClassData are contained in a list inside AllClassData. The attributes of this class are copied from the Java2C_Main in construction and there are forgotten after running the pass.


Field Summary
protected  ClassData classData
          The data of this class for first and second path.
protected  LocalIdents fileLevelIdents
          A TreeMap of all classData sorted by classname to find all other classData.
protected  Report log
           
protected  GenerateFile parentGenerateFile
           
(package private)  RunRequiredFirstPass_ifc runRequiredFirstPass
          The interface to call a firstpass run of a needed type.
protected  java.lang.String sMethodNameCurrent
          The C-name of the current translated method, used for _Stacktrace and alloc_s_BlockHeapJc.
private static java.lang.String sNewLine
          String to generate newline and indent.
private  boolean stopCond
           
protected  iWriteContent writeContent
          A writer to file.
 
Constructor Summary
protected GenerateClass(iWriteContent writeContent, GenerateFile parentGenerateFile, LocalIdents fileLevelIdents, RunRequiredFirstPass_ifc runRequiredFirstPass, Report log)
          constructs the class.
 
Method Summary
(package private)  FieldData createFieldDataNewObject(ZbnfParseResultItem zbnfNewObject, ZbnfParseResultItem zbnfDescription, LocalIdents typeIdentsForNew, LocalIdents localIdentsP, StatementBlock blockEnvironment, java.lang.String sNameField, ClassData declaringClass, char intension, char accessModeP, char staticMode, boolean isFinal)
          Creates FieldData for a new Type(...)
 FieldData createFieldInfo(ZbnfParseResultItem zbnfVariable, ZbnfParseResultItem zbnfType, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfNewObject, LocalIdents localIdentsP, StatementBlock blockEnvironment, ClassData declaringClass, char intension, char definitionCondition)
          Prepare the type properties from a given ZBNF type::= or adequate info.
 ClassData gen_AnonymousClass(ZbnfParseResultItem zbnfNewObject, ZbnfParseResultItem zbnfDescription, LocalIdents localIdents, StatementBlock blockEnvironment, java.lang.String sNameField, char intension, GenerateFile fileContainsClass)
          Generate an anonymous class, in Java: new Type(..){...}
protected  CCodeData gen_variableDefinition(ZbnfParseResultItem zbnfVariableDefinition, ZbnfParseResultItem zbnfDescription, LocalIdents localIdents, StatementBlock blockEnvironment, java.util.List<ClassData.InitInfoVariable> listVariablesToInit, char intension)
          Generates a variable definition with syntax of < variableDefinition>, register the variable in the LocalIdents of the class or block and registers in the list of variables to init or static variables.
protected  CCodeData genConstantValue(ZbnfParseResultItem item)
          generates constants values from parse result of the syntaxterm simpleValue.
static java.lang.String genIndent(int indent)
          generates a String with the correct indentation.
(package private)  java.lang.String get_shortDescription(ZbnfParseResultItem zbnfDescription)
          Prepares the description from the < description>parse result item.
 int getDimensionsArray(ZbnfParseResultItem zbnfType)
          Gets the info whether the type is an array type written like ident[][].
protected  ClassData getType(ZbnfParseResultItem zbnfType, LocalIdents localIdentsP)
          Provides the ClassData for the given type.
(package private)  FieldData getTypeInfoArray(ZbnfParseResultItem zbnfVariable, ZbnfParseResultItem zbnfType, ZbnfParseResultItem zbnfDescription, LocalIdents localIdentsP, java.lang.String sNameField, ClassData declaringClass, char intension, char accessMode, ClassData typeClass, char staticMode, int dimensionArray)
           
(package private)  FieldData getTypeInfoSimple(ZbnfParseResultItem zbnfVariable, ZbnfParseResultItem zbnfType, ZbnfParseResultItem zbnfDescription, LocalIdents localIdentsP, java.lang.String sNameField, ClassData declaringClass, char intension, char accessMode, ClassData typeClass, ClassData instanceClass, char staticMode, ZbnfParseResultItem itemNewObject)
           
protected  void setStop()
           
protected  void stop()
          It's a debug helper.
protected  void stopCond()
           
protected  void write_Description(ZbnfParseResultItem item, java.lang.StringBuilder uHeader)
          writes the parsed description in the H-File.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Report log

sNewLine

private static final java.lang.String sNewLine
String to generate newline and indent.

See Also:
Constant Field Values

writeContent

protected iWriteContent writeContent
A writer to file.


fileLevelIdents

protected final LocalIdents fileLevelIdents
A TreeMap of all classData sorted by classname to find all other classData. This list is complete if the second path runs.


parentGenerateFile

protected final GenerateFile parentGenerateFile

classData

protected ClassData classData
The data of this class for first and second path. A nested class will be recognized as a normal class.


sMethodNameCurrent

protected java.lang.String sMethodNameCurrent
The C-name of the current translated method, used for _Stacktrace and alloc_s_BlockHeapJc. This value is set and used inside SecondPass#write_methodDefinition(ZbnfParseResultItem, String, LocalIdents).


runRequiredFirstPass

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


stopCond

private boolean stopCond
Constructor Detail

GenerateClass

protected GenerateClass(iWriteContent writeContent,
                        GenerateFile parentGenerateFile,
                        LocalIdents fileLevelIdents,
                        RunRequiredFirstPass_ifc runRequiredFirstPass,
                        Report log)
constructs the class. This constructor is called from the superclass.

Parameters:
writeContent - The writer to the C- and H-File.
fileLevelIdents - List of all known Classes while translation Java2C
runRequiredFirstPass - Reference to run the first pass of a required class. If in the first or second pass any ClassData from another class are necessary but there was not found in pkgIdents, the first pass of this required class will called recursively while processing the pass of this class.
Method Detail

write_Description

protected void write_Description(ZbnfParseResultItem item,
                                 java.lang.StringBuilder uHeader)
                          throws java.io.IOException
writes the parsed description in the H-File.

Parameters:
item - description::= test_description::=
Throws:
java.io.IOException

gen_variableDefinition

protected CCodeData gen_variableDefinition(ZbnfParseResultItem zbnfVariableDefinition,
                                           ZbnfParseResultItem zbnfDescription,
                                           LocalIdents localIdents,
                                           StatementBlock blockEnvironment,
                                           java.util.List<ClassData.InitInfoVariable> listVariablesToInit,
                                           char intension)
                                    throws java.text.ParseException,
                                           java.io.FileNotFoundException,
                                           java.lang.IllegalArgumentException,
                                           java.io.IOException,
                                           java.lang.IllegalAccessException,
                                           java.lang.InstantiationException
Generates a variable definition with syntax of < variableDefinition>, register the variable in the LocalIdents of the class or block and registers in the list of variables to init or static variables.
The variableDefinition is used both in first and second pass of translation, in the first pass there are the class variables, in the second pass there are variables in block statement. But also arguments for method and constructor calls with the syntax of a in a argumentList::=... are translated with this method. It is the same syntax. The FieldData#gen_VariableDefinition() is called inside. The properties of the variable are stored in its FieldData, which are created here from the ZBNF parse results. So the C-code-String of variable definition is able to prepare only with knowledge of the FieldData.
There are some special cases all considered here:

Parameters:
zbnfVariableDefinition - from parsers result.
zbnfDescription - The description to the variable. If the variable is a method argument, than this description is gotten as a part of the method description after tag param. The description may contain java2c-tags. The following tags are respected:
  • zeroTermString
  • zeroTermStringTODO
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
  • zeroTermString
localIdents - The environment identifiers. Register the variable there, get types from them.
listVariablesToInit - The initialization of variables is stored in this list. The initializations should be done in C not by the variables declaration but in another part of code. For class variables that is the constructor(s). Therefore this parameter should be the ClassData.variablesToInit of this. But if this routine is called inside a statement block, an extra List instance for the block should given locally.
intension - intension of calling
  • A = argument list of declaration of a method or constructor.
  • a = argument list of definition of a method or constructor.
  • b = inside statement block
  • c = class level
  • s = static class level
Returns:
Code snipped and informations of the variables declaration.
Throws:
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException

gen_AnonymousClass

public ClassData gen_AnonymousClass(ZbnfParseResultItem zbnfNewObject,
                                    ZbnfParseResultItem zbnfDescription,
                                    LocalIdents localIdents,
                                    StatementBlock blockEnvironment,
                                    java.lang.String sNameField,
                                    char intension,
                                    GenerateFile fileContainsClass)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException,
                                    java.io.IOException,
                                    java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.text.ParseException
Generate an anonymous class, in Java: new Type(..){...}.



Parameters:
zbnfNewObject - The parse result from newObject::=...
zbnfNewObject -
zbnfDescription -
localIdents - The idents of the context, either classLevelIdents if intensio TODO always classLevelIdents.
blockEnvironment -
sNameField - The name of the field which is initialized with new Type(..){...} to build the name of the inner class, TODO name of routine.
intension - 'b' if called in an statement block, otherwise: at class level.
fileContainsClass -
Returns:
Throws:
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

get_shortDescription

java.lang.String get_shortDescription(ZbnfParseResultItem zbnfDescription)
Prepares the description from the < description>parse result item. The description is shorted to one line, but only to ". ", the first sentence.

Parameters:
parent - The item
Returns:
Description guaranteed without newline.

genConstantValue

protected CCodeData genConstantValue(ZbnfParseResultItem item)
generates constants values from parse result of the syntaxterm simpleValue. It is called if a < simpleValue> is expected, but the simpleValue should or may be a constant. At example generation a #define NAME VALUE expression in C where a final static int NAME = VALUE; is given in Java.

Parameters:
item - The part of a simpleValue what is
 [ <""?simpleStringLiteral>
 | <''?simpleCharLiteral>
 | 0x<#x?hexNumber>
 | - 0x<#x?hexNumberNegative>
 | <#-?intNumber>[?\.]
 | <#f?floatNumber>F
 | <#f?doubleNumber>
 ]
Returns:
null if it is not any of the named part, than it may be a non constant value, see syntax description in Java.zbnf, return the constant expression in C if it is a constant one.

genIndent

public static java.lang.String genIndent(int indent)
generates a String with the correct indentation.

Parameters:
indent - nr of indentation, as counter for nesting
Returns:
"\n" and the appropriate number of spaces.

getType

protected ClassData getType(ZbnfParseResultItem zbnfType,
                            LocalIdents localIdentsP)
                     throws java.io.FileNotFoundException,
                            java.lang.IllegalArgumentException,
                            java.io.IOException,
                            java.lang.IllegalAccessException,
                            java.lang.InstantiationException,
                            java.text.ParseException
Provides the ClassData for the given type. The type is given in form of a parse result item with semantic
 type::=
 [ [List|LinkedList|ArrayList|Iterator|Class][ \<  \>] 
 | [Map|TreeMap|ArrayList|Iterator|Class][ \<  \>\<  \>] 
 | 
 ] 
 [{ \[ \]}].
 
. Especially because the possibility of <envIdent?typeIdent> the requested type may be a type inside another class (an inner class, Outerclass.Innerclass), so this class should be provided before, and the type should be searched there. In all cases a useable ClassData-instance is returned.

Parameters:
zbnfType - The zbnf-component with syntax type::=....
localIdents - The idents of this level.
Returns:
The ClassData of the type.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
java.text.ParseException

getDimensionsArray

public int getDimensionsArray(ZbnfParseResultItem zbnfType)
Gets the info whether the type is an array type written like ident[][].

Parameters:
zbnfType - The ZBNF parse result for a type.
Returns:
0 if [] isn't found (parse result typeArray isn't present, >0 if it is a array type.

createFieldInfo

public FieldData createFieldInfo(ZbnfParseResultItem zbnfVariable,
                                 ZbnfParseResultItem zbnfType,
                                 ZbnfParseResultItem zbnfDescription,
                                 ZbnfParseResultItem zbnfNewObject,
                                 LocalIdents localIdentsP,
                                 StatementBlock blockEnvironment,
                                 ClassData declaringClass,
                                 char intension,
                                 char definitionCondition)
                          throws java.lang.IllegalAccessException,
                                 java.lang.InstantiationException,
                                 java.io.FileNotFoundException,
                                 java.lang.IllegalArgumentException,
                                 java.io.IOException,
                                 java.text.ParseException
Prepare the type properties from a given ZBNF type::= or adequate info. The type properties are stored in a new FieldData, but without field name. The type properties includes array designation and some Java2CTag.

Parameters:
zbnfVariable - It may be null, if only the type informations should be kept. The ZBNF result which presents a variable definition. Some informations about the type of variable are contained in that level of parse result, like new Array[length], final, a static initialization etc.
zbnfType - The ZBNF result which presents type::= or nonArrayType::= or typeIdent::=
zbnfDescription - The ZBNF result which presents the description part to the type. If it is a variable definition, it is the description to the them. But if it is a argument or return type of a method, it is that part of the description of the method, which describes the param or return. It may contain a <$?Java2CTag> to the type element. This param may be null, if no description of them is available.
zbnfNewObject - maybe given, to create a stack or embedded instance.
localIdentsP - The local visible identifiers.
intension -
Returns:
A new instance of FieldData containing all type informations, but without name of field and without any instance informations like fix size of array etc.
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException - from called getType(ZbnfParseResultItem, LocalIdents).
java.text.ParseException
Since:
2009-06-27

getTypeInfoSimple

FieldData getTypeInfoSimple(ZbnfParseResultItem zbnfVariable,
                            ZbnfParseResultItem zbnfType,
                            ZbnfParseResultItem zbnfDescription,
                            LocalIdents localIdentsP,
                            java.lang.String sNameField,
                            ClassData declaringClass,
                            char intension,
                            char accessMode,
                            ClassData typeClass,
                            ClassData instanceClass,
                            char staticMode,
                            ZbnfParseResultItem itemNewObject)
                      throws java.io.FileNotFoundException,
                             java.lang.IllegalArgumentException,
                             java.io.IOException,
                             java.lang.IllegalAccessException,
                             java.lang.InstantiationException,
                             java.text.ParseException
Throws:
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

createFieldDataNewObject

FieldData createFieldDataNewObject(ZbnfParseResultItem zbnfNewObject,
                                   ZbnfParseResultItem zbnfDescription,
                                   LocalIdents typeIdentsForNew,
                                   LocalIdents localIdentsP,
                                   StatementBlock blockEnvironment,
                                   java.lang.String sNameField,
                                   ClassData declaringClass,
                                   char intension,
                                   char accessModeP,
                                   char staticMode,
                                   boolean isFinal)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException,
                                    java.io.IOException,
                                    java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.text.ParseException
Creates FieldData for a new Type(...)-construction. If a variable is initialized with the new-construction, it may be an embedded instance, or a instance from a given implementation class or others. This things are detected by evaluating the java2c=annotation in the zbnfDescription, or in zbnfNewObject. Then this method returns the complete FieldData for the variable.

If a new-construction is used in an expression, the param sNameField in null. But the other informations in FieldData may be a point of interesting, so the adequate form is able to use.

Parameters:
zbnfNewObject - The parse result from expression newObject::=.
zbnfDescription - The description to the variable
typeIdentsForNew -
localIdentsP - The environment for parameters. -not for the new Object.
sNameField - name of variable
declaringClass - The class where the FieldData should be associated to. May be null for statementblock-fields or new in Expression.
intension -
accessModeP -
staticMode -
isFinal -
Returns:
Throws:
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

getTypeInfoArray

FieldData getTypeInfoArray(ZbnfParseResultItem zbnfVariable,
                           ZbnfParseResultItem zbnfType,
                           ZbnfParseResultItem zbnfDescription,
                           LocalIdents localIdentsP,
                           java.lang.String sNameField,
                           ClassData declaringClass,
                           char intension,
                           char accessMode,
                           ClassData typeClass,
                           char staticMode,
                           int dimensionArray)
                     throws java.io.FileNotFoundException,
                            java.lang.IllegalArgumentException,
                            java.io.IOException,
                            java.lang.IllegalAccessException,
                            java.lang.InstantiationException,
                            java.text.ParseException
Throws:
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException

stop

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


setStop

protected void setStop()

stopCond

protected void stopCond()