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

OOP: fixed false semantic errors for inherited members


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 10502b1a
...@@ -94,6 +94,9 @@ public abstract class Definition extends Assignment implements IAppendableSyntax ...@@ -94,6 +94,9 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
protected String genName = ""; protected String genName = "";
private Location commentLocation = null; private Location commentLocation = null;
/** Indicates if the definition is inherited from a parent class */
private boolean isInherited = false;
/** /**
* The cumulative location of a definition is the location of the definition if it is stand alone, * The cumulative location of a definition is the location of the definition if it is stand alone,
...@@ -795,4 +798,12 @@ public abstract class Definition extends Assignment implements IAppendableSyntax ...@@ -795,4 +798,12 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
ErrorReporter.INTERNAL_ERROR("Code generator reached Definition.generateCodeInitComp `" + getFullName() + "'' incorrectly"); ErrorReporter.INTERNAL_ERROR("Code generator reached Definition.generateCodeInitComp `" + getFullName() + "'' incorrectly");
aData.getSrc().append("FATAL_ERROR encountered while processing `" + getFullName() + "''\n"); aData.getSrc().append("FATAL_ERROR encountered while processing `" + getFullName() + "''\n");
} }
public void setInherited(boolean isInherited) {
this.isInherited = isInherited;
}
public boolean isInherited() {
return isInherited;
}
} }
...@@ -26,6 +26,7 @@ import org.eclipse.titan.designer.AST.ISubReference; ...@@ -26,6 +26,7 @@ import org.eclipse.titan.designer.AST.ISubReference;
import org.eclipse.titan.designer.AST.Identifier; import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Location; import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.ReferenceChain;
import org.eclipse.titan.designer.AST.ReferenceFinder; import org.eclipse.titan.designer.AST.ReferenceFinder;
import org.eclipse.titan.designer.AST.Scope; import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.IType; import org.eclipse.titan.designer.AST.IType;
...@@ -254,10 +255,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -254,10 +255,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
private void addDefinitionsOfExtendsParents(final CompilationTimeStamp timestamp) { private void addDefinitionsOfExtendsParents(final CompilationTimeStamp timestamp) {
extendsGainedDefinitions.clear(); extendsGainedDefinitions.clear();
if (extendsReferences != null) { if (extendsReferences == null) {
extendsReferences.check(timestamp); return;
} }
extendsReferences.check(timestamp);
final List<ClassTypeBody> bodies = getExtendsInheritedClassBodies(); final List<ClassTypeBody> bodies = getExtendsInheritedClassBodies();
for (final ClassTypeBody body : bodies) { for (final ClassTypeBody body : bodies) {
final Map<String, Definition> subDefinitionMap = body.getDefinitionMap(); final Map<String, Definition> subDefinitionMap = body.getDefinitionMap();
...@@ -265,6 +268,9 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -265,6 +268,9 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
final String name = definition.getIdentifier().getName(); final String name = definition.getIdentifier().getName();
if (definitions.hasDefinition(name)) { if (definitions.hasDefinition(name)) {
final Definition localDefinition = definitions.getDefinition(name); final Definition localDefinition = definitions.getDefinition(name);
if (localDefinition.isInherited()) {
continue;
}
final VisibilityModifier modifier = definition.getVisibilityModifier(); final VisibilityModifier modifier = definition.getVisibilityModifier();
if (!(definition instanceof Def_Function)) { if (!(definition instanceof Def_Function)) {
localDefinition.getLocation().reportSemanticError(FIELDNOOVERRIDE); localDefinition.getLocation().reportSemanticError(FIELDNOOVERRIDE);
...@@ -304,7 +310,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -304,7 +310,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
} }
} else if (extendsGainedDefinitions.containsKey(name)) { } else if (extendsGainedDefinitions.containsKey(name)) {
final Definition previousDefinition = extendsGainedDefinitions.get(name); final Definition previousDefinition = extendsGainedDefinitions.get(name);
if (!previousDefinition.equals(definition)) { if (!previousDefinition.equals(definition) && !previousDefinition.isInherited()) {
// it is not the same definition inherited on two paths // it is not the same definition inherited on two paths
if (this.equals(previousDefinition.getMyScope())) { if (this.equals(previousDefinition.getMyScope())) {
previousDefinition.getLocation().reportSemanticError(MessageFormat.format(LOCALINHERITANCECOLLISION, previousDefinition.getLocation().reportSemanticError(MessageFormat.format(LOCALINHERITANCECOLLISION,
...@@ -322,6 +328,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -322,6 +328,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
} }
} }
} else { } else {
definition.setInherited(true);
extendsGainedDefinitions.put(name, definition); extendsGainedDefinitions.put(name, definition);
if (!definition.getMyScope().getModuleScope().equals(parentScope.getModuleScope())) { if (!definition.getMyScope().getModuleScope().equals(parentScope.getModuleScope())) {
......
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