Commit d880c8e8 authored by Arpad Lovassy's avatar Arpad Lovassy
Browse files

java compiler: recof n_elem(): fix funcion name and generated code


Signed-off-by: Arpad Lovassy's avatarzlovarp <arpad.lovassy@semcon.com>
parent 147c42ac
......@@ -206,6 +206,9 @@ public final class SubsetMatch_Template extends CompositeTemplate {
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if ( template instanceof All_From_Template ) {
template = ((All_From_Template)template).getAllFrom();
}
IValue value = ((SpecificValue_Template) template).getValue();
Reference reference;
if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
......@@ -243,7 +246,7 @@ public final class SubsetMatch_Template extends CompositeTemplate {
break;
}
setType.append(".n_elem()");
setType.append(".n_elem().getInt()");
}
source.append(preamble);
......@@ -257,8 +260,12 @@ public final class SubsetMatch_Template extends CompositeTemplate {
switch (template.getTemplatetype()) {
case ALL_FROM: {
// the template must be all from
template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
IValue value = ((SpecificValue_Template) template).getValue();
TTCN3Template template2 = template;
if ( template instanceof All_From_Template ) {
template2 = ((All_From_Template)template).getAllFrom();
}
template2.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
IValue value = ((SpecificValue_Template) template2).getValue();
Reference reference;
if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
//value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
......@@ -290,12 +297,12 @@ public final class SubsetMatch_Template extends CompositeTemplate {
break;
}
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem(); i_i < i_lim; ++i_i ) '{'\n", expression.expression));
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", expression.expression));
String embeddedName = MessageFormat.format("{0}.setItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem()", expression.expression));
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", expression.expression));
break;
}
default:
......
......@@ -188,7 +188,11 @@ public final class SupersetMatch_Template extends CompositeTemplate {
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
IValue value = ((SpecificValue_Template) template).getValue();
TTCN3Template template2 = template;
if ( template instanceof All_From_Template ) {
template2 = ((All_From_Template)template).getAllFrom();
}
IValue value = ((SpecificValue_Template) template2).getValue();
Reference reference;
if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
reference = ((Undefined_LowerIdentifier_Value) value).getAsReference();
......@@ -225,7 +229,7 @@ public final class SupersetMatch_Template extends CompositeTemplate {
break;
}
setType.append(".n_elem()");
setType.append(".n_elem().getInt()");
}
source.append(preamble);
......@@ -239,8 +243,12 @@ public final class SupersetMatch_Template extends CompositeTemplate {
switch (template.getTemplatetype()) {
case ALL_FROM: {
// the template must be all from
template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
IValue value = ((SpecificValue_Template) template).getValue();
TTCN3Template template2 = template;
if ( template instanceof All_From_Template ) {
template2 = ((All_From_Template)template).getAllFrom();
}
template2.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
IValue value = ((SpecificValue_Template) template2).getValue();
Reference reference;
if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
//value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
......@@ -272,12 +280,12 @@ public final class SupersetMatch_Template extends CompositeTemplate {
break;
}
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem(); i_i < i_lim; ++i_i ) '{'\n", expression.expression));
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", expression.expression));
String embeddedName = MessageFormat.format("{0}.setItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem()", expression.expression));
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", expression.expression));
break;
}
default:
......
......@@ -571,13 +571,13 @@ public final class Template_List extends CompositeTemplate {
break;
}
setSize.append(".n_elem()");
body.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem(); i_i < i_lim; ++i_i ) '{'\n", bodyExpression.expression));
setSize.append(".n_elem().getInt()");
body.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", bodyExpression.expression));
String embeddedName = MessageFormat.format("{0}.setItem({1} + i_i)", name, counter);
((All_From_Template) template).generateCodeInitAllFrom(aData, body, embeddedName);
body.append("}\n");
body.append(MessageFormat.format("{0} += {1}.n_elem();\n", counter, bodyExpression.expression));
body.append(MessageFormat.format("{0} += {1}.n_elem().getInt();\n", counter, bodyExpression.expression));
} else if (template.getTemplatetype() == Template_type.PERMUTATION_MATCH) {
int numPermutations = ((PermutationMatch_Template) template).getNofTemplates();
String permutationStart = aData.getTemporaryVariableName();
......@@ -618,14 +618,14 @@ public final class Template_List extends CompositeTemplate {
break;
}
setSize.append(".n_elem()");
body.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem(); i_i < i_lim; ++i_i ) '{'\n", bodyExpression.expression));
setSize.append(".n_elem().getInt()");
body.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", bodyExpression.expression));
String embeddedName = MessageFormat.format("{0}.setItem({1} + i_i)", name, counter);
((All_From_Template) template2).generateCodeInitAllFrom(aData, body, embeddedName);
body.append("}\n");
body.append(MessageFormat.format("{0} += {1}.n_elem();\n", counter, bodyExpression.expression));
body.append(MessageFormat.format("{0} += {1}.n_elem().getInt();\n", counter, bodyExpression.expression));
template2.lastTimeBuilt = aData.buildTimestamp;
} else {
fixedPart++;
......
......@@ -498,7 +498,7 @@ public class RecordOfGenerator {
source.append("\t\tif (index_value < 0) {\n");
source.append( MessageFormat.format( "\t\t\tthrow new TtcnError( \"Accessing an element of type {0} using a negative index: \"+index_value+\".\");\n", displayName ) );
source.append("\t\t}\n");
source.append("\t\tfinal int nofElements = getNofElements().getInt();\n");
source.append("\t\tfinal int nofElements = n_elem().getInt();\n");
source.append("\t\tif ( index_value >= nofElements ) {\n");
source.append( MessageFormat.format( "\t\t\tthrow new TtcnError( \"Index overflow in a value of type {0}: The index is \"+index_value+\", but the value has only \"+nofElements+\" elements.\" );\n", displayName ) );
source.append("\t\t}\n");
......@@ -521,7 +521,7 @@ public class RecordOfGenerator {
source.append("\t}\n");
source.append('\n');
source.append("\tpublic TitanInteger getNofElements() {\n");
source.append("\tpublic TitanInteger n_elem() {\n");
source.append("\t\treturn sizeOf();\n");
source.append("\t}\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment