Commit a9d182f4 authored by Adam Knapp's avatar Adam Knapp
Browse files

Advanced matching code generation #413 #414 #415


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 274a93db
...@@ -130,7 +130,7 @@ public class ConjunctionMatch_template extends CompositeTemplate { ...@@ -130,7 +130,7 @@ public class ConjunctionMatch_template extends CompositeTemplate {
final StringBuilder setType = new StringBuilder(); final StringBuilder setType = new StringBuilder();
final StringBuilder variableReferences[] = new StringBuilder[templates.getNofTemplates()]; final StringBuilder variableReferences[] = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.set_type(template_sel.VALUE_LIST, {1}", name, fixedPart)); setType.append(MessageFormat.format("{0}.set_type(template_sel.CONJUNCTION_MATCH, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) { for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v)); TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
...@@ -210,7 +210,7 @@ public class ConjunctionMatch_template extends CompositeTemplate { ...@@ -210,7 +210,7 @@ public class ConjunctionMatch_template extends CompositeTemplate {
} }
} }
} else { } else {
source.append(MessageFormat.format("{0}.set_type(template_sel.VALUE_LIST, {1});\n", name, templates.getNofTemplates())); source.append(MessageFormat.format("{0}.set_type(template_sel.CONJUNCTION_MATCH, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) { for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i); final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) { if (template.needsTemporaryReference()) {
......
...@@ -15,6 +15,7 @@ import org.eclipse.titan.designer.AST.IType; ...@@ -15,6 +15,7 @@ import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.Scope; import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.IType.Type_type; import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition; import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct; import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct;
import org.eclipse.titan.designer.compiler.JavaGenData; import org.eclipse.titan.designer.compiler.JavaGenData;
...@@ -37,6 +38,8 @@ public class ImplicationMatch_template extends TTCN3Template { ...@@ -37,6 +38,8 @@ public class ImplicationMatch_template extends TTCN3Template {
this.precondition = new TemplateInstance(null, null, precondition); this.precondition = new TemplateInstance(null, null, precondition);
this.precondition.setLocation(precondition.getLocation()); this.precondition.setLocation(precondition.getLocation());
this.implied_template = impliedTemplate; this.implied_template = impliedTemplate;
this.precondition.setFullNameParent(this);
this.implied_template.setFullNameParent(this);
} }
@Override @Override
...@@ -99,7 +102,7 @@ public class ImplicationMatch_template extends TTCN3Template { ...@@ -99,7 +102,7 @@ public class ImplicationMatch_template extends TTCN3Template {
final String typeName = myGovernor.getGenNameTemplate(aData, source); final String typeName = myGovernor.getGenNameTemplate(aData, source);
final ExpressionStruct preconditionExpression = new ExpressionStruct(); final ExpressionStruct preconditionExpression = new ExpressionStruct();
precondition.generateCode(aData, preconditionExpression, null); precondition.generateCode(aData, preconditionExpression, Restriction_type.TR_NONE);
if (preconditionExpression.preamble.length() > 0) { if (preconditionExpression.preamble.length() > 0) {
source.append(preconditionExpression.preamble); source.append(preconditionExpression.preamble);
} }
...@@ -109,7 +112,7 @@ public class ImplicationMatch_template extends TTCN3Template { ...@@ -109,7 +112,7 @@ public class ImplicationMatch_template extends TTCN3Template {
} }
final ExpressionStruct impliedExpression = new ExpressionStruct(); final ExpressionStruct impliedExpression = new ExpressionStruct();
implied_template.generateCode(aData, impliedExpression, null); implied_template.generateCode(aData, impliedExpression, Restriction_type.TR_NONE);
if (impliedExpression.preamble.length() > 0) { if (impliedExpression.preamble.length() > 0) {
source.append(impliedExpression.preamble); source.append(impliedExpression.preamble);
} }
...@@ -118,7 +121,19 @@ public class ImplicationMatch_template extends TTCN3Template { ...@@ -118,7 +121,19 @@ public class ImplicationMatch_template extends TTCN3Template {
source.append(impliedExpression.postamble); source.append(impliedExpression.postamble);
} }
source.append(MessageFormat.format("{0} = {1}({2}, {3});\n", name, typeName, preconditionId, impliedTemplateId)); source.append(MessageFormat.format("{0} = new {1}({2}, {3});\n", name, typeName, preconditionId, impliedTemplateId));
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScopeGen());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
} }
@Override @Override
......
...@@ -31,7 +31,10 @@ public abstract class Base_Template { ...@@ -31,7 +31,10 @@ public abstract class Base_Template {
STRING_PATTERN (8), STRING_PATTERN (8),
SUPERSET_MATCH (9), SUPERSET_MATCH (9),
SUBSET_MATCH (10), SUBSET_MATCH (10),
DECODE_MATCH (11); DECODE_MATCH (11),
CONJUNCTION_MATCH (12),
IMPLICATION_MATCH (13),
DYNAMIC_MATCH (14);
private final int value; private final int value;
template_sel (final int value) { template_sel (final int value) {
...@@ -51,6 +54,28 @@ public abstract class Base_Template { ...@@ -51,6 +54,28 @@ public abstract class Base_Template {
TR_PRESENT TR_PRESENT
}; };
/**
* Struct for implication match.
* Contains the precondition and the implication template of the specified type.
*
* @param <T> Type of the inner precondition and implication template.
*/
protected class ImplicationMatchStruct<T> {
public T precondition;
public T implied_template;
}
/**
* Struct for dynamic matching.
* Contains the IDynamicMatch interface of the specified type as pointer/reference and its counter.
*
* @param <T> Type of the IDynamicMatch interface.
*/
protected class DynamicMatchStruct<T> {
public int ref_count;
public IDynamicMatch<T> ptr;
}
protected template_sel template_selection; protected template_sel template_selection;
protected boolean is_ifPresent; protected boolean is_ifPresent;
......
...@@ -65,6 +65,7 @@ public final class Param_Types { ...@@ -65,6 +65,7 @@ public final class Param_Types {
MP_Indexed_List, MP_Indexed_List,
MP_List_Template, MP_List_Template,
MP_ComplementList_Template, MP_ComplementList_Template,
MP_ConjunctionList_Template,
MP_Superset_Template, MP_Superset_Template,
MP_Subset_Template, MP_Subset_Template,
MP_Permutation_Template, MP_Permutation_Template,
...@@ -1734,6 +1735,21 @@ public final class Param_Types { ...@@ -1734,6 +1735,21 @@ public final class Param_Types {
} }
} }
public static class Module_Param_ConjunctionList_Template extends Module_Param_Compound {
public type_t get_type() {
return type_t.MP_ConjunctionList_Template;
}
public String get_type_str() {
return "conjunction list template";
}
public void log_value() {
log_value_vec("conjunct(",")");
}
}
public static class Module_Param_Superset_Template extends Module_Param_Compound { public static class Module_Param_Superset_Template extends Module_Param_Compound {
public type_t get_type() { public type_t get_type() {
......
...@@ -32,6 +32,7 @@ import org.eclipse.titan.runtime.core.Param_Types.Module_Parameter.type_t; ...@@ -32,6 +32,7 @@ import org.eclipse.titan.runtime.core.Param_Types.Module_Parameter.type_t;
* @author Arpad Lovassy * @author Arpad Lovassy
*/ */
public class TitanInteger_template extends Base_Template { public class TitanInteger_template extends Base_Template {
// int_val part // int_val part
// TODO maybe should be renamed in core // TODO maybe should be renamed in core
private TitanInteger single_value; private TitanInteger single_value;
...@@ -44,6 +45,9 @@ public class TitanInteger_template extends Base_Template { ...@@ -44,6 +45,9 @@ public class TitanInteger_template extends Base_Template {
private boolean min_is_exclusive, max_is_exclusive; private boolean min_is_exclusive, max_is_exclusive;
private TitanInteger min_value, max_value; private TitanInteger min_value, max_value;
private ImplicationMatchStruct<TitanInteger_template> implication;
private DynamicMatchStruct<TitanInteger> dynamic_match;
/** /**
* Initializes to unbound/uninitialized template. * Initializes to unbound/uninitialized template.
* */ * */
...@@ -132,6 +136,31 @@ public class TitanInteger_template extends Base_Template { ...@@ -132,6 +136,31 @@ public class TitanInteger_template extends Base_Template {
copy_template(otherValue); copy_template(otherValue);
} }
/**
* Initializes for implication matching.
*
* @param precondition
* @param impliedTemplate
*/
public TitanInteger_template(final TitanInteger_template precondition, final TitanInteger_template impliedTemplate) {
super(template_sel.IMPLICATION_MATCH);
implication = new ImplicationMatchStruct<TitanInteger_template>();
implication.precondition = precondition;
implication.implied_template = impliedTemplate;
}
/**
* Initializes for dynamic matching.
*
* @param dynamicMatch
*/
public TitanInteger_template(final IDynamicMatch<TitanInteger> dynamicMatch) {
super(template_sel.DYNAMIC_MATCH);
dynamic_match = new DynamicMatchStruct<TitanInteger>();
dynamic_match.ptr = dynamicMatch;
dynamic_match.ref_count = 1;
}
@Override @Override
public void clean_up() { public void clean_up() {
switch (template_selection) { switch (template_selection) {
...@@ -140,6 +169,7 @@ public class TitanInteger_template extends Base_Template { ...@@ -140,6 +169,7 @@ public class TitanInteger_template extends Base_Template {
break; break;
case VALUE_LIST: case VALUE_LIST:
case COMPLEMENTED_LIST: case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
value_list.clear(); value_list.clear();
value_list = null; value_list = null;
break; break;
...@@ -147,6 +177,22 @@ public class TitanInteger_template extends Base_Template { ...@@ -147,6 +177,22 @@ public class TitanInteger_template extends Base_Template {
min_value = null; min_value = null;
max_value = null; max_value = null;
break; break;
case IMPLICATION_MATCH:
if (implication != null) {
implication.precondition = null;
implication.implied_template = null;
}
implication = null;
break;
case DYNAMIC_MATCH:
if (dynamic_match != null) {
dynamic_match.ref_count--;
if (dynamic_match.ref_count == 0) {
dynamic_match.ptr = null;
dynamic_match = null;
}
}
break;
default: default:
break; break;
} }
...@@ -276,6 +322,7 @@ public class TitanInteger_template extends Base_Template { ...@@ -276,6 +322,7 @@ public class TitanInteger_template extends Base_Template {
break; break;
case VALUE_LIST: case VALUE_LIST:
case COMPLEMENTED_LIST: case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
value_list = new ArrayList<TitanInteger_template>(otherValue.value_list.size()); value_list = new ArrayList<TitanInteger_template>(otherValue.value_list.size());
for (int i = 0; i < otherValue.value_list.size(); i++) { for (int i = 0; i < otherValue.value_list.size(); i++) {
final TitanInteger_template temp = new TitanInteger_template(otherValue.value_list.get(i)); final TitanInteger_template temp = new TitanInteger_template(otherValue.value_list.get(i));
...@@ -294,6 +341,13 @@ public class TitanInteger_template extends Base_Template { ...@@ -294,6 +341,13 @@ public class TitanInteger_template extends Base_Template {
max_value = new TitanInteger(otherValue.max_value); max_value = new TitanInteger(otherValue.max_value);
} }
break; break;
case IMPLICATION_MATCH:
implication = otherValue.implication;
break;
case DYNAMIC_MATCH:
dynamic_match = otherValue.dynamic_match;
dynamic_match.ref_count++;
break;
default: default:
throw new TtcnError("Copying an uninitialized/unsupported integer template."); throw new TtcnError("Copying an uninitialized/unsupported integer template.");
} }
...@@ -368,6 +422,17 @@ public class TitanInteger_template extends Base_Template { ...@@ -368,6 +422,17 @@ public class TitanInteger_template extends Base_Template {
} }
return lowerMatch && upperMatch; return lowerMatch && upperMatch;
} }
case CONJUNCTION_MATCH:
for (int i = 0; i < value_list.size(); i++) {
if (!value_list.get(i).match(otherValue, legacy)) {
return false;
}
}
return true;
case IMPLICATION_MATCH:
return !implication.precondition.match(otherValue) || implication.implied_template.match(otherValue);
case DYNAMIC_MATCH:
return dynamic_match.ptr.match(otherValue);
default: default:
throw new TtcnError("Matching with an uninitialized/unsupported integer template."); throw new TtcnError("Matching with an uninitialized/unsupported integer template.");
} }
...@@ -388,6 +453,7 @@ public class TitanInteger_template extends Base_Template { ...@@ -388,6 +453,7 @@ public class TitanInteger_template extends Base_Template {
switch (templateType) { switch (templateType) {
case VALUE_LIST: case VALUE_LIST:
case COMPLEMENTED_LIST: case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
set_selection(templateType); set_selection(templateType);
value_list = new ArrayList<TitanInteger_template>(listLength); value_list = new ArrayList<TitanInteger_template>(listLength);
for (int i = 0; i < listLength; i++) { for (int i = 0; i < listLength; i++) {
...@@ -418,7 +484,8 @@ public class TitanInteger_template extends Base_Template { ...@@ -418,7 +484,8 @@ public class TitanInteger_template extends Base_Template {
@Override @Override
public TitanInteger_template list_item(final int listIndex) { public TitanInteger_template list_item(final int listIndex) {
if (!template_sel.VALUE_LIST.equals(template_selection) && if (!template_sel.VALUE_LIST.equals(template_selection) &&
!template_sel.COMPLEMENTED_LIST.equals(template_selection)) { !template_sel.COMPLEMENTED_LIST.equals(template_selection) &&
!template_sel.CONJUNCTION_MATCH.equals(template_selection)) {
throw new TtcnError("Accessing a list element of a non-list integer template."); throw new TtcnError("Accessing a list element of a non-list integer template.");
} }
if (listIndex < 0) { if (listIndex < 0) {
...@@ -518,6 +585,8 @@ public class TitanInteger_template extends Base_Template { ...@@ -518,6 +585,8 @@ public class TitanInteger_template extends Base_Template {
case OMIT_VALUE: case OMIT_VALUE:
case ANY_OR_OMIT: case ANY_OR_OMIT:
return true; return true;
case IMPLICATION_MATCH:
return !implication.precondition.match_omit() || implication.implied_template.match_omit();
case VALUE_LIST: case VALUE_LIST:
case COMPLEMENTED_LIST: case COMPLEMENTED_LIST:
if (legacy) { if (legacy) {
...@@ -549,6 +618,10 @@ public class TitanInteger_template extends Base_Template { ...@@ -549,6 +618,10 @@ public class TitanInteger_template extends Base_Template {
} }
case COMPLEMENTED_LIST: case COMPLEMENTED_LIST:
TTCN_Logger.log_event_str("complement"); TTCN_Logger.log_event_str("complement");
case CONJUNCTION_MATCH:
if (template_sel.CONJUNCTION_MATCH.equals(template_selection)) {
TTCN_Logger.log_event_str("conjunct");
}
case VALUE_LIST: case VALUE_LIST:
TTCN_Logger.log_char('('); TTCN_Logger.log_char('(');
for (int i = 0; i < value_list.size(); i++) { for (int i = 0; i < value_list.size(); i++) {
...@@ -590,6 +663,14 @@ public class TitanInteger_template extends Base_Template { ...@@ -590,6 +663,14 @@ public class TitanInteger_template extends Base_Template {
TTCN_Logger.log_char(')'); TTCN_Logger.log_char(')');
break; break;
case IMPLICATION_MATCH:
implication.precondition.log();
TTCN_Logger.log_event_str(" implies ");
implication.implied_template.log();
break;
case DYNAMIC_MATCH:
TTCN_Logger.log_event_str("@dynamic template");
break;
default: default:
log_generic(); log_generic();
break; break;
......
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