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

OOP: allowed function calls in extended field refs


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent d69add8c
......@@ -62,6 +62,16 @@ type class OuterClass {
class InnerClass {
private template MyUnion t_union;
public var integer badInteger := "xyz";
public class EvenDeeper {
public const charstring chr := "abc";
public class Core {
public function f_inside(in integer pl_int) return charstring {
return this.chr;
}
}
}
}
}
}
......@@ -163,6 +173,9 @@ testcase tc_basicSyntax() runs on CT {
var integer vl_integer := vl_outer of OuterClass; // type mismatch
var boolean vl_boolean := vl_outer of BaseFunctionClass; // semanticall correct
// nested class member reference
var octetstring vl_octet := vl_outer.NestedClass.InnerClass.EvenDeeper.Core.f_inside(1)
}
}
\ No newline at end of file
......@@ -113,6 +113,14 @@ type class OuterClass {
class DeeplyNested {
const integer m_const := 0;
class EvenDeeper {
const charstring m_str := "abc";
public class Core {
function f_inside(in integer pl_int) return float {
return 0.1;
}
}
}
}
}
}
......@@ -230,6 +238,9 @@ testcase tc_basicSyntax() runs on CT {
if (vl_outerClass of OuterClass) {
vl_outerClass.m_string := "xyz";
}
// nested class member reference
var float vl_float := vl_outerClass.NestedClass.DeeplyNested.EvenDeeper.Core.f_inside(1);
}
control {
......
......@@ -55,6 +55,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String TRAITCANNOTBEFINAL = "A trait class cannot be final";
private static final String ABSTRACTCANNOTBETRAIT = "A class cannot be both abstract and trait";
private static final String TRAITWITHFINALLY = "A trait class should not define a finally block";
private static final String UNKNOWNFIELD = "Unknown field reference";
private final ClassTypeBody classBody;
......@@ -141,10 +142,12 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
Assignment assignment = classBody.getAssByIdentifier(timestamp, subreference.getId());
if (assignment == null)
if (assignment == null) {
subreference.getLocation().reportSemanticError(UNKNOWNFIELD);
return null;
}
if (subreferences.size() < 3) {
if (subreferences.size() == actualSubReference + 1) {
return assignment.getType(timestamp);
}
......
......@@ -7900,9 +7900,22 @@ pr_Primary returns[Value value]
pr_ExtendedFieldReference returns[List<ISubReference> subReferences]
@init {
$subReferences = new ArrayList<ISubReference>();
ParsedActualParameters parameters = null;
}:
( a = pr_Dot
( structFieldId = pr_Identifier
( funcid = pr_Identifier
LPAREN
( par = pr_FunctionActualParList {
parameters = $par.parsedParameters;
parameters.setLocation( getLocation( $par.start, $par.stop ) );
} )?
RPAREN
{
ParameterisedSubReference funcReference = new ParameterisedSubReference($funcid.identifier, parameters);
funcReference.setLocation( getLocation( $funcid.start, $par.stop ) );
$subReferences.add(funcReference);
}
| structFieldId = pr_Identifier
{ FieldSubReference tempReference = new FieldSubReference($structFieldId.identifier);
tempReference.setLocation(getLocation( $structFieldId.start, $structFieldId.stop));
$subReferences.add(tempReference);
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(16);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(18);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 15;
......@@ -54,7 +54,7 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Local Definiton `vl_b' collides with definition inherited from class type `@classesNegativeSemantic.SubClass'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 17;
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 11;
lineNum += 21;
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Constant must be initialized", lineNum, IMarker.SEVERITY_ERROR));
......@@ -71,10 +71,13 @@ public class OOP_Semantic_tests {
lineNum += 10;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `charstring'", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", ++lineNum, IMarker.SEVERITY_ERROR));
lineNum += 12;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 11;
markersToCheck.add(new MarkerToCheck("Unknown field reference", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", ++lineNum, IMarker.SEVERITY_ERROR));
lineNum += 8;
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `octetstring' was expected instead of `charstring'", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
......
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