public class Docu.F_Translation_Secondpass extends java.lang.Object
Constructor and Description |
---|
Docu.F_Translation_Secondpass() |
Modifier and Type | Method and Description |
---|---|
void |
f1_referencesOrEnvironmentTypes()
In Java a environment-type for a static method and a reference of a dynamic method are not differenced.
|
void |
f2_casting()
There are four types of castings, it is the combination of
implicitly or explicitly casts,
casts of scalar types (int etc) or reference types.
|
void |
f3_methodCall_WithParameterSensitivity()
Methods in Java are parameter sensitive.
|
void |
f4_methodCallWithVariableArguments()
Variable arguments are known both in Java and in C.
|
void |
f5_methodCallFromSuperClasses() |
void |
f6_methodCallFromOuterClasses() |
void |
f7_constructorCall()
A constructor is either a static method of the associated class, or it is understand as
a non-static method of the outer class, if the class is an non-static inner class.
|
void |
f9_intension_of_call()
The translation process of details should know informations about its environment of call.
|
public Docu.F_Translation_Secondpass()
public void f1_referencesOrEnvironmentTypes()
Arrays.binarySearch(..) //an example of static method of class Arrays myInstance.method(...) //a normal class method call.The difference is detectable only searching the identifier in translator tables. Therefore the identifier is tested in the method in
StatementBlock#gen_reference(String[], ZbnfParseResultItem, LocalIdents, char, IdentInfos[] retIdentInfo)
.
The got association String from ZBNF-parse-result is tested calling LocalIdents.getType(String, LocalIdents)
in the given local environment. It includes especially standard types,
but also local types in the class definition and the file-level types (package and import).
If the association String is recognized as Type, the associated type is used in the next reference levels
respectively it is returned in parameter retIdent. Because that type is the base type info for searching
the referenced identifier, the method calls in C are translated with the name_Type-info.public void f2_casting()
&ref->base.super.base.super
instead an equivalent (SuperType*)(ref)
. The machine code is equal for both variants.
assert(ref instance of Type);
.
It will be translated and executed in C too, and it is conspicuously and should sufficing for a safety software check.
#methodCall_WithParameterSensitivity()
.
it should be tested if a given argument is matching to formal argument types.
The method ClassData.matchedToTypeSrc(ClassData)
is provided for such check.
&ref->embeddedInstance
.
Additionally there are some special cases like a StringJc
or OS_TimeStamp
,
which are taken as value arguments and returned as values in methods.
FieldData.testAndcast(CCodeData, char)
produces the correct expression
with given C-code including type and access mode of it in respect to a given field-type-description.
It is used at any assignments: method arguments, return value preparation and value assignments.
At example in Java it is coded ref-embeddedInstance
, but a parameter or destination
variable is of an base or interface type. Than the method returns the necessary adaption
for C language in form &(ref->embeddedInstance.base.IfcType)
.
FieldData.testAndChangeAccess(char, String, char)
produces the correct expression
if only an access should be changed.
StatementBlock.gen_AssignCheckCast(CCodeData, String, CCodeData)
.
ClassData.addCastFromType(ClassData, String, String)
and ClassData.addCastToType(ClassData, String, String)
adds a possibility of cast
to the a class. It is used explicitely for standard types,
but also for declaring the possibility of access super and interface types,
see Docu.SuperClassesAndInterfaces
.
It is called inside ClassData.fillMethodsOverrideable(ClassData.InheritanceInfo inheritanceInfo, String sPathToMtbl, String sPathToBase)
public void f3_methodCall_WithParameterSensitivity()
append(int value)
is another method as
append(String value)
.
It is clear for Java users. Okay. In C++ it is the same concept.
methodname_classname
.
StatementBlock#gen_value(ZbnfParseResultItem, char)
.
The type is returned in its CCodeData
-return data.
The type of a value is build from
StatementBlock#gen_variable(org.vishia.zbnf.ZbnfParseResultItem, LocalIdents, char, CCodeData)
CCodeData
-return data.
GenerateClass#genConstantValue(org.vishia.zbnf.ZbnfParseResultItem)
.
The type of the constant value is detect while parsing the Java source code. The type of a numeric value
is detect additional by testing the value range of the number. Especially the type of an string literal
in "string" is designated as Java2C_Main.CRuntimeJavalikeClassData#clazz_s0
.
The s0
means, C-like 0-terminated string. It is a special case of a String represented by
{ Java2C_Main.CRuntimeJavalikeClassData#clazzStringJc
.
StatementBlock#gen_simpleMethodCall(org.vishia.zbnf.ZbnfParseResultItem, CCodeData, LocalIdents)
.
StatementBlock#gen_newObject(org.vishia.zbnf.ZbnfParseResultItem, LocalIdents)
or StatementBlock#gen_newArray(org.vishia.zbnf.ZbnfParseResultItem, ClassData[], LocalIdents)
.
StatementBlock#gen_simpleMethodCall(org.vishia.zbnf.ZbnfParseResultItem, CCodeData, LocalIdents)
.
While translating the actual parameters are read from the ZbnfParseResultItem. The values are generated
calling StatementBlock#gen_value(org.vishia.zbnf.ZbnfParseResultItem, char)
.
This method returns the type of the parameters. The types are used to search the method.
ClassData#searchMethod(String sNameJava, java.util.List paramsType)
is called with the ClassData
-instance of the environment type.
That is the type of the instance in Java left from point of method call. This ClassData are referenced from
the parameter envInstanceInfo
of gen_simpleMethodCall()
.
If the environment instance is this
, the envInstanceInfo
came from
ClassData.classTypeInfo
of the own ClassData-Instance.
ClassData.matchedToTypeSrc(ClassData)
arbitrates whether the type is compatible. Than it is possible that a cast expression
is necessary in C, without though an automatic casting in Java is done.
The cast expression is generated in
StatementBlock#gen_simpleMethodCall(org.vishia.zbnf.ZbnfParseResultItem, CCodeData, LocalIdents)
.
Java2C_Main.CRuntimeJavalikeClassData
- constructor. It is hand-made.
FirstPass#runFirstPassFile(String, org.vishia.zbnf.ZbnfParseResultItem, String, ClassData, java.util.List, LocalIdents)
.
ClassData.testAndSetAmbiguousnessOfMethod(String)
is called with the java name of the method. If more as one method with the same name is found,
the method name is ambiguous. Only than a complex method name for C should be built.
FirstPass#wrwrite_methodDeclaration(ZbnfParseResultItem parent, String sClassName, LocalIdents
.
In this routine it is known whether or not the method is ambiguous, because all methods are tested before.
FirstPass#gen_methodHeadAndRegisterMethod(org.vishia.zbnf.ZbnfParseResultItem, String, String, FieldData, boolean)
,
is called. In this routine the C-method-name is build either with argument-type-naming parts or not.
The argument-type-naming parts of the C-method-name are simple chars for standard types,
see registration of standard types in Java2C_Main.CRuntimeJavalikeClassData
,
calling the constructor of ClassData#ClassData(String, String, String, String, String)
.
A short name for user-Type-arguments is built with prominent chars of the type,
testing its unambiguously in global scope.
ClassData#addMethod(String, String, FieldData, FieldData[])
.
public void f4_methodCallWithVariableArguments()
printf("values: %3.3f, %4d\n", floatValue, intValue);
. It is classic.
Because the type of values may not correct (float or double, long, short), the compiler
may convert a float value in double etc. to prevent errors. The originally idea was
to determine the fine specification of the type with modifiers such as %3hd
for short.
But already float and double are not possible to difference. Some compilers operates variedly.
That is C/C++.
method(Object ...){...} //declaration of a method method(5, 3.4, intVal, classInstance); //call of method.Java2C generated a type String as argument before a variable argument list in any case. The type String contains the detect type of any actual argument as one letter. Especially the primitive and some Standard types are detect in this way. All complex types are supplied as ObjectJc. Therefore the method from example above has the following representation in C:
method(char const* typeArgs, ...); //declaration of method method("IDIL", 5, 3.4, intVal, classInstance); //call...TODO
public void f5_methodCallFromSuperClasses()
public void f6_methodCallFromOuterClasses()
public void f7_constructorCall()
ClassData#searchMethod(String, java.util.List, boolean)
,
where the name is
ClassData.isNonStaticInner
is checked.
This rules are regarded in
StatementBlock#genInitEmbeddedInstance(org.vishia.zbnf.ZbnfParseResultItem, org.vishia.zbnf.ZbnfParseResultItem, FieldData, String, int)
StatementBlock#gen_newObject(org.vishia.zbnf.ZbnfParseResultItem, CCodeData, LocalIdents)
ClassData#searchMethod(String, java.util.List, boolean)
.public void f9_intension_of_call()
Ccmbzf=RrelaAtisPYxu | method |
-------------------- | SecondPass#gen_statementBlock(org.vishia.zbnf.ZbnfParseResultItem, int, org.vishia.java2C.StatementBlock, FieldData, char) |
-cmb-f-----aA------- | SecondPass#gen_variableDefinition(org.vishia.zbnf.ZbnfParseResultItem, org.vishia.zbnf.ZbnfParseResultItem, LocalIdents, java.util.List, char) |
C--------------s---- | GenerateClass#gen_AnonymousClass(org.vishia.zbnf.ZbnfParseResultItem, LocalIdents, String, char, GenerateFile) |
Ccmb------------P--- | FirstPass#buildType(StringBuilder, String, GenerateFile, String, String, String, String, org.vishia.zbnf.ZbnfParseResultItem, boolean, String, ClassData, java.util.List, boolean, ClassData, char) |
Ccmb------------PYx- | ClassData#ClassData(String, GenerateFile, String, String, String, String, String, char, ClassData, ClassData, ClassData[], org.vishia.zbnf.ZbnfParseResultItem, String, char, LocalIdents) |
---------ela-------u | StatementBlock#gen_simpleValue(org.vishia.zbnf.ZbnfParseResultItem, org.vishia.zbnf.ZbnfParseResultItem, org.vishia.zbnf.ZbnfParseResultItem, LocalIdents, boolean, char, boolean) |