Skip to content
Snippets Groups Projects
Commit b54e7c15 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: allow member id reuse in member functions


Signed-off-by: default avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 4408d862
No related branches found
No related tags found
1 merge request!710OOP: allow member id reuse in member functions
......@@ -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;
......
......@@ -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
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment