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

OOP: finally/catch for altstep and testcase; better modifier handling for classes (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 71fb3d93
......@@ -49,6 +49,7 @@ import org.eclipse.titan.designer.preferences.PreferenceConstants;
* The Def_Altstep class represents TTCN3 altstep definitions.
*
* @author Kristof Szabados
* @author Miklos Magyari
* */
public final class Def_Altstep extends Definition implements IParameterisedAssignment {
private static final String FULLNAMEPART1 = ".<formal_parameter_list>";
......@@ -57,6 +58,7 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
private static final String FULLNAMEPART4 = ".<guards>";
private static final String FULLNAMEPART5 = ".<mtc_type>";
private static final String FULLNAMEPART6 = ".<system_type>";
private static final String FULLNAMEPART7 = ".<finally_block>";
private static final String DASHALLOWEDONLYFORTEMPLATES = "Using not used symbol (`-') as the default parameter"
+ " is allowed only for modified templates";
......@@ -71,17 +73,20 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
private final Reference systemRef;
private Component_Type systemType = null;
private final StatementBlock block;
private final StatementBlock finallyBlock;
private final AltGuards altGuards;
private NamedBridgeScope bridgeScope = null;
public Def_Altstep(final Identifier identifier, final FormalParameterList formalParameters, final Reference runsOnRef,
final Reference mtcReference, final Reference systemReference, final StatementBlock block, final AltGuards altGuards) {
final Reference mtcReference, final Reference systemReference, final StatementBlock block, final StatementBlock finallyBlock,
final AltGuards altGuards) {
super(identifier);
this.formalParList = formalParameters;
this.runsOnRef = runsOnRef;
this.mtcRef = mtcReference;
this.systemRef = systemReference;
this.block = block;
this.finallyBlock = finallyBlock;
this.altGuards = altGuards;
if (formalParList != null) {
......@@ -100,6 +105,10 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
if (block != null) {
block.setMyDefinition(this);
}
if (finallyBlock != null) {
finallyBlock.setMyDefinition(this);
finallyBlock.setOwnerIsFinally();
}
if (altGuards != null) {
altGuards.setMyDefinition(this);
}
......@@ -136,6 +145,8 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
return builder.append(FULLNAMEPART5);
} else if (systemRef == child) {
return builder.append(FULLNAMEPART6);
} else if (finallyBlock == child) {
return builder.append(FULLNAMEPART7);
}
return builder;
......@@ -203,6 +214,9 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
altGuards.setMyScope(block);
bridgeScope.addSubScope(block.getLocation(), block);
}
if (finallyBlock != null) {
finallyBlock.setMyScope(formalParList);
}
bridgeScope.addSubScope(formalParList.getLocation(), formalParList);
if (altGuards != null) {
......@@ -312,6 +326,10 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
block.check(timestamp);
block.setCodeSection(CodeSectionType.CS_INLINE);
}
if (finallyBlock != null) {
finallyBlock.check(timestamp);
}
if (altGuards != null) {
altGuards.setIsAltstep();
......
......@@ -110,6 +110,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private static final String FULLNAMEPART5 = ".<mtc_type>";
private static final String FULLNAMEPART6 = ".<system_type>";
private static final String FULLNAMEPART7 = ".<port_type>";
private static final String FULLNAMEPART8 = ".<finally_block>";
public static final String PORTRETURNNOTALLOWED = "Functions can not return ports";
private static final String DASHALLOWEDONLYFORTEMPLATES = "Using not used symbol (`-') as the default parameter"
......@@ -192,7 +193,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
if (finallyBlock != null) {
finallyBlock.setMyDefinition(this);
finallyBlock.setFullNameParent(this);
finallyBlock.setOwnerIsDestructor();
finallyBlock.setOwnerIsFinally();
}
if (runsOnRef != null) {
runsOnRef.setFullNameParent(this);
......@@ -262,6 +263,8 @@ public final class Def_Function extends Definition implements IParameterisedAssi
return builder.append(FULLNAMEPART6);
} else if (portReference == child) {
return builder.append(FULLNAMEPART7);
} else if (finallyBlock == child) {
return builder.append(FULLNAMEPART8);
}
return builder;
......
......@@ -47,12 +47,14 @@ import org.eclipse.titan.designer.preferences.PreferenceConstants;
*
* @author Kristof Szabados
* @author Arpad Lovassy
* @author Miklos Magyari
*/
public final class Def_Testcase extends Definition implements IParameterisedAssignment {
private static final String FULLNAMEPART1 = ".<formal_parameter_list>";
private static final String FULLNAMEPART2 = ".<runs_on_type>";
private static final String FULLNAMEPART3 = ".<system_type>";
private static final String FULLNAMEPART4 = ".<statement_block>";
private static final String FULLNAMEPART5 = ".<finally_block>";
private static final String DASHALLOWEDONLYFORTEMPLATES = "Using not used symbol (`-') as the default parameter"
+ " is allowed only for modified templates";
......@@ -65,10 +67,11 @@ public final class Def_Testcase extends Definition implements IParameterisedAssi
private final Reference systemReference;
private Component_Type systemType = null;
private final StatementBlock block;
private final StatementBlock finallyBlock;
private NamedBridgeScope bridgeScope = null;
public Def_Testcase(final Identifier identifier, final FormalParameterList formalParameters, final Reference runsOnRef,
final Reference systemRef, final StatementBlock block) {
final Reference systemRef, final StatementBlock block, final StatementBlock finallyBlock) {
super(identifier);
this.formalParList = formalParameters;
if (formalParList != null) {
......@@ -81,6 +84,12 @@ public final class Def_Testcase extends Definition implements IParameterisedAssi
block.setMyDefinition(this);
block.setFullNameParent(this);
}
this.finallyBlock = finallyBlock;
if (finallyBlock != null) {
finallyBlock.setMyDefinition(this);
finallyBlock.setFullNameParent(this);
finallyBlock.setOwnerIsFinally();
}
if (formalParList != null) {
formalParList.setFullNameParent(this);
......@@ -116,6 +125,8 @@ public final class Def_Testcase extends Definition implements IParameterisedAssi
return builder.append(FULLNAMEPART3);
} else if (block == child) {
return builder.append(FULLNAMEPART4);
} else if (finallyBlock == child) {
return builder.append(FULLNAMEPART5);
}
return builder;
......@@ -209,6 +220,9 @@ public final class Def_Testcase extends Definition implements IParameterisedAssi
block.setMyScope(formalParList);
bridgeScope.addSubScope(block.getLocation(), block);
}
if (finallyBlock != null) {
finallyBlock.setMyScope(formalParList);
}
bridgeScope.addSubScope(formalParList.getLocation(), formalParList);
}
......@@ -302,6 +316,10 @@ public final class Def_Testcase extends Definition implements IParameterisedAssi
block.postCheck();
block.setCodeSection(CodeSectionType.CS_INLINE);
}
if (finallyBlock != null) {
finallyBlock.check(timestamp);
}
if (withAttributesPath != null) {
withAttributesPath.checkGlobalAttributes(timestamp, false);
......
......@@ -258,7 +258,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
/**
* Sets indication that it is a statement block of a class destructor.
**/
public void setOwnerIsDestructor() {
public void setOwnerIsFinally() {
ownerIsDestructor = true;
}
......
......@@ -103,7 +103,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
if (finallyBlock != null) {
finallyBlock.setFullNameParent(this);
finallyBlock.setOwnerIsDestructor();
finallyBlock.setOwnerIsFinally();
}
}
......
......@@ -2006,7 +2006,7 @@ pr_TestcaseTypeDef returns[Def_Type def_type]
runsonReference = helper.runsonReference;
systemReference = helper.systemReference;
}
}
}
)
{
if($i.identifier != null) {
......@@ -3353,6 +3353,7 @@ pr_TestcaseDef returns[ Def_Testcase def_testcase]
Reference runsonReference = null;
Reference systemReference = null;
StatementBlock statementBlock = null;
StatementBlock finallyBlock = null;
}:
( col = pr_TestcaseKeyword
i = pr_Identifier
......@@ -3364,12 +3365,16 @@ pr_TestcaseDef returns[ Def_Testcase def_testcase]
if(helper != null) { runsonReference = helper.runsonReference; systemReference = helper.systemReference; }
}
s = pr_StatementBlock { statementBlock = $s.statementblock; }
pr_CatchBlockList?
fd = pr_FinallyDef {
finallyBlock = $fd.statementBlock;
}
)
{
if($i.identifier != null) {
if(parameters == null) { parameters = new TestcaseFormalParameterList(new ArrayList<FormalParameter>()); }
parameters.setLocation(getLocation( $start1.start, $end.stop));
$def_testcase = new Def_Testcase($i.identifier, parameters, runsonReference, systemReference, statementBlock);
$def_testcase = new Def_Testcase($i.identifier, parameters, runsonReference, systemReference, statementBlock, finallyBlock);
$def_testcase.setLocation(getLocation( $col.start, $s.stop));
$def_testcase.setCommentLocation( getLastCommentLocation( $start ) );
}
......@@ -3579,18 +3584,26 @@ pr_AltstepDef returns[ Def_Altstep def_altstep]
Configuration_Helper runsonHelper = new Configuration_Helper();
AltGuards altGuards = null;
List<Definition> definitions = null;
StatementBlock finallyBlock = null;
}:
( col = pr_AltstepKeyword
// CONTROL ?
// INTERLEAVE ?
i = pr_Identifier
start1 = pr_LParen
( p = pr_FunctionFormalParList { parameters = $p.parList;} )?
end = pr_RParen
( pr_RunsOnSpec[ runsonHelper ] )?
pr_AltOrTcConfigSpec[ runsonHelper ]
pr_ExceptionSpec ?
blockstart = pr_BeginChar
( d = pr_AltstepLocalDefList { definitions = $d.definitions; } )?
a = pr_AltGuardList { altGuards = $a.altGuards; }
endcol = pr_EndChar
pr_CatchBlockList?
fd = pr_FinallyDef {
finallyBlock = $fd.statementBlock;
}
)
{
if($i.identifier != null && altGuards != null ) {
......@@ -3606,7 +3619,7 @@ pr_AltstepDef returns[ Def_Altstep def_altstep]
if(parameters == null) { parameters = new FormalParameterList(new ArrayList<FormalParameter>()); }
parameters.setLocation(getLocation( $start1.start, $end.stop));
altGuards.setLocation(getLocation( $a.start, $a.stop));
$def_altstep = new Def_Altstep($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, statementBlock, altGuards);
$def_altstep = new Def_Altstep($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, statementBlock, finallyBlock, altGuards);
$def_altstep.setLocation(getLocation( $col.start, $endcol.stop));
}
};
......@@ -9074,6 +9087,7 @@ pr_ClassTypeDef returns[Def_Type def_type]
ClassTypeBody body = null;
ClassTypeReferenceList refs = null;
VisibilityModifier visibility = VisibilityModifier.Protected;
Location modifierLocation = null;
boolean isAbstract = false;
boolean isFinal = false;
boolean isTrait = false;
......@@ -9082,9 +9096,12 @@ pr_ClassTypeDef returns[Def_Type def_type]
}:
( ( ext = pr_ExtKeyword { isExternal = true; } )?
kw = pr_ClassKeyword
( fm = pr_FinalModifier { isFinal = $fm.isFinal; } )?
( am = pr_AbstractModifier { isAbstract = $am.isAbstract; } )?
( tm = pr_TraitModifier { isTrait = $tm.isTrait; } )?
cm = pr_ClassModifier {
isFinal = $cm.isFinal;
isAbstract = $cm.isAbstract;
isTrait = $cm.isTrait;
modifierLocation = getLocation( $cm.start, $cm.stop );
}
i = pr_Identifier
ecd = pr_ExtendsClassDef { refs = $ecd.refList; }
(runson = pr_RunsOnSpec[runsonHelper] {
......@@ -9114,7 +9131,7 @@ pr_ClassTypeDef returns[Def_Type def_type]
if (body == null) {
body = new ClassTypeBody($i.identifier, refs);
}
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, getLocation($kw.stop, $i.start), runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, finallyBlock);
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, modifierLocation, runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, finallyBlock);
type.setLocation(getLocation($start, getLastVisibleToken()));
$def_type = new Def_Type($i.identifier, type);
$def_type.setLocation(getLocation($kw.start, $i.stop));
......@@ -9127,6 +9144,19 @@ pr_ClassKeyword:
CLASS
);
pr_ClassModifier returns[boolean isAbstract, boolean isFinal, boolean isTrait]
@init {
$isAbstract = false;
$isFinal = false;
$isTrait = false;
}:
(
FINALKEYWORD { $isFinal = true;}
| ABSTRACTKEYWORD { $isAbstract = true; }
| TRAITKEYWORD { $isTrait = true; }
)*
;
pr_FinalModifier returns[boolean isFinal]
@init {
$isFinal = false;
......@@ -9141,13 +9171,6 @@ pr_AbstractModifier returns[boolean isAbstract]
ABSTRACTKEYWORD { $isAbstract = true; }
;
pr_TraitModifier returns[boolean isTrait]
@init {
$isTrait = false;
}:
TRAITKEYWORD { $isTrait = true; }
;
pr_ExtendsClassDef returns[ClassTypeReferenceList refList]
@init {
$refList = new ClassTypeReferenceList();
......@@ -9268,16 +9291,19 @@ pr_ClassFunctionDef returns[Def_Function def_func]
TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
boolean isAbstract = false;
boolean isFinal = false;
boolean isTrait = false;
boolean isDeterministic = false;
Location modifierLocation = null;
SignatureExceptions exceptions = null;
}:
(
pr_ExtKeyword?
col = pr_FunctionKeyword
( fm = pr_FinalModifier { isFinal = $fm.isFinal; modifierLocation = getLocation($fm.start); } )?
( am = pr_AbstractModifier { isAbstract = $am.isAbstract; modifierLocation = getLocation($am.start); } )?
pr_DeterministicModifier?
cfm = pr_ClassFunctionModifier {
isFinal = $cfm.isFinal;
isAbstract = $cfm.isAbstract;
isDeterministic = $cfm.isDeterministic;
modifierLocation = getLocation( $cfm.start, $cfm.stop );
}
id = pr_Identifier
start1 = pr_LParen
(pl = pr_FunctionFormalParList { parameters = $pl.parList; } )?
......@@ -9310,6 +9336,19 @@ pr_ClassFunctionDef returns[Def_Function def_func]
}
};
pr_ClassFunctionModifier returns[boolean isAbstract, boolean isFinal, boolean isDeterministic]
@init {
$isAbstract = false;
$isFinal = false;
$isDeterministic = false;
}:
(
FINALKEYWORD { $isFinal = true;}
| ABSTRACTKEYWORD { $isAbstract = true; }
| DETERMINISTICKEYWORD { $isDeterministic = true; }
)*
;
pr_ClassConstructorDef returns[Def_Function def_func]
@init {
FormalParameterList parameters = null;
......
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