public class StatementBlock extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
int |
blockNestingCnt
The deepness of block nesting.
|
boolean |
lastWasReturn
Saves, whether the last generated statement is a return.
|
LocalIdents |
localIdents
The identifiers valid at this block level.
|
static java.lang.String |
sVersion
Version, history and license.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
gen_ActivateGarbageCollection(int indent,
boolean bRet,
CCodeData cCodeReturn)
generates the statement for
activateGC_ObjectJc() . |
java.lang.String |
gen_assignment(ZbnfParseResultItem zbnfStatement,
ZbnfParseResultItem zbnfDescription,
int indent,
LocalIdents localIdents,
char intension)
generates an assignment-statement from given parse result item < statement>.
|
java.lang.String |
gen_newArray(ZbnfParseResultItem zbnfNewArray,
org.vishia.java2C.ClassData[] retTypeValue,
LocalIdents idents,
FieldData variable)
generates the expression for a new Type[...] expression.
|
java.lang.String |
gen_newObj()
Returns a new identifier for a newObject.
|
java.lang.String |
gen_persistringVariable()
Returns a new identifier for a persistent String.
|
CCodeData |
gen_simpleValue(ZbnfParseResultItem zbnfItem,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
LocalIdents localIdents,
boolean maybeNonPersistent,
char intension,
boolean bRefNeed)
generates the code for ZBNF-< simpleValue>.
|
java.lang.String |
gen_statement(ZbnfParseResultItem zbnfParentStatement,
ZbnfParseResultItem zbnfParentDescription,
int indent,
LocalIdents localIdents,
FieldData typeReturn,
char intension)
generates a statement from given parse result item < statement>.
|
static java.lang.String |
gen_statementBlock(ZbnfParseResultItem zbnfStatementBlock,
ZbnfParseResultItem zbnfDescriptionBlock,
int indent,
StatementBlock parentBlock,
FieldData typeReturn,
org.vishia.java2C.GenerateClass classFrame,
char intension)
Generates C-code from a parsed statement block.
|
java.lang.String |
gen_StringAssignment(int indent,
CCodeData leftValue,
java.lang.String sAssignOperatorC,
ZbnfParseResultItem zbnfValue,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
LocalIdents localIdents,
char intension)
Generates an assignment to a String.
|
java.lang.String |
gen_tempString()
Counts the
#nrof and returns the name of a reference for new Objects. |
java.lang.String |
gen_throwNew(ZbnfParseResultItem zbnfStatement,
ZbnfParseResultItem zbnfDescription,
LocalIdents localIdents,
FieldData typeReturn)
generates the expression for a
|
java.lang.String |
gen_try_statement(ZbnfParseResultItem zbnfStatement1,
int indent,
LocalIdents localIdents)
generates the expression for a < try_Statment> .
|
CCodeData |
gen_value(ZbnfParseResultItem parent,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
boolean maybeNonPersistent,
char intension)
generates the expression to get a value.
|
java.lang.String |
gen_value(ZbnfParseResultItem zbnfCondition,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
org.vishia.java2C.ClassData[] retType,
LocalIdents localIdents,
boolean maybeNonPersistent,
char intension) |
CCodeData |
gen_variableAccess(ZbnfParseResultItem itemVariable,
ZbnfParseResultItem zbnfDescription,
ZbnfParseResultItem zbnfStatement,
LocalIdents localIdents,
char intension,
CCodeData cCodeReferenceInput)
generates an access to a value in a variable or a using of a variable as left value.
|
java.lang.String |
gen_VariableInitAssignment(ZbnfParseResultItem zbnfStatement,
int indent)
generates the initial assignments to variables.
|
public static final java.lang.String sVersion
FieldData.modeAccess
=='M' for code generation.
gen_throwNew(ZbnfParseResultItem, ZbnfParseResultItem, LocalIdents, FieldData)
for the text expression
used to use text buffer in thread context in gen_ConcatenatedStrings(String, ClassData, char, Iterator, ZbnfParseResultItem, ZbnfParseResultItem, String, LocalIdents, boolean)
.
The annotation Java4C.StringBuilderInThreadCxt
is not necessary for that up to now. Strings for Exception texts are prepared always in the thread context.
It is not possible to prepare them in a special buffer because there is not a buffer. The exception handling should be executed without additional effort.
The catch of an exception removes the String from the thread context always.
fieldsNonStatic
and fieldsStatic
now stored as instance data used in FirstPass.gatherAllDefinitions()
for ClassLevelIdents.
public final int blockNestingCnt
public boolean lastWasReturn
public LocalIdents localIdents
public static java.lang.String gen_statementBlock(ZbnfParseResultItem zbnfStatementBlock, ZbnfParseResultItem zbnfDescriptionBlock, int indent, StatementBlock parentBlock, FieldData typeReturn, org.vishia.java2C.GenerateClass classFrame, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
GenerateClass#gen_variableDefinition(ZbnfParseResultItem, LocalIdents, List, char)
.
It should be done first because in C all variable should be define on the begin of a block.
The variable identifiers and types are stored in a local copy of LocalIdents
, which are intialized
with the content of the localIdentsP given as argument, which comes either from the parent block or from the class.
#gen_VariableInitAssignment(ZbnfParseResultItem, int, LocalIdents)
.
It is separated from the variable definition and it isn't implemented as initializing of variable,
because in Java there are more variants. In C the type name = value;
is an initializing of the variable,
but type name; ...; name = value;
it is an assignment. It is a fine difficult explainable difference.
The Java2C produce assignments, not initializing.
#gen_statement(ZbnfParseResultItem, int, LocalIdents)
.
Therefore a separate String variable is used, because MemC-elements, see next:
new
-statements, the MemC
definitions are generated.
They are named with a incremental number. They are placed after the variable definitions of the block
but before the statements. This is necessary because the MemC memX
is an variable also.
activateGC_ObjectJc(memX,...)
is generated for all MemC-elements.
The MemC-Elements are countered on level of the statement block, represented by this class.
This is also done in #gen_statement(ZbnfParseResultItem, int, LocalIdents)
before a return
statement.
It is not done if the last statement was a return
.
Thats why it is done with an extra method #gen_ActivateGarbageCollection(int)
.
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.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_statement(ZbnfParseResultItem zbnfParentStatement, ZbnfParseResultItem zbnfParentDescription, int indent, LocalIdents localIdents, FieldData typeReturn, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
get_description(ZbnfParseResultItem)
gen_assignment(ZbnfParseResultItem, int indent, LocalIdents)
is be called immediate.
gen_statementBlock(ZbnfParseResultItem, int indent, LocalIdents)
is be called immediate with a new instance of StatementBlock
.
gen_value(ZbnfParseResultItem, LocalIdents, char)
.
As well as the condition occupies more as one line in Java, in C it is written yet in one line.
Typically it is a suitable behavior. But if the condition expression is complex,
it is not so ideal in C. The reason for this behavior: The parser ignore new lines,
all are white spaces. The C-code is correct, but possibly not ideal readable. It is a good style
for writing comprehensible code separating a complex expressions in smaller parts.
To divide a conditional expression in smaller parts, some local boolean variable may be used.
It is anyhow effective at machine level.
if(...)
in the same line.
But typically it is a statement block, and will be written in extra lines with the correct indentation.
else if(...)
is given in Java, the if(...)
after else
is a simple statement. Therefore it was be produced as else if(...)
also in C.
It can be understand as a chain of if.
StacktraceJc
.
The gen_ActivateGarbageCollection(int)
is called
because the statement block may contain one or some new-Statements.
gen_simpleValue(ZbnfParseResultItem, LocalIdents, char intension)
is called with intension='m'. The methodcall is translated like a simple value,
it is syntactically the same. (void-value).
gen_throwNew(ZbnfParseResultItem, LocalIdents)
is be called.
break
is generated.
It are the same relations in Java likewise in C.
parent
- The ZBNF parse result item which is a < statement>indent
- Number of nesting level of the block to generate indentations of a line.localIdents
- The indentation of the block: TODO use it as class element.typeReturn
- The return type of the superior method if it contains a return statement.intension
- Intension of call: 'c'-constructor body, 'm'-method body, 'b'-internal block, 'z'-part of if, while etc., 'f'-finalize body.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_newObj()
nrofNew
thereby.public java.lang.String gen_persistringVariable()
nrofPersistentStrings
thereby.public java.lang.String gen_tempString()
#nrof
and returns the name of a reference for new Objects.public java.lang.String gen_ActivateGarbageCollection(int indent, boolean bRet, CCodeData cCodeReturn)
activateGC_ObjectJc()
.
This is placed on end of a statement block or before an return
-statement,
if inside new-statements are generated.indent
- number of indentations. 2 spaces per indentation are produced.public java.lang.String gen_assignment(ZbnfParseResultItem zbnfStatement, ZbnfParseResultItem zbnfDescription, int indent, LocalIdents localIdents, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
gen_variable(ZbnfParseResultItem, LocalIdents , char intension, LocalIdents.IdentInfos[] retIdentInfo)
with intension='='. The argument retIdentInfo is a call by returned reference.
The returned object contains informations about the kind of the left-value variable,
especially if it is an enhanced reference.
gen_value(ZbnfParseResultItem, LocalIdents, char intension)
with intension='e'.
clearBackRefJc(variable)
is produced before the new reference is set to it, and setBackRefJc(variable)
after it is set. This subroutines implement the necessities of Garbage Collection for that enhanced references.zbnfAssignment
- The ZBNF parse result item which is a < assignment>indent
- Number of nesting level of the block to generate indentations of a line.localIdents
- The indentation of the block: TODO use it as class element.intension
- Intension of call: 'c'-constructor body, 'm'-method body, 'b'-internal block, 'z'-part of if, while etc., 'f'-finalize body.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_StringAssignment(int indent, CCodeData leftValue, java.lang.String sAssignOperatorC, ZbnfParseResultItem zbnfValue, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, LocalIdents localIdents, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
indent
- sVariableC
- typeLeftValue
- sAssignOperatorC
- sValueC
- typeValue
- intension
- Intension of call: 'c'-constructor body, 'm'-method body, 'b'-internal block, 'z'-part of if, while etc., 'f'-finalize body.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public CCodeData gen_variableAccess(ZbnfParseResultItem itemVariable, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, LocalIdents localIdents, char intension, CCodeData cCodeReferenceInput) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
thiz->
is written before.
thiz->super.
is written before.
thiz->outer->
is written before.
->
or .
,
depended on the reference kind. It may be an embedded struct.
The LocalIdents of the referencing object are used to desire it.
REFJc(variable)
is generated to get the stored reference as value.
REFJc(variable)
is a Macro to get the reference pointer inside an enhanced referende.
Especially if it is left value, the code of enhanced reference itself is generated.
itemVariable
- The ZBNF parse result item of the < ?variable>-semantic.
It is a part of a simpleValue-syntax-prescript.localIdents
- The Identifier info of the environment.intension
- Info about the location respectively cause to call this method.
e-expression R-first reference r-nested reference =:leftvalue ...retIdentInfo
- information about the variable in its context.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_value(ZbnfParseResultItem zbnfCondition, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, org.vishia.java2C.ClassData[] retType, LocalIdents localIdents, boolean maybeNonPersistent, char intension) 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 CCodeData gen_value(ZbnfParseResultItem parent, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, boolean maybeNonPersistent, char intension) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
{ [|< unaryOperator>] < simpleValue?> ? < binaryOperator> }
.
Therefore #gen_simpleValue(ZbnfParseResultItem, LocalIdents, char)
is called inside.
All components of the < value> are processed in one while-loop because it is stored one after another.
That includes also the [< ?conditional>...
construct
in which is this method is called recursively.
parent
- The parse result item which has the semantic <...?value>.intension
- intension of generating:
Docu.F_Translation_Secondpass.f9_intension_of_call()
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
java.lang.InstantiationException
public CCodeData gen_simpleValue(ZbnfParseResultItem zbnfItem, ZbnfParseResultItem zbnfDescription, ZbnfParseResultItem zbnfStatement, LocalIdents localIdents, boolean maybeNonPersistent, char intension, boolean bRefNeed) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
#gen_variable(ZbnfParseResultItem, LocalIdents, char, org.vishia.java2C.FieldData[])
,
but a < variable> can be more as that, especially a left value. This is not considered here.
this
or super
.
#gen_newObject(ZbnfParseResultItem, CCodeData, LocalIdents)
.
#gen_simpleMethodCall(ZbnfParseResultItem, String, org.vishia.java2C.FieldData, LocalIdents)
is called.
zbnfItem
- One of the alternatives in simpleValue::=...
localIdents
- of the environmentintension
- calling intension.java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_newArray(ZbnfParseResultItem zbnfNewArray, org.vishia.java2C.ClassData[] retTypeValue, LocalIdents idents, FieldData variable) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
gen_newObj()
.
The variable nrofNew
is used and incremented for that.
zbnfNewArray
- The zbnf parse result item of the < newObject>idents
- The identifier of the environment.variable
- The variable to assign to, or nulljava.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_try_statement(ZbnfParseResultItem zbnfStatement1, int indent, LocalIdents localIdents) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
zbnfThrowNew
- localIdents
- java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_throwNew(ZbnfParseResultItem zbnfStatement, ZbnfParseResultItem zbnfDescription, LocalIdents localIdents, FieldData typeReturn) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
zbnfThrowNew
- localIdents
- java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException
public java.lang.String gen_VariableInitAssignment(ZbnfParseResultItem zbnfStatement, int indent) throws java.text.ParseException, java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
#gen_statementBlock(ZbnfParseResultItem , int, StatementBlock, ClassData, char)
zbnfVariableDefinition
- Item of < variableDefinition>java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
java.lang.IllegalArgumentException
java.io.FileNotFoundException