public class SecondPass extends java.lang.Object
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.Modifier and Type | Field and Description |
---|---|
protected org.vishia.java2C.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 org.vishia.mainCmd.Report |
log |
protected GenerateFile |
parentGenerateFile |
protected java.lang.String |
sMethodNameCurrent
The C-name of the current translated method, used for _Stacktrace and alloc_s_BlockHeapJc.
|
static java.lang.String |
sVersion
Version, history and license.
|
protected org.vishia.java2C.iWriteContent |
writeContent
A writer to file.
|
Modifier and Type | Method and Description |
---|---|
FieldData |
createFieldInfo(ZbnfParseResultItem zbnfVariable,
ZbnfParseResultItem zbnfType,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfAnnotation,
ZbnfParseResultItem zbnfNewObject,
LocalIdents localIdentsP,
StatementBlock blockEnvironment,
org.vishia.java2C.ClassData declaringClass,
char intension,
char definitionCondition)
Prepare the type properties from a given ZBNF
type::= or adequate info. |
org.vishia.java2C.ClassData |
gen_AnonymousClass(ZbnfParseResultItem zbnfNewObject,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
LocalIdents localIdents,
StatementBlock blockEnvironment,
java.lang.String sNameField,
char intension,
GenerateFile fileContainsClass)
Generate an anonymous class, in Java:
new Type(..){...} . |
java.lang.String |
gen_for_statement(ZbnfParseResultItem zbnfStatement,
int indent,
StatementBlock parentStatementBlock,
FieldData typeReturn) |
protected CCodeData |
gen_variableDefinition(ZbnfParseResultItem zbnfStatement,
ZbnfParseResultItem zbnfDescription,
LocalIdents localIdents,
StatementBlock blockEnvironment,
java.util.List<org.vishia.java2C.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(boolean isDefine,
int indent)
generates a String with the correct indentation.
|
int |
getDimensionsArray(ZbnfParseResultItem zbnfType)
Gets the info whether the type is an array type written like
ident[][] . |
protected org.vishia.java2C.ClassData |
getType(ZbnfParseResultItem zbnfType,
LocalIdents localIdentsP)
Provides the
ClassData for the given type. |
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.
|
void |
write_finalizeDefinition(ZbnfParseResultItem zbnfClass,
java.lang.String sClassName,
LocalIdents idents) |
void |
write_methodDefinition(org.vishia.java2C.ClassData.MethodWithZbnfItem methodDef,
java.lang.String sClassName,
LocalIdents parentIdents)
writes a method definition as C-method into the C-File.
|
public static final java.lang.String sVersion
|kPtrVal_Modifier_reflectJc
in the reflection on FieldData.modeAccess
== 'M'.
protected final org.vishia.mainCmd.Report log
protected org.vishia.java2C.iWriteContent writeContent
protected final LocalIdents fileLevelIdents
protected final GenerateFile parentGenerateFile
protected org.vishia.java2C.ClassData classData
protected java.lang.String sMethodNameCurrent
SecondPass#write_methodDefinition(ZbnfParseResultItem, String, LocalIdents)
.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
java.text.ParseException
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
public void write_methodDefinition(org.vishia.java2C.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
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.
Type* thiz
as first and ThCxt* _thCxt
as last argument of method head.
gen_variableDefinition(ZbnfParseResultItem, LocalIdents, List, char intension)
to generate the arguments of the constructor, in Java2C.zbnf < argumentList>
and < argument>
{ StacktraceJc stacktrace...
-expressions.
StatementBlock#gen_statementBlock(ZbnfParseResultItem, int, LocalIdents)
is used to generate the statement block of the constructor.
RunRequiredFirstPass_ifc#runRequestedFirstPass(String)
.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 thiz-type and as C-method-identifier-postfix.java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
public java.lang.String gen_for_statement(ZbnfParseResultItem zbnfStatement, 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
java.text.ParseException
java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
protected void write_Description(ZbnfParseResultItem item, java.lang.StringBuilder uHeader) throws java.io.IOException
item
- description::= test_description::=java.io.IOException
protected CCodeData gen_variableDefinition(ZbnfParseResultItem zbnfStatement, ZbnfParseResultItem zbnfDescription, LocalIdents localIdents, StatementBlock blockEnvironment, java.util.List<org.vishia.java2C.ClassData.InitInfoVariable> listVariablesToInit, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
argumentList::=...
are translated with this method.
It is the same syntax.
LocalIdents
are given per reference, it is either the instance of this classData
or the instance of the block-statement.
classData
.ClassData.staticVariables
. Static variables are only able at class level.
Static variables may have an initialization or not.
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
.
final static
variable with a immediate simple assignment like
final static int name = 5;
, a #define name_Classname 5
is produced.
final Type ... = new Type(...)
, an embedded struct is defined in C.
That's correct, because a final reference can't be changed and the reference type is equal the
instanciated type. Embedded struct constructs are opportune in C to optimize access and
memory layout of the data.
struct Type_t* ...
or with using an enhanced reference like Type_REF ...
. All enhanced references
are defined together in 1 headerfile In form typedef struct NAMEREF_t { ObjectRefValuesJc refbase; struct NAME_t* ref; } NAMEREF;, see
referenceNeeded()
and Java2C_Main.writeFileRef()
.
NOTE 2014-01-12: it is wrong that All enhanced references are defined together in 1 headerfile.
This fact was changed. TODO description
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
zeroTermString
TODO
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
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public org.vishia.java2C.ClassData gen_AnonymousClass(ZbnfParseResultItem zbnfNewObject, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, 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
new Type(..){...}
.
FirstPass#runFirstPassClass(StringBuilder, GenerateFile, String, String, String, String, ZbnfParseResultItem, boolean, String, ClassData, List, boolean, ClassData)
.
FirstPass#writeCtor(...)
runSecondPassClass(ZbnfParseResultItem, String)
is called.
The content of this second-pass is written using TODO before the running second-pass.
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
- java.io.FileNotFoundException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.text.ParseException
protected CCodeData genConstantValue(ZbnfParseResultItem item)
#define NAME VALUE
expression in C where a
final static int NAME = VALUE;
is given in Java.item
- The part of a simpleValue what is
[ <""?simpleStringLiteral> | <''?simpleCharLiteral> | 0x<#x?hexNumber> | - 0x<#x?hexNumberNegative> | <#-?intNumber>[?\.] | <#f?floatNumber>F | <#f?doubleNumber> ]
public static java.lang.String genIndent(boolean isDefine, int indent)
indent
- nr of indentation, as counter for nestingprotected org.vishia.java2C.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
ClassData
for the given type. The type is given in form of a parse result item
with semantic
type::= [ [List|LinkedList|ArrayList|Iterator|Class][ \<. Especially because the possibility of\>] | [Map|TreeMap|ArrayList|Iterator|Class][ \< \>\< \>] | ] [{ \[ \]}].
<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.
ClassData
with the given key are found,
starting in the LocalIdents
of the current context, further searching in the
Java2C_Main#userTypes
and the Java2C_Main.standardClassData
,
if necessary searched as inner type. It are one or some simple accesses to the appropriate
LocalIdents
.
<envIdent?typeIdent>
)
isn't found, it is possible that this type isn't translated yet, but it is a part of the
users type.java
sources to translate. In this case a type.java
-file
should be part of input files, given with cmd line arguments -i:FILE
or
inside the -if:INPFILE
. Therefore
RunRequiredFirstPass_ifc#runRequestedFirstPass(String type)
is called.
This routine either processes the parsing and first pass of translation for that file,
or it parses the appropriate type.stc
File and provides therewith
the ClassData
. The parsing is a deep recursively process, because other types
are need too. This routine is called than recursively.
type.java
-File in the Java sources exists. In both cases
a new ClassData
with attribute "external" is created.
ClassData
-instance is returned.zbnfType
- The zbnf-component with syntax type::=...
.localIdents
- The idents of this level.java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
java.text.ParseException
public int getDimensionsArray(ZbnfParseResultItem zbnfType)
ident[][]
.zbnfType
- The ZBNF parse result for a type.[]
isn't found (parse result typeArray
isn't present,
>0 if it is a array type.public FieldData createFieldInfo(ZbnfParseResultItem zbnfVariable, ZbnfParseResultItem zbnfType, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfAnnotation, ZbnfParseResultItem zbnfNewObject, LocalIdents localIdentsP, StatementBlock blockEnvironment, org.vishia.java2C.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
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.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.zbnfAnnotation
- The ZBNF result which presents the whole statement. if it is a variable definition this arg is equal zbnfVariable.
If it is a method definition this is the method definition statement. This result item is used to check Java4C-annotations which are regarded to the type
of the variable or the return type of the method.zbnfNewObject
- maybe given, to create a stack or embedded instance.localIdentsP
- The local visible identifiers.intension
- 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
protected void stop()
protected void setStop()
protected void stopCond()