From b54e7c15345f24f9fb50fb2f8c8b583475a58324 Mon Sep 17 00:00:00 2001 From: Miklos Magyari <miklos.magyari@sigmatechnology.se> Date: Fri, 9 Jul 2021 11:59:42 +0200 Subject: [PATCH] OOP: allow member id reuse in member functions Signed-off-by: Miklos Magyari <miklos.magyari@sigmatechnology.se> --- .../src/Basic_tests/OopPositiveBasicSyntax.ttcn | 14 ++++++++++++++ .../AST/TTCN3/definitions/FormalParameterList.java | 14 +++++++++++++- .../AST/TTCN3/statements/StatementBlock.java | 14 +++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Semantic_Analizer_Tests/src/Basic_tests/OopPositiveBasicSyntax.ttcn b/Semantic_Analizer_Tests/src/Basic_tests/OopPositiveBasicSyntax.ttcn index 8708fc6f3b..f0d5228a38 100644 --- a/Semantic_Analizer_Tests/src/Basic_tests/OopPositiveBasicSyntax.ttcn +++ b/Semantic_Analizer_Tests/src/Basic_tests/OopPositiveBasicSyntax.ttcn @@ -135,6 +135,20 @@ type class SuperBaseClass { } } +// class method identifier reuse in method formal parameters or method body +type class ReuseClass { + var integer pl_orig := 10; + var charstring cl_orig := "abc"; + + function f_reuse_in_paramlist(in charstring pl_orig) return integer { + return 0; + } + + function f_reuse_in_body(integer pl_param) { + const float cl_orig := 0.1; + } +} + type class SubClass4 extends SuperBaseClass { private const integer m_const2 := 2; private const integer m_const3 := 2; diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/FormalParameterList.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/FormalParameterList.java index 50c9e59075..da755ecf1c 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/FormalParameterList.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/FormalParameterList.java @@ -29,6 +29,7 @@ import org.eclipse.titan.designer.AST.IValue; import org.eclipse.titan.designer.AST.Identifier; import org.eclipse.titan.designer.AST.Location; import org.eclipse.titan.designer.AST.NULL_Location; +import org.eclipse.titan.designer.AST.NamedBridgeScope; import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.ReferenceChain; import org.eclipse.titan.designer.AST.ReferenceFinder; @@ -39,7 +40,9 @@ import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; import org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable; import org.eclipse.titan.designer.AST.TTCN3.TTCN3Scope; import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter.parameterEvaluationType; +import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type; +import org.eclipse.titan.designer.AST.TTCN3.types.ClassTypeBody; import org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter; import org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters; import org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template; @@ -276,7 +279,7 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode, for (int i = 0, size = parameters.size(); i < size; i++) { FormalParameter parameter = parameters.get(i); final Identifier identifier = parameter.getIdentifier(); - if (parentScope != null) { + if (parentScope != null && ! isInClassBody()) { if (parentScope.hasAssignmentWithId(timestamp, identifier)) { parameter.getLocation().reportSemanticError( MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName())); @@ -359,6 +362,15 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode, lastTimeChecked = timestamp; } + + private boolean isInClassBody() { + Scope scope = parentScope; + do { + scope = scope.getParentScope(); + } while (scope instanceof StatementBlock || scope instanceof FormalParameterList || scope instanceof NamedBridgeScope); + + return scope instanceof ClassTypeBody; + } /** * Checks the properties of the parameter list, that can only be checked 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 5c9181368f..a89b678e3c 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 @@ -30,6 +30,7 @@ import org.eclipse.titan.designer.AST.ISubReference; import org.eclipse.titan.designer.AST.Identifier; import org.eclipse.titan.designer.AST.Location; import org.eclipse.titan.designer.AST.NULL_Location; +import org.eclipse.titan.designer.AST.NamedBridgeScope; import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.ReferenceFinder; import org.eclipse.titan.designer.AST.ReferenceFinder.Hit; @@ -41,7 +42,9 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase; import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition; +import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList; import org.eclipse.titan.designer.AST.TTCN3.statements.Statement.Statement_type; +import org.eclipse.titan.designer.AST.TTCN3.types.ClassTypeBody; import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type; import org.eclipse.titan.designer.compiler.JavaGenData; import org.eclipse.titan.designer.editors.ProposalCollector; @@ -501,7 +504,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode, } } else { definitionMap.put(definitionName, definition); - if (parentScope != null && definition.getLocation() != null) { + if (parentScope != null && ! isInClassBody() && definition.getLocation() != null) { if (parentScope.hasAssignmentWithId(timestamp, identifier)) { definition.getLocation().reportSemanticError( MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName())); @@ -521,6 +524,15 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode, } } } + + private boolean isInClassBody() { + Scope scope = parentScope; + do { + scope = scope.getParentScope(); + } while (scope instanceof StatementBlock || scope instanceof FormalParameterList || scope instanceof NamedBridgeScope); + + return scope instanceof ClassTypeBody; + } /** * Does the semantic checking of the statement block. -- GitLab