diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Altstep.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Altstep.java index 7160c823024757bc8b77b0c1c0bf2d4fad03b7ca..03aa79024ec95f7ef68f566fb1e4ba28f93f7826 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Altstep.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Altstep.java @@ -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 = "."; @@ -57,6 +58,7 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig private static final String FULLNAMEPART4 = "."; private static final String FULLNAMEPART5 = "."; private static final String FULLNAMEPART6 = "."; + private static final String FULLNAMEPART7 = "."; 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(); diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Function.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Function.java index 43ef7141e19d753d1524045580a46657722fce03..23e7454d6307de656e2c714f847db9e9daaac838 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Function.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Function.java @@ -110,6 +110,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi private static final String FULLNAMEPART5 = "."; private static final String FULLNAMEPART6 = "."; private static final String FULLNAMEPART7 = "."; + private static final String FULLNAMEPART8 = "."; 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; diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Testcase.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Testcase.java index b14011dd29fa236c17b2b7fb033d7d7706acc47c..757115da9e3322b60faa0f38eaee684eabbc8907 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Testcase.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Testcase.java @@ -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 = "."; private static final String FULLNAMEPART2 = "."; private static final String FULLNAMEPART3 = "."; private static final String FULLNAMEPART4 = "."; + private static final String FULLNAMEPART5 = "."; 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); diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/statements/StatementBlock.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/statements/StatementBlock.java index 4f5afc009cd43969f427469ddfe6d808237b62c3..026ab226c57d9c3a4c11d34e2041647ba182969b 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/statements/StatementBlock.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/statements/StatementBlock.java @@ -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; } diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/types/Class_Type.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/types/Class_Type.java index 8eac279b29e982475ef015fc6fb3727a1149f6e0..acd4405c3108c366a43d141befa32057da466f47 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/types/Class_Type.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/types/Class_Type.java @@ -103,7 +103,7 @@ public final class Class_Type extends Type implements ITypeWithComponents { } if (finallyBlock != null) { finallyBlock.setFullNameParent(this); - finallyBlock.setOwnerIsDestructor(); + finallyBlock.setOwnerIsFinally(); } } diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3Parser.g4 b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3Parser.g4 index 261b2e887ed7da626f217af8ea076a07f22e6977..33544eb56ad6054c6942d7e219e422f3ee06ddd8 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3Parser.g4 +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3Parser.g4 @@ -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()); } 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 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()); } 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;