Commit 387be469 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Fixed parent statement block lookup for 'value' reference


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 4073d708
......@@ -507,6 +507,26 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
return getRefdAssignment(timestamp, checkParameterList, null);
}
/**
* Walks up the scope hierarchy and tries to find the parent statement block for a 'value' reference
* It can be identified by the existence of a value formal parameter list
* @param statementBlock
* @return
*/
private StatementBlock getValueStatementBlock() {
Scope scope = getMyScope();
while (scope != null) {
if (scope instanceof StatementBlock) {
final StatementBlock block = (StatementBlock)scope;
if (((StatementBlock)block ).getValueParamList() != null) {
return (StatementBlock)scope;
}
}
scope = scope.getParentScope();
}
return null;
}
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp) && !checkParameterList) {
return referredAssignment;
......@@ -515,21 +535,24 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
lastTimeChecked = timestamp;
if (reftype == Ref_Type.REF_VALUE) {
if (getMyScope() instanceof StatementBlock) {
final StatementBlock sb = (StatementBlock)getMyScope();
FormalParameter valueParam = getValueParameter(sb);
StatementBlock parentBlock = getValueStatementBlock();
if (parentBlock != null) {
final FormalParameterList valueParamList = parentBlock.getValueParamList();
if (valueParamList != null) {
FormalParameter valueParam = valueParamList.getParameterByIndex(0);
if (valueParam != null) {
return valueParam;
} else {
if (sb.ownerIsProperty() && ! sb.isPropertySetter()) {
if (parentBlock.ownerIsProperty() && ! parentBlock.isPropertySetter()) {
getLocation().reportSemanticError(VALUENOTSETTER);
} else {
getLocation().reportSemanticError(INVALIDVALUEREFERENCE);
}
return null;
}
}
}
}
getLocation().reportSemanticError(INVALIDVALUEREFERENCE);
return null;
}
if (myScope == null || getId() == null) {
return null;
......@@ -1517,24 +1540,4 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
public Ref_Type getReferenceType() {
return reftype;
}
/**
* Finds the 'value' formal parameter for a StatementBlock by walking up the scope hierarchy.
* @param statementBlock
* @return
*/
private FormalParameter getValueParameter(StatementBlock statementBlock) {
Scope scope = statementBlock;
while (scope != null) {
if (scope instanceof StatementBlock) {
final StatementBlock block = (StatementBlock)scope;
if (((StatementBlock)block ).getValueParamList() != null) {
return ((StatementBlock)block).getValueParamList().getParameterByIndex(0);
}
}
scope = scope.getParentScope();
}
return null;
}
}
......@@ -1150,7 +1150,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
/**
* Gets a formal parameter list for this statement block.
* It is used by class properties for the special keyword 'value'.
* It is used by class properties and dynamic matching templates for the special keyword 'value'.
* @param fpl
*/
public FormalParameterList getValueParamList() {
......
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