diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/ClassCasting_Value.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/ClassCasting_Value.java deleted file mode 100755 index 2a4d7f04881d9a3f6cfe21620ccb61d4d1ab38c5..0000000000000000000000000000000000000000 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/ClassCasting_Value.java +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2000-2022 Ericsson Telecom AB - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html - ******************************************************************************/ -package org.eclipse.titan.designer.AST.TTCN3.values; - -import org.eclipse.titan.designer.AST.ASTVisitor; -import org.eclipse.titan.designer.AST.IReferenceChain; -import org.eclipse.titan.designer.AST.IType.Type_type; -import org.eclipse.titan.designer.AST.IValue; -import org.eclipse.titan.designer.AST.Reference; -import org.eclipse.titan.designer.AST.Type; -import org.eclipse.titan.designer.AST.Value; -import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; -import org.eclipse.titan.designer.compiler.JavaGenData; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException; -import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater; - -/** - * - * @author Miklos Magyari - * - */ -public class ClassCasting_Value extends Value { - private final Type type; - private final Reference reference; - private final Reference leftReference; - - public ClassCasting_Value(final Type type, final Reference reference) { - this.type = type; - this.reference = reference; - - leftReference = null; - } - - public ClassCasting_Value(final Reference leftReference, final Reference reference) { - this.leftReference = leftReference; - this.reference = reference; - - type = null; - } - - @Override - public Value_type getValuetype() { - return Value_type.CLASS_VALUE; - } - - @Override - public Type_type getExpressionReturntype(CompilationTimeStamp timestamp, Expected_Value_type expectedValue) { - return Type_type.TYPE_CLASS; - } - - @Override - public boolean isUnfoldable(CompilationTimeStamp timestamp, Expected_Value_type expectedValue, - IReferenceChain referenceChain) { - // TODO Auto-generated method stub - return false; - } - - @Override - public IValue getReferencedSubValue(CompilationTimeStamp timestamp, Reference reference, int actualSubReference, - IReferenceChain refChain) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String createStringRepresentation() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean checkEquality(CompilationTimeStamp timestamp, IValue other) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException { - // TODO Auto-generated method stub - - } - - @Override - public StringBuilder generateCodeInit(JavaGenData aData, StringBuilder source, String name) { - // TODO Auto-generated method stub - return null; - } - - @Override - protected boolean memberAccept(ASTVisitor v) { - // TODO Auto-generated method stub - return false; - } -} diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/OfClass_Value.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/OfClass_Value.java deleted file mode 100755 index d9c843765a2140b0c8c83ae34f1ed9789cf9fe61..0000000000000000000000000000000000000000 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/OfClass_Value.java +++ /dev/null @@ -1,133 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2000-2022 Ericsson Telecom AB - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html - ******************************************************************************/ -package org.eclipse.titan.designer.AST.TTCN3.values; - -import org.eclipse.titan.designer.AST.ASTVisitor; -import org.eclipse.titan.designer.AST.Assignment; -import org.eclipse.titan.designer.AST.IReferenceChain; -import org.eclipse.titan.designer.AST.IType; -import org.eclipse.titan.designer.AST.IType.Type_type; -import org.eclipse.titan.designer.AST.IValue; -import org.eclipse.titan.designer.AST.Reference; -import org.eclipse.titan.designer.AST.Type; -import org.eclipse.titan.designer.AST.Value; -import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; -import org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type; -import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type; -import org.eclipse.titan.designer.compiler.JavaGenData; -import org.eclipse.titan.designer.parsers.CompilationTimeStamp; -import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException; -import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater; - -/** - * Represents a class of-operator - * ETSI ES 203 790 V1.3.1 (2021-05) - * 5.1.2.5 - * - * @author Miklos Magyari - * - */ -public class OfClass_Value extends Value { - private final Type type; - private final Reference reference; - - public OfClass_Value(final Type type, final Reference reference) { - this.type = type; - this.reference = reference; - } - - @Override - public Type_type getExpressionReturntype(CompilationTimeStamp timestamp, Expected_Value_type expectedValue) { - return Type_type.TYPE_BOOL; - } - - @Override - /** {@inheritDoc} */ - public IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) { - if (myGovernor != null) { - return myGovernor; - } - - return new Boolean_Type(); - } - - @Override - public Value_type getValuetype() { - return Value_type.BOOLEAN_VALUE; - } - - @Override - public boolean isUnfoldable(CompilationTimeStamp timestamp, Expected_Value_type expectedValue, - IReferenceChain referenceChain) { - // class of object reference - final Class_Type refClass = reference.checkVariableReference(timestamp) - .getTypeRefdLast(timestamp).getClassType(); - // expected class - final Class_Type expectedClass = type.getTypeRefdLast(timestamp).getClassType(); - - // the result is always false if the classes are not related to each other, - // otherwise a runtime check is required - return refClass.isParentClass(timestamp, expectedClass) || - expectedClass.isParentClass(timestamp, refClass); - } - - @Override - /** {@inheritDoc} */ - public boolean checkExpressionSelfReferenceValue(final CompilationTimeStamp timestamp, final Assignment lhs) { - if (lhs != null) { - final Assignment assignment = reference.getRefdAssignment(timestamp, false); - return assignment == lhs; - } - return false; - } - - @Override - public String createStringRepresentation() { - return reference.getDisplayName() + " of " + type.getTypename(); - } - - @Override - /** {@inheritDoc} */ - public boolean canGenerateSingleExpression() { - return reference.hasSingleExpression(); - } - - @Override - protected boolean memberAccept(ASTVisitor v) { - if (reference != null && !reference.accept(v)) { - return false; - } - return true; - } - - @Override - public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException { - if (isDamaged) { - throw new ReParseException(); - } - } - - @Override - public IValue getReferencedSubValue(CompilationTimeStamp timestamp, Reference reference, int actualSubReference, - IReferenceChain refChain) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean checkEquality(CompilationTimeStamp timestamp, IValue other) { - // TODO Auto-generated method stub - return false; - } - - @Override - public StringBuilder generateCodeInit(JavaGenData aData, StringBuilder source, String name) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/ClassCastingExpression.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/ClassCastingExpression.java index 4e72095a147b150f270155893780aef8fabc0454..baa2a3fa9a4e317797cbceef9efa2e27eb16fdf2 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/ClassCastingExpression.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/ClassCastingExpression.java @@ -17,7 +17,8 @@ import org.eclipse.titan.designer.parsers.CompilationTimeStamp; import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException; import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater; -/** Represents TTCN3 class casting expressions (OOP extension) +/** + * Represents TTCN3 class casting expressions (OOP extension) * * @author Miklos Magyari * @@ -28,9 +29,9 @@ public class ClassCastingExpression extends Expression_Value { private static final String CLASSTYPEEXPECTED = "Class type was expected"; private static final String CANNOTCAST = "Cannot cast an object of class type `{0}'' to class type `{1}''"; - private final Type type; private final Reference rightReference; - private final Reference leftReference; + private Type type; + private Reference leftReference; public ClassCastingExpression(final Type type, final Reference reference) { this.type = type; @@ -70,6 +71,18 @@ public class ClassCastingExpression extends Expression_Value { return Type_type.TYPE_CLASS; } + @Override + /** {@inheritDoc} */ + public IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) { + final IType governor = super.getMyGovernor(); + + if (governor != null) { + return governor; + } + + return new Class_Type(); + } + @Override /** {@inheritDoc} */ public void setMyScope(final Scope scope) { @@ -97,7 +110,7 @@ public class ClassCastingExpression extends Expression_Value { lastTimeChecked = timestamp; lastValue = this; - if ((leftReference == null && rightReference == null) || type == null) { + if ((leftReference == null && rightReference == null) || (type == null && rightReference == null)) { setIsErroneous(true); return lastValue; } @@ -109,10 +122,21 @@ public class ClassCastingExpression extends Expression_Value { } if (!isUnfoldable(timestamp)) { - setMyGovernor(type.getTypeRefdLast(timestamp)); + if (type != null) { + setMyGovernor(type.getTypeRefdLast(timestamp)); + } + + // this differs from titan core as we still have the reference + // and it is not converted to a type + if (leftReference != null) { + final IType leftRefType = leftReference.checkVariableReference(timestamp); + if (leftRefType != null) { + setMyGovernor(leftRefType.getTypeRefdLast(timestamp)); + } + } } - return null; + return lastValue; } @Override @@ -138,7 +162,18 @@ public class ClassCastingExpression extends Expression_Value { @Override public boolean isUnfoldable(CompilationTimeStamp timestamp, Expected_Value_type expectedValue, IReferenceChain referenceChain) { - // TODO Auto-generated method stub + if (type != null) { + return type.isIdentical(timestamp, rightReference.checkVariableReference(timestamp)); + } + + // this differs from titan core as we still have the reference + // and it is not converted to a type + if (leftReference != null) { + final IType leftRefType = leftReference.checkVariableReference(timestamp); + if (leftRefType != null) { + return leftRefType.isIdentical(timestamp, rightReference.checkVariableReference(timestamp)); + } + } return false; } @@ -173,16 +208,26 @@ public class ClassCastingExpression extends Expression_Value { } else { setIsErroneous(true); } - type.check(timestamp); - final IType typeLast = type.getTypeRefdLast(timestamp); - if (typeLast.getTypetype() != Type_type.TYPE_CLASS) { - type.getLocation().reportSemanticError(CLASSTYPEEXPECTED); - setIsErroneous(true); - } else if (! getIsErroneous(timestamp)) { - final Class_Type newClass = typeLast.getClassType(); - final Class_Type oldClass = typeRefdLast.getClassType(); - if (!newClass.isParentClass(timestamp, oldClass) && !oldClass.isParentClass(timestamp, newClass)) { - getLocation().reportSemanticError(MessageFormat.format(CANNOTCAST, typeRefdLast.getTypename(), type.getTypename())); + + if (type != null) { + type.check(timestamp); + final IType typeLast = type.getTypeRefdLast(timestamp); + if (typeLast.getTypetype() != Type_type.TYPE_CLASS) { + type.getLocation().reportSemanticError(CLASSTYPEEXPECTED); + setIsErroneous(true); + } else if (! getIsErroneous(timestamp)) { + final Class_Type newClass = typeLast.getClassType(); + final Class_Type oldClass = typeRefdLast.getClassType(); + if (!newClass.isParentClass(timestamp, oldClass) && !oldClass.isParentClass(timestamp, newClass)) { + getLocation().reportSemanticError(MessageFormat.format(CANNOTCAST, typeRefdLast.getTypename(), type.getTypename())); + } + } + } + + // We differ from titan core here as we do not convert left reference to type + if (leftReference != null) { + if (leftReference.checkVariableReference(timestamp) == null) { + setIsErroneous(true); } } } diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/OfClassExpression.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/OfClassExpression.java index 29bfe9be2594974053b503c2042e467e95c09871..b1299aac4b70a6e9c1630c5dd7ce14074637d207 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/OfClassExpression.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/values/expressions/OfClassExpression.java @@ -91,7 +91,7 @@ public class OfClassExpression extends Expression_Value { if (!isUnfoldable(timestamp)) { value = false; } - return null; + return lastValue; } @Override