Commit a507ef78 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - all constructor formal params should be `in` (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent c53817ab
......@@ -99,6 +99,11 @@ type class BaseFunctionClass {
}
}
// constructor
type class ConstructorClass {
create(integer pl_i1, in integer pl_i2, inout integer pl_i3, out integer pl_i4) {}
}
type class OuterClass {
private var integer m_int := 0;
......
......@@ -81,6 +81,7 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
+ " {0} `{1}'' cannot be start on a parallel test component";
private static final String WILLREMAINUNCHANGED =
"{0} `{1}'' started on parallel test components. Its `out'' and `inout'' parameters will remain unchanged at the end of the operation.";
private static final String CONSTRUCTORPARAMIN = "All formal parameters of a constructor shall be `in` parameters";
private final List<FormalParameter> parameters = new ArrayList<FormalParameter>();
private Location location = NULL_Location.INSTANCE;
......@@ -276,9 +277,27 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
minimumNofParameters = 0;
isStartable = true;
boolean isConstructor = false;
if (getMyDefinition() instanceof Def_Function) {
final Def_Function parentFunc = (Def_Function)getMyDefinition();
if (parentFunc.getIdentifier().getName().equals("create") && isInClassBody()) {
isConstructor = true;
}
}
for (int i = 0, size = parameters.size(); i < size; i++) {
FormalParameter parameter = parameters.get(i);
final Identifier identifier = parameter.getIdentifier();
if (isConstructor) {
switch (parameter.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
break;
default:
parameter.getLocation().reportSemanticError(CONSTRUCTORPARAMIN);
}
}
if (parentScope != null && ! isInClassBody()) {
if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
parameter.getLocation().reportSemanticError(
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(55);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(57);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -83,7 +83,11 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Reference to non-existent field `nonexist' in union template for type `@classesNegativeSemantic.MyUnion'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Local Definiton `vl_b' collides with definition inherited from class type `@classesNegativeSemantic.SubClass'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 17;
lineNum += 11;
for (i = 0; i < 2; i++) {
markersToCheck.add(new MarkerToCheck("All formal parameters of a constructor shall be `in` parameters", lineNum, IMarker.SEVERITY_ERROR));
}
lineNum += 11;
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 21;
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
......
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