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

OOP: semantic check - abstract method body; template in params; more conf tests (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent c3a92651
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.4, Ensure that use final classes correctly.
** @verdict pass accept
**
** modified by Miklos Magyari
*****************************************************************/
module Sem_5010104_finalClasses_001 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
type class @final FinalClass {
function doSomething() return charstring {
return "something";
}
}
testcase tc_Sem_5010104_finalClasses_001() runs on GeneralComp {
var FinalClass vl_a := FinalClass.create();
if (vl_a.doSomething() == "something") {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_Sem_5010104_finalClasses_001());
}
}
\ No newline at end of file
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.5, Ensure that use class constructor with formal parameter.
** @verdict pass accept
**
** modified by Miklos Magyari
*****************************************************************/
module Sem_5010105_Constructors_001 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
type class MyClass {
var integer v_i;
var charstring v_id;
create(integer pl_i, charstring pl_id) {
this.v_i := pl_i;
this.v_id := pl_id;
}
public function get_vi() return integer {
return this.v_i;
}
public function get_vid() return charstring {
return this.v_id;
}
}
testcase tc_Sem_5010105_Constructors_001() runs on GeneralComp {
var MyClass vl_a := MyClass.create(5, "abc");
if (vl_a.get_vi() == 5 and vl_a.get_vid() == "abc") {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_Sem_5010105_Constructors_001());
}
}
\ No newline at end of file
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.5, Ensure that use class constructor with its superclass constructor.
** @verdict pass accept
**
** modified by Miklos Magyari
*****************************************************************/
module Sem_5010105_Constructors_002 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
type class MySuperClass {
public var octetstring v_o;
create(octetstring pl_o) {
this.v_o := pl_o;
}
public function get_vo() return octetstring {
return this.v_o;
}
}
type class MySubClass extends MySuperClass {
public var template charstring vt_cstr;
create(template charstring pl_cstr) : MySuperClass('AA5600'O) {
this.vt_cstr := pl_cstr;
}
}
testcase tc_Sem_5010105_Constructors_002() runs on GeneralComp {
var MySubClass vl_a := MySubClass.create( pattern "?abc*");
if (vl_a.get_vo() == 'AA5600'O) {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_Sem_5010105_Constructors_002());
}
}
\ No newline at end of file
......@@ -292,6 +292,7 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
switch (parameter.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_TEMP_IN:
break;
default:
parameter.getLocation().reportSemanticError(CONSTRUCTORPARAMIN);
......
......@@ -62,6 +62,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
public static final String TRAITMETHODHASBODY = "Trait method cannot have a function body";
public static final String TRAITCONSTRUCTOR = "Trait classes cannot have a constructor";
public static final String TRAITMETHODABSTRACT = "Trait classes can only declare abstract methods";
public static final String ABSTRACTMETHODHASBODY = "Abstract method cannot have a function body";
private final Identifier identifier;
/** The class's own definitions */
......@@ -365,6 +366,17 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
definitions.checkAll(timestamp);
if (myType.isAbstract()) {
for (Definition def : definitions) {
if (def instanceof Def_Function) {
final Def_Function funcDef = (Def_Function)def;
if (funcDef.isAbstract() && funcDef.hasBody()) {
funcDef.getLocation().reportSingularSemanticError(ABSTRACTMETHODHASBODY);
myType.setIsErroneous(true);
}
}
}
}
if (myType.isTrait()) {
for (Definition def : definitions) {
if (def instanceof Def_Function) {
......
......@@ -34,7 +34,10 @@ public class OOP_Syntax_tests {
// "Sem_50101_top_level_006.ttcn",
"Sem_50101_top_level_007.ttcn",
"Sem_50101_top_level_008.ttcn",
"Sem_5010102_abstractClasses_001.ttcn"
"Sem_5010102_abstractClasses_001.ttcn",
"Sem_5010104_finalClasses_001.ttcn",
"Sem_5010105_Constructors_001.ttcn",
"Sem_5010105_Constructors_002.ttcn"
);
public static List<String> testFilesNegative = Arrays.asList(
......
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