Commit 8aa59d7a authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: handling 'value' references inside property statement blocks (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ecd8d028
......@@ -75,6 +75,8 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
public static final String CLASSEXPECTED = "class type expected";
public static final String TYPEEXPECTED = "Type reference expected";
public static final String ASN1SETTINGEXPECTED = "Reference to ASN.1 setting expected";
private static final String INVALIDVALUEREFERENCE = "Invalid `value` reference";
public enum Ref_Type {
REF_BASIC,
......@@ -495,7 +497,6 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
return getRefdAssignment(timestamp, checkParameterList, null);
}
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp) && !checkParameterList) {
return referredAssignment;
......@@ -503,6 +504,19 @@ 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);
if (valueParam != null) {
return (Assignment)valueParam;
} else {
getLocation().reportSemanticError(INVALIDVALUEREFERENCE);
return null;
}
}
}
if (myScope == null || getId() == null) {
return null;
}
......@@ -1489,4 +1503,24 @@ 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;
}
}
......@@ -131,6 +131,11 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
/** Indicates it is a statement block of a class property */
private boolean ownerIsProperty;
/** Formal parameter list with only one member.
* It is used to support the special 'value' keyword in class properties
*/
private FormalParameterList valueParamList;
/**
* Caches whether this function has return statement or not. Used to
......@@ -1126,4 +1131,22 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
}
}
/**
* Sets a formal parameter list for this statement block.
* It is used by class properties for the special keyword 'value'.
* @param fpl
*/
public void setValueParamList(FormalParameterList fpl) {
this.valueParamList = fpl;
}
/**
* Gets a formal parameter list for this statement block.
* It is used by class properties for the special keyword 'value'.
* @param fpl
*/
public FormalParameterList getValueParamList() {
return valueParamList;
}
}
......@@ -8,15 +8,23 @@
package org.eclipse.titan.designer.AST.TTCN3.types;
import java.util.ArrayList;
import java.util.List;
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.TypeCompatibilityInfo;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo.Chain;
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.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.compiler.JavaGenData;
......@@ -32,6 +40,7 @@ public final class Property_Type extends Type {
private Type myType;
private StatementBlock getStatementBlock;
private StatementBlock setStatementBlock;
private FormalParameterList fpList;
public Property_Type(Type type) {
this.myType = type;
......@@ -67,10 +76,17 @@ public final class Property_Type extends Type {
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
FormalParameter valueParam = new FormalParameter(null, Assignment_type.A_PAR_VAL_IN, myType, new Identifier(Identifier_type.ID_TTCN, "value"), null, null);
List<FormalParameter> paramList = new ArrayList<FormalParameter>();
paramList.add(valueParam);
fpList = new FormalParameterList(paramList);
if (getStatementBlock != null) {
getStatementBlock.setValueParamList(fpList);
getStatementBlock.check(timestamp);
}
if (setStatementBlock != null) {
setStatementBlock.setValueParamList(fpList);
setStatementBlock.check(timestamp);
}
}
......
......@@ -6287,8 +6287,10 @@ pr_Value returns[Value value]
}:
( v1 = pr_PredefinedValue { $value = $v1.value; }
| v2 = pr_ReferencedValue { $value = $v2.value; }
| VALUE {
| v3 = pr_ValueKeyword {
Reference valueRef = new Reference(null, Reference.Ref_Type.REF_VALUE);
FieldSubReference subReference = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, "value", getLocation( $v3.start, $v3.stop)));
valueRef.addSubReference(subReference);
$value = new Referenced_Value(valueRef);
}
);
......
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