use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type 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.ASN1.types.ASN1_Sequence_Type 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.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Named_Template_List method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
if (asValue != null) {
asValue.generateCodeInit(aData, source, name);
return;
}
if (myGovernor == null) {
return;
}
// FIXME actually a bit more complex
final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (type == null) {
return;
}
if (namedTemplates.getNofTemplates() == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
}
// else is not needed as the loop will not run
for (int i = 0; i < namedTemplates.getNofTemplates(); i++) {
final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
final String fieldName = namedTemplate.getName().getName();
// FIXME handle needs_temp_ref case
final String generatedFieldName = FieldSubReference.getJavaGetterName(fieldName);
final TTCN3Template template = namedTemplate.getTemplate();
if (template.needsTemporaryReference()) {
Type fieldType;
switch(type.getTypetype()) {
case TYPE_SIGNATURE:
fieldType = ((Signature_Type) type).getParameterByName(fieldName).getType();
break;
case TYPE_TTCN3_SEQUENCE:
fieldType = ((TTCN3_Sequence_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_TTCN3_SET:
fieldType = ((TTCN3_Set_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_ASN1_SEQUENCE:
fieldType = ((ASN1_Sequence_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ASN1_SET:
fieldType = ((ASN1_Set_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ASN1_CHOICE:
fieldType = ((ASN1_Choice_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_TTCN3_CHOICE:
fieldType = ((TTCN3_Choice_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_OPENTYPE:
fieldType = ((Open_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ANYTYPE:
fieldType = ((Anytype_Type) type).getComponentByName(fieldName).getType();
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing named template list `" + getFullName() + "''");
return;
}
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.get{3}();\n", fieldType.getGenNameTemplate(aData, source, myScope), tempId, name, generatedFieldName));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.get{1}()", name, generatedFieldName);
template.generateCodeInit(aData, source, embeddedName);
}
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
Aggregations