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

OOP: added timestamp for checking extends list


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 816b1942
...@@ -262,7 +262,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -262,7 +262,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
extendsReferences.check(timestamp); extendsReferences.check(timestamp);
final List<ClassTypeBody> bodies = getExtendsInheritedClassBodies(); final List<ClassTypeBody> bodies = getExtendsInheritedClassBodies(timestamp);
for (final ClassTypeBody body : bodies) { for (final ClassTypeBody body : bodies) {
final Map<String, Definition> subDefinitionMap = body.getDefinitionMap(); final Map<String, Definition> subDefinitionMap = body.getDefinitionMap();
for (final Definition definition : subDefinitionMap.values()) { for (final Definition definition : subDefinitionMap.values()) {
...@@ -364,15 +364,16 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -364,15 +364,16 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
* *
* @return the collected class type bodies. * @return the collected class type bodies.
* */ * */
public List<ClassTypeBody> getExtendsInheritedClassBodies() { public List<ClassTypeBody> getExtendsInheritedClassBodies(CompilationTimeStamp timestamp) {
final List<ClassTypeBody> result = new ArrayList<ClassTypeBody>(); final List<ClassTypeBody> result = new ArrayList<ClassTypeBody>();
final LinkedList<ClassTypeBody> toBeChecked = new LinkedList<ClassTypeBody>(extendsReferences.getClassBodies()); extendsReferences.check(timestamp);
final LinkedList<ClassTypeBody> toBeChecked = new LinkedList<ClassTypeBody>(extendsReferences.getClassBodies(timestamp));
while(!toBeChecked.isEmpty()) { while(!toBeChecked.isEmpty()) {
final ClassTypeBody body = toBeChecked.removeFirst(); final ClassTypeBody body = toBeChecked.removeFirst();
if(!result.contains(body)) { if(!result.contains(body)) {
result.add(body); result.add(body);
if (body.extendsReferences != null && body.extendsReferences.getClassBodies() != null) { if (body.extendsReferences != null && body.extendsReferences.getClassBodies(null) != null) {
for(final ClassTypeBody subBody : body.extendsReferences.getClassBodies()) { for(final ClassTypeBody subBody : body.extendsReferences.getClassBodies(null)) {
if(!result.contains(subBody) && !toBeChecked.contains(subBody)) { if(!result.contains(subBody) && !toBeChecked.contains(subBody)) {
toBeChecked.add(subBody); toBeChecked.add(subBody);
} }
...@@ -385,7 +386,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -385,7 +386,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
} }
public Assignment getAssFromParents(final CompilationTimeStamp timestamp, final Reference reference) { public Assignment getAssFromParents(final CompilationTimeStamp timestamp, final Reference reference) {
final LinkedList<ClassTypeBody> toBeChecked = new LinkedList<ClassTypeBody>(extendsReferences.getClassBodies()); final LinkedList<ClassTypeBody> toBeChecked = new LinkedList<ClassTypeBody>(extendsReferences.getClassBodies(null));
Assignment assignment = null; Assignment assignment = null;
for (ClassTypeBody body : toBeChecked) { for (ClassTypeBody body : toBeChecked) {
......
...@@ -71,7 +71,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable ...@@ -71,7 +71,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
this.myClass = parentClass; this.myClass = parentClass;
} }
public List<ClassTypeBody> getClassBodies() { public List<ClassTypeBody> getClassBodies(CompilationTimeStamp timestamp) {
if (timestamp != null) {
checkUniqueness(timestamp);
}
return orderedClassTypeBodies; return orderedClassTypeBodies;
} }
......
...@@ -554,14 +554,16 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -554,14 +554,16 @@ public final class Class_Type extends Type implements ITypeWithComponents {
* @param class to be checked * @param class to be checked
* @return * @return
*/ */
public boolean isRelatedClass(Class_Type related) { public boolean isRelatedClass(CompilationTimeStamp timestamp, Class_Type related) {
List<ClassTypeBody> bodies = getClassBody().getExtendsInheritedClassBodies(); getClassBody().check(timestamp);
List<ClassTypeBody> bodies = getClassBody().getExtendsInheritedClassBodies(timestamp);
for (ClassTypeBody body : bodies) { for (ClassTypeBody body : bodies) {
if (body.getMyType() == related) { if (body.getMyType() == related) {
return true; return true;
} }
} }
List<ClassTypeBody> relatedBodies = related.getClassBody().getExtendsInheritedClassBodies(); related.getClassBody().check(timestamp);
List<ClassTypeBody> relatedBodies = related.getClassBody().getExtendsInheritedClassBodies(timestamp);
for (ClassTypeBody body : relatedBodies) { for (ClassTypeBody body : relatedBodies) {
if (body.getMyType() == this) { if (body.getMyType() == this) {
return true; return true;
......
...@@ -90,7 +90,7 @@ public class ClassCastingExpression extends Expression_Value { ...@@ -90,7 +90,7 @@ public class ClassCastingExpression extends Expression_Value {
} }
} }
if (leftClass != null && rightClass != null) { if (leftClass != null && rightClass != null) {
if (leftClass.isRelatedClass(rightClass) == false) { if (leftClass.isRelatedClass(timestamp, rightClass) == false) {
getLocation().reportSemanticError(CASTINGTOUNRELATED); getLocation().reportSemanticError(CASTINGTOUNRELATED);
} }
} }
......
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