public abstract class GenericCompiler
extends eu.bandm.tools.formatfrontends.absy.Visitor
initTransformerClass(GeneratedClass)
on this class.
visit()
methods for all the
specific language constructs.
compileOnePattern(Element_pattern)
for
each expression it wants to translate. This method intializes internal
registers, calls visit()
, and finally relocates all constant expressions
to initializer blocks.fresult
,
The caller has to store this code in the generated class according to its need.
fresult
(read/write) holding the code = translation result.
("f-result" = "functional result"),
isdynamic
(read/write) must be set by custom code to true
in most cases, ie. when the constructed format will not be constant, but
will depend on the data.
checkedmode
(read) if we are at the left of some "?
"
operator,
GenericCompiler.Subformat
can be defined. This class reduces all
relevant
parameters from the font-end constructs for aggregates (fold operators,
code, etc.) into interal values and stores them, for easy recursion.
Modifier and Type | Class and Description |
---|---|
protected class |
GenericCompiler.Subformat
A sub-parser which extracts the list format description
for a sub-object which is an aggregate,
and stores them locally, for ease of recursion.
|
Modifier and Type | Field and Description |
---|---|
Format |
callFunctionForRaisingException
format for calling the method which throws
TakeAlternativeException ,
cf NAME_METHOD_THROW_TAKE_ALTERNATIVE . |
protected boolean |
checkedmode
are we currently visiting left part of a "?" operator ?
|
protected Map<String,Format> |
constcache
Maps "fresult" contents (=unformatted java code, used as a key) to
the name of the constant fields which will hold the code's result.
|
protected Map<String,Format> |
exprCache |
protected Format |
fresult
accumulator for format generating functional code.
|
protected boolean |
isdynamic
indicates whether the code currently contained in
fresult
does generate formats "dynamically" (which implies that its result
can NOT be stored in a constant field). |
protected static int |
MODIF_CONST
modifier used for all fields generated to hold
constant format expressions (= "protected static final").
|
protected SimpleMessage.Generator<XMLDocumentIdentifier> |
msg |
protected String |
NAME_CONST_FORMAT_EMPTY
name of the generated field which holds an empty format,
normally "
format_empty ". |
String |
NAME_METHOD_THROW_TAKE_ALTERNATIVE
name of the method generated for convenience
for throwing
TakeAlternativeException . |
protected String |
NAME_VAR_DEFAULT_INDENT
name of the generated field which holds the default idententation,
normally "
default_indent ". |
protected String |
NAME_VAR_FORMAT_RESULT
name of the generated field which holds the resulting format.
|
protected String |
NAME_VAR_MODE
name of the generated field which holds the current mode,
normally "
mode ". |
protected MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> |
rec
Needed ONLY because ".getReceiver()" is of type "? super M", which does not
wokr.
|
static Format |
REF_FORMAT_Format
The format which refers to
Format |
protected GeneratedClass |
targetclass
class into which to generate all const field definitions.
|
static EnvironmentClass |
WRAPPEDCLASS_CompoundConstructor |
static EnvironmentClass |
WRAPPEDCLASS_Format |
static EnvironmentClass |
WRAPPEDCLASS_Function
Refers to
eu.bandm.tools.ops ,
and is for convenience of derived compilers only. |
static EnvironmentClass |
WRAPPEDCLASS_ListoidFormatter
For convenience of derived compilers only.
|
static EnvironmentClass |
WRAPPEDCLASS_Lists
Attention, refers NOT to java.util, but to
eu.bandm.tools.ops , and is for convenience of derived compilers only. |
static EnvironmentClass |
WRAPPEDCLASS_MapEntry
For convenience of derived compilers only.
|
static EnvironmentClass |
WRAPPEDCLASS_MapoidFormatter
For convenience of derived compilers only.
|
static EnvironmentClass |
WRAPPEDCLASS_Object |
static EnvironmentClass |
WRAPPEDCLASS_TakeAlternativeException |
static EnvironmentClass |
WRAPPEDCLASS_TryerCatcher |
validating
Constructor and Description |
---|
GenericCompiler(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> rec) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkconst()
|
protected void |
compileCallToFormatText(Format model)
compiles a call to
Format.text(String) , if model != null. |
protected void |
compileModeSwitch(eu.bandm.tools.formatfrontends.absy.Element_cases el)
Compiles a switch statement with
$mode as its selector. |
void |
compileOnePattern(eu.bandm.tools.formatfrontends.absy.Element_pattern el)
called from derived code for translating one(1) rule.
|
void |
create_resultfield(GeneratedClass gc)
creates a field "
Format result=Format.empty; "
for formatting wisitors which
need such a temp storage (ie. |
protected Format |
expr(String code) |
protected abstract Format |
getCurrentModel()
Currently only needed to compile
escapeToJava() in the variant operating
directly on the model element. |
protected MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> |
getMsgReceiver() |
void |
initTransformerClass(GeneratedClass gc)
Creates standard fields for the generated format generating class.
|
protected void |
process_compound(eu.bandm.tools.formatfrontends.absy.Element[] subs,
String constr) |
protected Format |
refer(CompoundConstructor c) |
protected void |
setMsgReceiver(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> rec) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_alternative element)
Compiles the cascade of alternatives/catch clauses from the
front end representation {@code ...? ...
|
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_append element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_beneath element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_beside element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_block element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_escapeToJava element)
Creates code for a java escape.
|
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_indent element)
creates code for indentation.
|
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_line element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_literal el)
Creates code for one literal, which might also be empty.
|
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_nullException el)
Creates code for the
$throw element. |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_prior el)
<!ELEMENT prior (number, (number | appendOp)?, pattern, pattern) >
It directly maps its arguments to a call of
Format.prior(int, int, eu.bandm.tools.format.Format, eu.bandm.tools.format.Format) . |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_tabular element) |
void |
visit(eu.bandm.tools.formatfrontends.absy.Element_whitespace el)
Creates code for whitespace.
|
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
visit
public static final EnvironmentClass WRAPPEDCLASS_Object
public static final EnvironmentClass WRAPPEDCLASS_Lists
eu.bandm.tools.ops
, and is for convenience of derived compilers only.public static final EnvironmentClass WRAPPEDCLASS_Function
eu.bandm.tools.ops
,
and is for convenience of derived compilers only.public static final EnvironmentClass WRAPPEDCLASS_Format
public static final EnvironmentClass WRAPPEDCLASS_TakeAlternativeException
public static final EnvironmentClass WRAPPEDCLASS_MapoidFormatter
public static final EnvironmentClass WRAPPEDCLASS_MapEntry
public static final EnvironmentClass WRAPPEDCLASS_ListoidFormatter
public static final EnvironmentClass WRAPPEDCLASS_TryerCatcher
public static final EnvironmentClass WRAPPEDCLASS_CompoundConstructor
public final String NAME_METHOD_THROW_TAKE_ALTERNATIVE
TakeAlternativeException
.public final Format callFunctionForRaisingException
TakeAlternativeException
,
cf NAME_METHOD_THROW_TAKE_ALTERNATIVE
.protected String NAME_VAR_DEFAULT_INDENT
default_indent
".protected String NAME_VAR_MODE
mode
".protected String NAME_CONST_FORMAT_EMPTY
format_empty
".protected static final int MODIF_CONST
protected String NAME_VAR_FORMAT_RESULT
protected MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> rec
protected final SimpleMessage.Generator<XMLDocumentIdentifier> msg
protected GeneratedClass targetclass
protected boolean isdynamic
fresult
does generate formats "dynamically" (which implies that its result
can NOT be stored in a constant field).protected boolean checkedmode
protected Format fresult
public GenericCompiler(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> rec)
protected void setMsgReceiver(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> rec)
protected MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> getMsgReceiver()
protected abstract Format getCurrentModel()
escapeToJava()
in the variant operating
directly on the model element.
Introduced 20170428.protected Format refer(CompoundConstructor c)
public void initTransformerClass(GeneratedClass gc)
targetclass
,
which otherwise stays =null.public void create_resultfield(GeneratedClass gc)
Format result=Format.empty;
"
for formatting wisitors which
need such a temp storage (ie. are not purely functinal code). public void compileOnePattern(eu.bandm.tools.formatfrontends.absy.Element_pattern el)
visit(el)
and
(3) leave result in fresult
.
after return, the contents of fresult (=format representing format-generating
code) must be stored to somewhere by the calling code!protected void checkconst()
protected void process_compound(eu.bandm.tools.formatfrontends.absy.Element[] subs, String constr)
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beneath element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beside element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_line element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_block element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_append element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_tabular element)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
protected void compileModeSwitch(eu.bandm.tools.formatfrontends.absy.Element_cases el)
$mode
as its selector.
Defaults to the empty format.protected void compileCallToFormatText(Format model)
Format.text(String)
, if model != null. otherwise
an exception or an empty format, if not left of a "?".public void visit(eu.bandm.tools.formatfrontends.absy.Element_alternative element)
...? ... ? ... ? ...
.
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_nullException el)
$throw
element. This causes explicit failure,
i.e. throwing of an instance of TakeAlternativeException
.
This is sensible when eg. done out of one (or some) of the cases of a
$switch
statement.
It may only be used to the left side of a ?
operator, which
results in the corresponding right side to be executed.visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_prior el)
<!ELEMENT prior (number, (number | appendOp)?, pattern, pattern) >
It directly maps its arguments to a call of
Format.prior(int, int, eu.bandm.tools.format.Format, eu.bandm.tools.format.Format)
.visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_literal el)
Format.literal(String)
or to Format.empty
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_whitespace el)
Format.space(int)
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_escapeToJava element)
$java 'my.package.Class.method'(formatsAsArgument..)
".
or
"$java 'my.package.Class.method'
".
The first argument must point to some static function from Format to Format.
If there is a second argument, it is a "block" construct of formats which
are arguments to the function. Otherwise the current model element is the
only argument.visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
public void visit(eu.bandm.tools.formatfrontends.absy.Element_indent element)
NAME_VAR_DEFAULT_INDENT
visit
in class eu.bandm.tools.formatfrontends.absy.Visitor
see also the complete user documentation .