GitLab will be shut down on June 25 to move to a new facility. https://www.eclipsestatus.io/incidents/5ffy27gwcbx7

Commit 89d243ff authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: raise exception is terminating; SO fix; OOP warning tests


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 9ab79648
......@@ -262,6 +262,19 @@ function f_fake_super() return charstring {
return "abc";
}
// class casting
type class CastBase {}
type class CastBase2 {}
type class CastChild extends CastBase {}
type class CastGrandChild extends CastChild {}
type class CastOther extends CastBase2 {}
function f_casting() {
var CastBase vl_toCast1 := CastBase.create;
var object vl_casted1 := vl_toCast1 => CastGrandChild; // correct
var object vl_casted2 := vl_toCast1 => CastOther; // invalid cast to unrelated class
}
// bad super references
function f_notinclass(in integer pl_int) {
var charstring vl_ch := super.f_fake_super();
......@@ -420,6 +433,20 @@ type class PropertyClass {
}
}
// raise exception
function f_with_exception(integer pl_int) return integer exception(integer) {
if (pl_int > 100) {
raise integer:0; // correct
}
return pl_int * 2;
} catch (integer e) {
log("Catch block");
} finally {
log("Finally block");
raise integer:0; // invalid, raise cannot be used in a finally block
}
testcase tc_basicSyntax() runs on CT {
var GrandSubClass vl_gsc := GrandSubClass.create;
......
......@@ -57,6 +57,8 @@ type class SubClass3 extends BaseClass, TraitBaseClass, TraitBaseClass2 {
var integer m_int;
}
type class SubClass4 extends SubClass1 {}
type class @abstract AbstractMethods {
// functions without a statement block
public function @abstract f_abs();
......@@ -236,7 +238,7 @@ type class ReuseClass {
}
}
type class SubClass4 extends SuperBaseClass {
type class SubClass5 extends SuperBaseClass {
private const integer m_const2 := 2;
private const integer m_const3 := 2;
public function f_get_const2() return integer {
......@@ -388,6 +390,19 @@ function @control f_example3(in integer pl_int) {
}
// raise exception
function f_with_exception(integer pl_int) return integer exception(integer) {
if (pl_int > 100) {
raise integer:0;
}
return pl_int * 2;
} catch (integer e) {
log("Catch block");
} finally {
log("Finally block");
}
testcase tc_basicSyntax() runs on CT {
var object vl_obj := MinimalClass.create;
......@@ -401,11 +416,11 @@ testcase tc_basicSyntax() runs on CT {
// class member access
var integer vl_intval := vl_thisClass.vl_a;
var SubClass4 vl_sub4 := SubClass4.create;
vl_intval := vl_sub4.f_get_all_sum();
var SubClass5 vl_sub5 := SubClass5.create;
vl_intval := vl_sub5.f_get_all_sum();
// class method call
vl_sub4.f_get_all_sum();
vl_sub5.f_get_all_sum();
// class of-operator
var OuterClass vl_outerClass := OuterClass.create;
......@@ -413,6 +428,12 @@ testcase tc_basicSyntax() runs on CT {
vl_outerClass.m_string := "xyz";
}
// class casting
var BaseClass vl_base := BaseClass.create;
var object vl_casted := vl_base => SubClass1;
var SubClass4 vl_subclass4 := SubClass4.create;
var object vl_casted2 := vl_subclass4 => BaseClass;
// nested class member reference
var float vl_float := vl_outerClass.NestedClass.DeeplyNested.EvenDeeper.Core.f_inside(1);
}
......
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Magyari, Miklos
*
******************************************************************************/
module classesWarningSemantic {
type component CT {
port PT pt_PT;
}
type component CT2 {
port PT pt2_PT;
}
type port PT message { inout integer; } with { extension "internal" }
type union MyUnion {
integer a,
charstring b
};
// raise exception
function f_with_exception(integer pl_int) return integer exception(integer) {
if (pl_int > 100) {
raise integer:0;
var float vl_never_reached := 0.0; // never reached
}
return pl_int * 2;
} catch (integer e) {
log("Catch block");
} finally {
log("Finally block");
}
testcase tc_basicWarning() runs on CT {
}
}
\ No newline at end of file
......@@ -46,6 +46,11 @@ public class RaiseException_Statement extends Statement {
}
}
@Override
/** {@inheritDoc} */
public boolean isTerminating(final CompilationTimeStamp timestamp) {
return true;
}
@Override
public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException {
......
......@@ -94,6 +94,8 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
return;
}
lastCompilationTimeStamp = timestamp;
int nrNonTraitExtends = 0;
for (final Reference classRef : classReferences) {
final Assignment refdAss = classRef.getRefdAssignment(timestamp, false);
......@@ -157,8 +159,6 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
for (final ClassTypeBody body : orderedClassTypeBodies) {
body.check(timestamp);
}
lastCompilationTimeStamp = timestamp;
}
/**
......
......@@ -24,6 +24,7 @@ import org.junit.Test;
public class OOP_Semantic_tests {
private static final String DIR_PATH = "src/Basic_tests/";
private static final String OOP_NEGATIVE_BASIC_SEMANTIC = "/OopNegativeSemanticTest.ttcn";
private static final String OOP_BASIC_SEMANTIC_WARNING = "/OopWarningSemanticTest.ttcn";
private static boolean parseOOP;
......@@ -34,6 +35,7 @@ public class OOP_Semantic_tests {
return;
Designer_plugin_tests.ignoreMarkersOnFile(DIR_PATH + OOP_NEGATIVE_BASIC_SEMANTIC);
Designer_plugin_tests.ignoreMarkersOnFile(DIR_PATH + OOP_BASIC_SEMANTIC_WARNING);
for (String testFile : OOP_Syntax_tests.testFilesNegative) {
Designer_plugin_tests.ignoreMarkersOnFile(OOP_Syntax_tests.OOP_DIR_PATH + "negative/" + testFile);
}
......@@ -42,8 +44,12 @@ public class OOP_Semantic_tests {
@Test
public void OOPNegativeSemantic_Test() throws Exception {
if (parseOOP) {
// check for semantic errors
Designer_plugin_tests.checkSemanticMarkersOnFile(oopNegative_ttcn_initializer(), DIR_PATH + OOP_NEGATIVE_BASIC_SEMANTIC);
// check for semantic warnings
Designer_plugin_tests.checkSemanticMarkersOnFile(oopWarning_ttcn_initializer(), DIR_PATH + OOP_BASIC_SEMANTIC_WARNING);
Designer_plugin_tests.checkSemanticMarkersOnFile(NegSem_50101_top_level_002_ttcn_initializer(),
OOP_Syntax_tests.OOP_DIR_PATH + "negative/NegSem_50101_top_level_002.ttcn");
......@@ -162,9 +168,18 @@ public class OOP_Semantic_tests {
return markersToCheck;
}
private ArrayList<MarkerToCheck> oopWarning_ttcn_initializer() {
//OopWarningSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(1);
int lineNum = 34;
markersToCheck.add(new MarkerToCheck("Control never reaches this statement", lineNum, IMarker.SEVERITY_WARNING));
return markersToCheck;
}
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(91);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(93);
int lineNum = 33;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -261,7 +276,9 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
lineNum += 18;
markersToCheck.add(new MarkerToCheck("A class can only be cast to a superclass or subclass", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5;
markersToCheck.add(new MarkerToCheck("`super' reference is only valid inside class bodies", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `charstring'", lineNum, IMarker.SEVERITY_ERROR));
......@@ -309,7 +326,9 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Property getter cannot be both abstract and final", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Abstract getter should not have a body", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 13;
lineNum += 17;
markersToCheck.add(new MarkerToCheck("Raise statement cannot be used in a finally block", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
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;
......
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