use of org.eclipse.titan.designer.AST.TypeCompatibilityInfo in project titan.EclipsePlug-ins by eclipse.
the class ExpressionUtilities method checkExpressionOperatorCompatibilityInternal.
/**
* Checks the compatibility of expression operands in cases where
* operands are compared (and one or both of them can be enumerations).
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expression
* the original expression this check should be performed
* on (used to report errors if there are any)
* @param referenceChain
* an initialized reference chain to help detecting
* circular references.
* @param expectedValue
* the kind of the value to be expected.
* @param param1
* the first operand.
* @param param2
* the second operand.
*/
private static void checkExpressionOperatorCompatibilityInternal(final CompilationTimeStamp timestamp, final Expression_Value expression, final IReferenceChain referenceChain, final Expected_Value_type expectedValue, final IValue param1, final IValue param2) {
if (expression == null || param1 == null || param2 == null) {
return;
}
if (param1.getIsErroneous(timestamp) || param2.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
IValue operand1 = param1;
IValue operand2 = param2;
final Type_type tempType1 = operand1.getExpressionReturntype(timestamp, expectedValue);
final Type_type tempType2 = operand2.getExpressionReturntype(timestamp, expectedValue);
if (Type_type.TYPE_UNDEFINED.equals(tempType1)) {
if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype())) {
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand2.getValuetype())) {
final Scope scope = expression.getMyScope();
final Module module = scope.getModuleScope();
final Identifier identifier = ((Undefined_LowerIdentifier_Value) operand1).getIdentifier();
if (scope.hasAssignmentWithId(timestamp, identifier) || module.hasImportedAssignmentWithID(timestamp, identifier)) {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
final Identifier identifier2 = ((Undefined_LowerIdentifier_Value) operand2).getIdentifier();
if (scope.hasAssignmentWithId(timestamp, identifier2) || module.hasImportedAssignmentWithID(timestamp, identifier2)) {
operand2 = operand2.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand2.getValuetype())) {
operand2 = operand2.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
if (operand1.getIsErroneous(timestamp) || operand2.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
expression.getLocation().reportSemanticError(UNDETERMINABLEOPERANDSERROR);
expression.setIsErroneous(true);
return;
}
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType2)) {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand2.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType1)) {
operand2 = operand2.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
}
final IType type1 = operand1.getExpressionGovernor(timestamp, expectedValue);
final IType type2 = operand2.getExpressionGovernor(timestamp, expectedValue);
if (operand1.getIsErroneous(timestamp) || operand2.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
if (type1 != null) {
if (type2 != null) {
final TypeCompatibilityInfo info1 = new TypeCompatibilityInfo(type1, type2, true);
final TypeCompatibilityInfo info2 = new TypeCompatibilityInfo(type2, type1, true);
final boolean retVal1 = type1.isCompatible(timestamp, type2, info1, null, null);
final boolean retVal2 = type2.isCompatible(timestamp, type1, info2, null, null);
if (!retVal1 && !retVal2) {
expression.getLocation().reportSemanticError(info1.toString());
expression.setIsErroneous(true);
return;
}
if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
if (info1.getNeedsConversion()) {
expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type1.getTypename(), type2.getTypename()));
} else if (info2.getNeedsConversion()) {
expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type2.getTypename(), type1.getTypename()));
}
}
} else {
operand2.setMyGovernor(type1);
final IValue tempValue = type1.checkThisValueRef(timestamp, operand2);
if (Value_type.OMIT_VALUE.equals(operand2.getValuetype())) {
operand1.checkExpressionOmitComparison(timestamp, expectedValue);
} else {
type1.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempValue);
return;
}
}
} else if (type2 != null) {
operand1.setMyGovernor(type2);
final IValue tempValue = type2.checkThisValueRef(timestamp, operand1);
if (Value_type.OMIT_VALUE.equals(operand1.getValuetype())) {
operand2.checkExpressionOmitComparison(timestamp, expectedValue);
} else {
type2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, tempValue, operand2);
return;
}
} else {
if (Type_type.TYPE_UNDEFINED.equals(tempType1) || Type_type.TYPE_UNDEFINED.equals(tempType2)) {
expression.getLocation().reportSemanticError(PLEASEUSEREFERENCES);
expression.setIsErroneous(true);
return;
}
if (!Type.isCompatible(timestamp, tempType1, tempType2, false, false) && !Type.isCompatible(timestamp, tempType2, tempType1, false, false)) {
expression.getLocation().reportSemanticError(INCOMPATIBLEOPERANDERROR);
expression.setIsErroneous(true);
}
}
}
use of org.eclipse.titan.designer.AST.TypeCompatibilityInfo in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
return this == temp;
}
switch(temp.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
{
final ASN1_Sequence_Type tempType = (ASN1_Sequence_Type) temp;
if (getNofComponents() != tempType.getNofComponents(timestamp)) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
if (cf.isOptional() != tempTypeCf.isOptional()) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName);
info.appendOp2Ref("." + tempTypeCfName);
info.setOp1Type(cfType);
info.setOp2Type(tempTypeCfType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeCfType);
if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCfName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SEQUENCE:
{
final TTCN3_Sequence_Type tempType = (TTCN3_Sequence_Type) temp;
if (this == tempType) {
return true;
}
if (getNofComponents() != tempType.getNofComponents()) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
if (cf.isOptional() != tempTypeCf.isOptional()) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName);
info.appendOp2Ref("." + tempTypeCfName);
info.setOp1Type(cfType);
info.setOp2Type(tempTypeCfType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeCfType);
if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCfName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SEQUENCE_OF:
{
final SequenceOf_Type tempType = (SequenceOf_Type) temp;
if (!tempType.isSubtypeCompatible(timestamp, this)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final int nofComps = getNofComponents();
if (nofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < nofComps; i++) {
final CompField cf = getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeOfType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeOfType);
if (!cfType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + cf.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
if (infoTemp.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_ARRAY:
{
final int nofComps = getNofComponents();
if (nofComps == 0) {
return false;
}
final Array_Type tempType = (Array_Type) temp;
final long tempTypeNOfComps = tempType.getDimension().getSize();
if (nofComps != tempTypeNOfComps) {
info.setErrorStr(MessageFormat.format(NOFFIELDSDIMENSIONDONTMATCH, nofComps, tempTypeNOfComps));
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < nofComps; i++) {
final CompField cf = getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeElementType = tempType.getElementType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeElementType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeElementType);
if (!cfType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + cf.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
case TYPE_SET_OF:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TypeCompatibilityInfo in project titan.EclipsePlug-ins by eclipse.
the class SequenceOf_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType lastOtherType = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || lastOtherType.getIsErroneous(timestamp) || this == lastOtherType) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
// There is another chance to be compatible:
// If records of/sets of are strongly compatible, then the records of/sets of are compatible
final IType last = getTypeRefdLast(timestamp);
return last.isStronglyCompatible(timestamp, lastOtherType, info, leftChain, rightChain);
}
switch(lastOtherType.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final ASN1_Sequence_Type tempType = (ASN1_Sequence_Type) lastOtherType;
final int tempTypeNofComps = tempType.getNofComponents(timestamp);
if (tempTypeNofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeCfType);
if (!ofType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
if (infoTemp.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SEQUENCE:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final TTCN3_Sequence_Type tempType = (TTCN3_Sequence_Type) lastOtherType;
final int tempTypeNofComps = tempType.getNofComponents();
if (tempTypeNofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeCfType);
if (!ofType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
if (infoTemp.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SEQUENCE_OF:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final SequenceOf_Type tempType = (SequenceOf_Type) lastOtherType;
if (this == tempType) {
return true;
}
final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeOfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeOfType, false);
if (!ofType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
// type.
if (info.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
if (info.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ARRAY:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final Array_Type tempType = (Array_Type) lastOtherType;
final IType tempTypeElementType = tempType.getElementType().getTypeRefdLast(timestamp);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeElementType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeElementType, false);
if (!ofType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
if (infoTemp.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
case TYPE_SET_OF:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TypeCompatibilityInfo in project titan.EclipsePlug-ins by eclipse.
the class SetOf_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType lastOtherType = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || lastOtherType.getIsErroneous(timestamp) || this == lastOtherType) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
// There is another chance to be compatible:
// If records of/sets of are strongly compatible, then the records of/sets of are compatible
final IType last = getTypeRefdLast(timestamp);
return last.isStronglyCompatible(timestamp, lastOtherType, info, leftChain, rightChain);
}
switch(lastOtherType.getTypetype()) {
case TYPE_ASN1_SET:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible set of/SET OF subtypes");
return false;
}
final ASN1_Set_Type tempType = (ASN1_Set_Type) lastOtherType;
final int tempTypeNofComps = tempType.getNofComponents(timestamp);
if (tempTypeNofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeCfType);
if (!ofType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
if (infoTemp.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SET:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible set of/SET OF subtypes");
return false;
}
final TTCN3_Set_Type tempType = (TTCN3_Set_Type) lastOtherType;
final int tempTypeNofComps = tempType.getNofComponents();
if (tempTypeNofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType ofType = getOfType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeCfType);
if (!ofType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
if (infoTemp.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SET_OF:
{
if (!isSubtypeCompatible(timestamp, lastOtherType)) {
info.setErrorStr("Incompatible set of/SET OF subtypes");
return false;
}
final SetOf_Type tempType = (SetOf_Type) lastOtherType;
if (this == tempType) {
return true;
}
final IType ofType = getOfType().getTypeRefdLast(timestamp);
final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
lChain.markState();
rChain.markState();
lChain.add(ofType);
rChain.add(tempTypeOfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(ofType, tempTypeOfType, false);
if (!ofType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !ofType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
if (info.getOp1RefStr().length() > 0) {
info.appendOp1Ref("[]");
}
if (info.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_SEQUENCE_OF:
case TYPE_ARRAY:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TypeCompatibilityInfo in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
return this == temp;
}
switch(temp.getTypetype()) {
case TYPE_ASN1_SET:
{
final ASN1_Set_Type tempType = (ASN1_Set_Type) temp;
if (getNofComponents() != tempType.getNofComponents(timestamp)) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
if (cf.isOptional() != tempTypeCf.isOptional()) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName);
info.appendOp2Ref("." + tempTypeCfName);
info.setOp1Type(cfType);
info.setOp2Type(tempTypeCfType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeCfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCfName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SET:
{
final TTCN3_Set_Type tempType = (TTCN3_Set_Type) temp;
if (this == tempType) {
return true;
}
if (getNofComponents() != tempType.getNofComponents()) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
if (cf.isOptional() != tempTypeCf.isOptional()) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName);
info.appendOp2Ref("." + tempTypeCompFieldName);
info.setOp1Type(cfType);
info.setOp2Type(tempTypeCfType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeCfType);
if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
final String cfName = cf.getIdentifier().getDisplayName();
final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCfName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SET_OF:
{
final SetOf_Type tempType = (SetOf_Type) temp;
if (!tempType.isSubtypeCompatible(timestamp, this)) {
info.setErrorStr("Incompatible set of/SET OF subtypes");
return false;
}
final int nofComps = getNofComponents();
if (nofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < nofComps; i++) {
final CompField cf = getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeOfType, false);
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeOfType);
if (!cfType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + cf.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
if (infoTemp.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_SEQUENCE_OF:
case TYPE_ARRAY:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
Aggregations