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

Dynamic matching semantic check improvements #413


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 1f0bd967
......@@ -35,6 +35,7 @@ import org.eclipse.titan.designer.AST.TypeCompatibilityInfo;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter.parameterEvaluationType;
import org.eclipse.titan.designer.AST.TTCN3.templates.CompositeTemplate;
import org.eclipse.titan.designer.AST.TTCN3.templates.DynamicMatch_template;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type;
......@@ -160,8 +161,26 @@ public final class Def_Template extends Definition implements IParameterisedAssi
if (body != null) {
body.setFullNameParent(this);
if (body.getTemplatetype().equals(ITTCN3Template.Template_type.DYNAMIC_MATCH)) {
switch (body.getTemplatetype()) {
case DYNAMIC_MATCH:
((DynamicMatch_template) body).getDynamicStatementBlock().setMyDefinition(this);
break;
case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
case PERMUTATION_MATCH:
case SUBSET_MATCH:
case SUPERSET_MATCH:
case TEMPLATE_LIST:
case VALUE_LIST:
final CompositeTemplate cTemp = (CompositeTemplate) body;
for (int i = 0, size = cTemp.getNofTemplates(); i < size; i++) {
if(cTemp.getTemplateByIndex(i).getTemplatetype().equals(ITTCN3Template.Template_type.DYNAMIC_MATCH)) {
((DynamicMatch_template) cTemp.getTemplateByIndex(i)).getDynamicStatementBlock().setMyDefinition(this);
}
}
break;
default:
break;
}
}
}
......
......@@ -53,7 +53,8 @@ public final class Return_Statement extends Statement {
+ "It is allowed only in functions, altsteps, dynamic matching and class property getters";
private static final String RETURNINDESTRUCTOR = "Return statement cannot be used in a class destructor";
private static final String INVALIDSETTERRETURN = "Return statement cannot be used in a property setter";
private static final String RETURNINDYNAMICTEMPLATE = "The dynamic template's statement block should return a boolean value";
private static final String RETURNINDYNAMICTEMPLATESB = "The dynamic template's statement block should return a boolean value";
private static final String RETURNINDYNAMICTEMPLATEREF = "The dynamic template's referenced function should return a boolean value";
private static final String FULLNAMEPART = ".returnexpression";
private static final String STATEMENT_NAME = "return";
private static final String RETURNTYPEEXPECTED = "Return type `{0}'' expected";
......@@ -211,7 +212,11 @@ public final class Return_Statement extends Statement {
if (myStatementBlock.isInDynamicTemplate() && template != null &&
!Type_type.TYPE_BOOL.equals(
template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
myStatementBlock.getDynamicTemplate().getLocation().reportSemanticError(RETURNINDYNAMICTEMPLATE);
if (myStatementBlock.getDynamicTemplate().hasReference()) {
myStatementBlock.getDynamicTemplate().getLocation().reportSemanticError(RETURNINDYNAMICTEMPLATEREF);
} else {
myStatementBlock.getDynamicTemplate().getLocation().reportSemanticError(RETURNINDYNAMICTEMPLATESB);
}
}
break;
default:
......
......@@ -118,13 +118,12 @@ public class DynamicMatch_template extends TTCN3Template {
if (getIsErroneous(timestamp)) {
return false;
}
// TODO: when referenced, the value param list is not correctly added
final Type myType = (Type)statementBlock.getMyDefinition().getType(timestamp);
addValueParamList(myType);
statementBlock.check(timestamp);
if (reference == null) {
final Type myType = (Type)statementBlock.getMyDefinition().getType(timestamp);
addValueParamList(myType);
statementBlock.check(timestamp);
return false;
}
......@@ -143,9 +142,6 @@ public class DynamicMatch_template extends TTCN3Template {
if (governor == null) {
setIsErroneous(true);
return selfReference;
} else {
addValueParamList((Type)governor);
statementBlock.check(timestamp);
}
return selfReference;
......@@ -212,6 +208,15 @@ public class DynamicMatch_template extends TTCN3Template {
return reference;
}
/**
* Returns whether the reference attribute of the dynamic match template is set or not
* @return {@code true} if the reference attribute of
* the dynamic match template is not {@code null}, {@code false} otherwise
*/
public boolean hasReference() {
return reference != null;
}
@Override
/** {@inheritDoc} */
public boolean hasSingleExpression() {
......
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