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

Advanced matching semantic check improvements #413 #414


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 0b3e5b80
......@@ -35,8 +35,6 @@ 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;
import org.eclipse.titan.designer.AST.TTCN3.templates.PatternString.PatternType;
......@@ -160,28 +158,7 @@ public final class Def_Template extends Definition implements IParameterisedAssi
}
if (body != null) {
body.setFullNameParent(this);
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;
}
body.setMyDefinition(this);
}
}
......
......@@ -92,6 +92,7 @@ public final class Def_Var_Template extends Definition {
}
if (initialValue != null) {
initialValue.setFullNameParent(this);
initialValue.setMyDefinition(this);
}
}
......
......@@ -209,6 +209,7 @@ public final class Return_Statement extends Statement {
break;
// dynamic match template
case A_TEMPLATE:
case A_VAR_TEMPLATE:
if (myStatementBlock.isInDynamicTemplate() && template != null &&
!Type_type.TYPE_BOOL.equals(
template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
......
......@@ -32,6 +32,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter;
import org.eclipse.titan.designer.AST.TTCN3.types.Array_Type;
......@@ -611,4 +612,10 @@ public class All_From_Template extends TTCN3Template {
public void generateCodeInitAllFrom(final JavaGenData aData, final StringBuilder source, final String name, final StringBuilder referenceCache) {
source.append(MessageFormat.format("{0}.operator_assign({1}.constGet_at(i_i));\n", name, referenceCache));
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
allFrom.setMyDefinition(definition);
}
}
......@@ -17,6 +17,7 @@ import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -171,4 +172,10 @@ public final class AnyOrOmit_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -16,6 +16,7 @@ import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -160,4 +161,10 @@ public final class Any_Value_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -13,6 +13,7 @@ import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
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.definitions.Definition;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -170,4 +171,10 @@ public final class BitString_Pattern_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -16,6 +16,7 @@ import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.templates.PatternString.PatternType;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -290,4 +291,12 @@ public final class CharString_Pattern_Template extends TTCN3Template {
public void generateCodeStrPattern(final JavaGenData aData, final StringBuilder source) {
source.append(patternstring.create_charstring_literals(aData,myScope.getModuleScopeGen(),source));
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
if (converted != null) {
converted.setMyDefinition(definition);
}
}
}
......@@ -16,6 +16,7 @@ import org.eclipse.titan.designer.AST.ReferenceFinder;
import org.eclipse.titan.designer.AST.ReferenceFinder.Hit;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
......@@ -248,4 +249,12 @@ public abstract class CompositeTemplate extends TTCN3Template {
}
return true;
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
for (int i = 0, size = templates.getNofTemplates(); i < size; i++) {
templates.getTemplateByIndex(i).setMyDefinition(definition);
}
}
}
......@@ -18,6 +18,7 @@ import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.Value;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -349,4 +350,12 @@ public class DecodeMatch_template extends TTCN3Template {
source.append("}\n");
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
if (target != null) {
target.getTemplateBody().setMyDefinition(definition);
}
}
}
......@@ -21,6 +21,7 @@ import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement;
......@@ -119,6 +120,9 @@ public class DynamicMatch_template extends TTCN3Template {
return false;
}
boolean selfReference = type.checkThisTemplate(timestamp, this, isModified, implicitOmit, lhs);
checkLengthRestriction(timestamp, type);
final Type myType = (Type)statementBlock.getMyDefinition().getType(timestamp);
addValueParamList(myType);
statementBlock.check(timestamp);
......@@ -132,7 +136,7 @@ public class DynamicMatch_template extends TTCN3Template {
return false;
}
final boolean selfReference = lhs == assignment;
selfReference |= lhs == assignment;
assignment.check(timestamp);
IType governor = assignment.getType(timestamp);
......@@ -247,6 +251,12 @@ public class DynamicMatch_template extends TTCN3Template {
this.formalParameterList = dynamicFormalParameterList;
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(final Definition definition) {
statementBlock.setMyDefinition(definition);
}
@Override
/** {@inheritDoc} */
public void setMyScope(final Scope scope) {
......
......@@ -13,6 +13,7 @@ import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
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.definitions.Definition;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -170,4 +171,10 @@ public final class HexString_Pattern_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -21,6 +21,7 @@ import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -468,4 +469,10 @@ public interface ITTCN3Template extends IGovernedSimple {
* @param usageModule the module where the template is to be used.
* */
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule);
/**
* Sets the definition of the statement block of the dynamic match template
* @param definition the definition to be set
*/
public void setMyDefinition(final Definition definition);
}
......@@ -9,13 +9,13 @@ package org.eclipse.titan.designer.AST.TTCN3.templates;
import java.text.MessageFormat;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.Scope;
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.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -27,44 +27,61 @@ import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
* */
public class ImplicationMatch_template extends TTCN3Template {
private TTCN3Template precondition;
private TemplateInstance precondition;
private TemplateInstance implied_template;
public ImplicationMatch_template(final TTCN3Template precondition, final TemplateInstance impliedTemplate) {
if (precondition == null || impliedTemplate == null) {
ErrorReporter.INTERNAL_ERROR("ImplicationMatch_template(ITTCN3Template precondition, TemplateInstance implied_template)");
}
// Creating a TemplateInstance with just a template body for now.
// The parser adds the precondition's type indicator and derived reference (if it has either)
// to the TemplateInstance containing this template. They will be moved during semantic analysis.
//this.precondition = new TemplateInstance(null, null, precondition);
this.precondition = precondition;
this.precondition = new TemplateInstance(null, null, precondition);
this.precondition.setLocation(precondition.getLocation());
this.implied_template = impliedTemplate;
}
@Override
public boolean checkExpressionSelfReferenceTemplate(final CompilationTimeStamp timestamp, final Assignment lhs) {
// TODO Auto-generated method stub
if (precondition != null && precondition.getTemplateBody().checkExpressionSelfReferenceTemplate(timestamp, lhs)) {
return true;
}
if (implied_template != null && implied_template.getTemplateBody().checkExpressionSelfReferenceTemplate(timestamp, lhs)) {
return true;
}
return false;
}
@Override
public void checkRecursions(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
if (referenceChain.add(this)) {
referenceChain.markState();
if (precondition != null) {
precondition.checkRecursions(timestamp, referenceChain);
referenceChain.previousState();
referenceChain.markState();
}
if (implied_template != null) {
implied_template.checkRecursions(timestamp, referenceChain);
referenceChain.previousState();
}
}
@Override
public void checkSpecificValue(final CompilationTimeStamp timestamp, final boolean allowOmit) {
// TODO Auto-generated method stub
getLocation().reportSemanticError("A specific value expected instead of an implication match");
}
@Override
/** {@inheritDoc} */
public boolean checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final IType type, final boolean isModified,
final boolean allowOmit, final boolean allowAnyOrOmit, final boolean subCheck, final boolean implicitOmit, final Assignment lhs) {
boolean selfReference = type.checkThisTemplate(timestamp, this, isModified, implicitOmit, lhs);
ITTCN3Template temporalComponent = type.checkThisTemplateRef(timestamp, precondition.getTemplateBody());
selfReference |= temporalComponent.checkThisTemplateGeneric(timestamp, type, false, false, true, subCheck, implicitOmit, lhs);
temporalComponent = type.checkThisTemplateRef(timestamp, implied_template.getTemplateBody());
selfReference |= temporalComponent.checkThisTemplateGeneric(timestamp, type, false, false, true, subCheck, implicitOmit, lhs);
checkLengthRestriction(timestamp, type);
return selfReference;
}
@Override
......@@ -88,7 +105,7 @@ public class ImplicationMatch_template extends TTCN3Template {
final String typeName = myGovernor.getGenNameTemplate(aData, source);
final ExpressionStruct preconditionExpression = new ExpressionStruct();
precondition.generateCodeExpression(aData, preconditionExpression, null);
precondition.generateCode(aData, preconditionExpression, null);
if (preconditionExpression.preamble.length() > 0) {
source.append(preconditionExpression.preamble);
}
......@@ -152,7 +169,7 @@ public class ImplicationMatch_template extends TTCN3Template {
* Returns the precondition template
* @return precondition template
*/
public TTCN3Template getPrecondition() {
public TemplateInstance getPrecondition() {
return precondition;
}
......@@ -190,6 +207,13 @@ public class ImplicationMatch_template extends TTCN3Template {
implied_template.setCodeSection(codeSection);
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
precondition.getTemplateBody().setMyDefinition(definition);
implied_template.getTemplateBody().setMyDefinition(definition);
}
@Override
/** {@inheritDoc} */
public void setMyScope(final Scope scope) {
......
......@@ -28,6 +28,7 @@ import org.eclipse.titan.designer.AST.Value;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
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.Definition;
import org.eclipse.titan.designer.AST.TTCN3.types.Array_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type;
......@@ -598,4 +599,12 @@ public final class Indexed_Template_List extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
for (int i = 0; i < indexedTemplates.getNofTemplates(); i++) {
indexedTemplates.getTemplateByIndex(i).getTemplate().setMyDefinition(definition);
}
}
}
......@@ -536,4 +536,10 @@ public final class Invoke_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -37,6 +37,7 @@ import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable;
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.Definition;
import org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.CompField;
import org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type;
......@@ -825,4 +826,12 @@ public final class Named_Template_List extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
for (int i = 0, size = namedTemplates.getNofTemplates(); i < size; i++) {
namedTemplates.getTemplateByIndex(i).getTemplate().setMyDefinition(definition);
}
}
}
......@@ -12,6 +12,7 @@ import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IValue;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.Notused_Value;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -123,4 +124,10 @@ public final class NotUsed_Template extends TTCN3Template {
public void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
//nothing to be done here
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -13,6 +13,7 @@ import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
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.definitions.Definition;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -180,4 +181,10 @@ public final class OctetString_Pattern_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
......@@ -17,6 +17,7 @@ import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.IValue;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -223,4 +224,10 @@ public final class OmitValue_Template extends TTCN3Template {
source.append(".set_ifPresent();\n");
}
}
@Override
/** {@inheritDoc} */
public void setMyDefinition(Definition definition) {
// Do nothing
}
}
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