Commit 482ccb63 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 be5ba6e6
......@@ -1199,7 +1199,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
this.isPropertySetter = true;
}
/**
/**
* Returns whether this statement block has a formal parameter list.
* It is used by class properties and by dynamic matching for the special keyword 'value'.
* @return {@code true} if a formal parameter list is set, otherwise {@code false}
......
......@@ -7,17 +7,25 @@
******************************************************************************/
package org.eclipse.titan.designer.AST.TTCN3.templates;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
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.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -40,12 +48,13 @@ public class DynamicMatch_template extends TTCN3Template {
public DynamicMatch_template(final Reference reference) {
// '@dynamic F' is equivalent to '@dynamic { return F(value); }'
// the parser has already added the function parameter 'value',
// the parser has already added the function parameter 'value',
// the rest of the statement block is constructed here
this.reference = reference;
statementBlock = new StatementBlock();
statementBlock.setDynamicTemplate(this);
statementBlock.addStatement(new Return_Statement(new Referenced_Template(reference)));
statementBlock.addStatement(new Return_Statement(
new SpecificValue_Template(new Referenced_Value(reference))));
if (reference != null) {
reference.setFullNameParent(this);
......@@ -53,14 +62,19 @@ public class DynamicMatch_template extends TTCN3Template {
}
public DynamicMatch_template(final StatementBlock block) {
if (block == null) {
ErrorReporter.INTERNAL_ERROR("DynamicMatch_template(StatementBlock block)");
}
statementBlock = block;
statementBlock.setDynamicTemplate(this);
this.setMyScope(block);
}
public void addValueParamList(final Type type) {
final FormalParameter valueParam = new FormalParameter(null, Assignment_type.A_PAR_VAL_IN, type, new Identifier(Identifier_type.ID_TTCN, "value"), null, null);
final List<FormalParameter> paramList = new ArrayList<FormalParameter>();
paramList.add(valueParam);
final FormalParameterList fpList = new FormalParameterList(paramList);
statementBlock.setValueParamList(fpList);
}
@Override
public String createStringRepresentation() {
final StringBuilder builder = new StringBuilder();
......@@ -104,10 +118,13 @@ public class DynamicMatch_template extends TTCN3Template {
if (getIsErroneous(timestamp)) {
return false;
}
statementBlock.check(timestamp);
// TODO: when referenced, the value param list is not correctly added
if (reference == null) {
final Type myType = (Type)statementBlock.getMyDefinition().getType(timestamp);
addValueParamList(myType);
statementBlock.check(timestamp);
return false;
}
......@@ -126,6 +143,9 @@ public class DynamicMatch_template extends TTCN3Template {
if (governor == null) {
setIsErroneous(true);
return selfReference;
} else {
addValueParamList((Type)governor);
statementBlock.check(timestamp);
}
return selfReference;
......
......@@ -3130,7 +3130,6 @@ pr_FunctionInstance returns[Reference temporalReference]
pr_FunctionRef returns[Reference reference]
@init {
$reference = null;
boolean isSuperRef = false;
}:
( i1 = pr_Identifier
( DOT
......@@ -9737,17 +9736,23 @@ pr_DynamicMatch returns[TTCN3Template template]
| fr = pr_FunctionRef { ref = $fr.reference; }
{
if (ref != null) {
Reference valueRef = new Reference(null, Reference.Ref_Type.REF_VALUE);
Identifier valueId = new Identifier(Identifier_type.ID_TTCN, "value", getLocation($fr.start, $fr.stop));
FieldSubReference fSubReference = new FieldSubReference(valueId);
fSubReference.setLocation(getLocation($fr.start, $fr.stop));
valueRef.addSubReference(fSubReference);
TemplateInstance ti = new TemplateInstance(null, null,
new Referenced_Template(new Reference(ref.getId(), Reference.Ref_Type.REF_VALUE)));
new SpecificValue_Template(new Referenced_Value(valueRef)));
ParsedActualParameters parameters = new ParsedActualParameters();
parameters.addUnnamedParameter(ti);
ParameterisedSubReference subReference = new ParameterisedSubReference(
new Identifier(Identifier_type.ID_TTCN, "value", getLocation($fr.start, $fr.stop)),
parameters);
ref.addSubReference(subReference);
$template = new DynamicMatch_template($fr.reference);
ParameterisedSubReference pSubReference = new ParameterisedSubReference(
ref.removeLastSubReference().getId(), parameters);
pSubReference.setLocation(getLocation($fr.start, $fr.stop));
ref.addSubReference(pSubReference);
$template = new DynamicMatch_template(ref);
}
}
)
......
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