use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class ASN1_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 temporalType = (ASN1_Sequence_Type) temp;
if (this == temporalType) {
return true;
}
if (getNofComponents(timestamp) != temporalType.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(temporalType);
}
for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
final CompField compField = getComponentByIndex(i);
final CompField temporalTypeCompField = temporalType.getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType temporalTypeCompFieldType = temporalTypeCompField.getType().getTypeRefdLast(timestamp);
if (compField.isOptional() != temporalTypeCompField.isOptional()) {
final String compFieldName = compField.getIdentifier().getDisplayName();
final String temporalTypeCompFieldName = temporalTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName);
info.appendOp2Ref("." + temporalTypeCompFieldName);
info.setOp1Type(compFieldType);
info.setOp2Type(temporalTypeCompFieldType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeCompFieldType, false);
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(temporalTypeCompFieldType);
if (!compFieldType.equals(temporalTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeCompFieldType, infoTemp, lChain, rChain)) {
final String compFieldame = compField.getIdentifier().getDisplayName();
final String temporalTypeCompFieldName = temporalTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldame + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + temporalTypeCompFieldName + 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 (getNofComponents(timestamp) != 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(timestamp); i < size; i++) {
final CompField compField = getComponentByIndex(i);
final CompField tempTypeComponentField = tempType.getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType temporalTypeCompFieldType = tempTypeComponentField.getType().getTypeRefdLast(timestamp);
if (compField.isOptional() != tempTypeComponentField.isOptional()) {
final String compFieldName = compField.getIdentifier().getDisplayName();
final String temporalTypeCompFieldName = tempTypeComponentField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName);
info.appendOp2Ref("." + temporalTypeCompFieldName);
info.setOp1Type(compFieldType);
info.setOp2Type(temporalTypeCompFieldType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeCompFieldType, false);
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(temporalTypeCompFieldType);
if (!compFieldType.equals(temporalTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeCompFieldType, infoTemp, lChain, rChain)) {
final String compFieldName = compField.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeComponentField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCompFieldName + 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 temporalType = (SequenceOf_Type) temp;
if (!temporalType.isSubtypeCompatible(timestamp, this)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final int thisNofComps = getNofComponents(timestamp);
if (thisNofComps == 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(temporalType);
}
for (int i = 0; i < thisNofComps; i++) {
final CompField compField = getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType temporalTypeOfType = temporalType.getOfType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeOfType, false);
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(temporalTypeOfType);
if (!compFieldType.equals(temporalTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeOfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + compField.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(timestamp);
if (nofComps == 0) {
return false;
}
final Array_Type temporalType = (Array_Type) temp;
final long temporalTypeNofComps = temporalType.getDimension().getSize();
if (nofComps != temporalTypeNofComps) {
info.setErrorStr(MessageFormat.format(NOFFIELDSDIMENSIONDONTMATCH, nofComps, temporalTypeNofComps));
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(temporalType);
}
for (int i = 0; i < nofComps; i++) {
final CompField compField = getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType tempTypeElementType = temporalType.getElementType().getTypeRefdLast(timestamp);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeElementType, false);
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(tempTypeElementType);
if (!compFieldType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + compField.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.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method setGenNameRecursive.
@Override
public /**
* {@inheritDoc}
*/
void setGenNameRecursive(final String parameterGenName) {
super.setGenNameRecursive(parameterGenName);
if (convertedValue != null) {
convertedValue.setGenNameRecursive(parameterGenName);
}
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null) {
return;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (Type_type.TYPE_TTCN3_SEQUENCE.equals(type.getTypetype())) {
for (int i = 0; i < values.getSize(); i++) {
final String name = values.getNamedValueByIndex(i).getName().getName();
if (((TTCN3_Sequence_Type) type).hasComponentWithName(name)) {
final StringBuilder embeddedName = new StringBuilder(parameterGenName);
embeddedName.append('.');
embeddedName.append(name);
embeddedName.append("()");
if (((TTCN3_Sequence_Type) type).getComponentByName(name).isOptional()) {
embeddedName.append(".get()");
}
final IValue v = values.getNamedValueByIndex(i).getValue();
if (v != null) {
v.setGenNameRecursive(embeddedName.toString());
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method checkEquality.
@Override
public /**
* {@inheritDoc}
*/
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
if (convertedValue != null && convertedValue != this) {
return convertedValue.checkEquality(timestamp, other);
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = other.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (!Value_type.SEQUENCE_VALUE.equals(last.getValuetype())) {
return false;
}
if (myGovernor == null) {
return false;
}
final Sequence_Value otherSequence = (Sequence_Value) last;
if (values.getSize() != otherSequence.values.getSize()) {
return false;
}
int nofComps = 0;
final IType leftGovernor = myGovernor.getTypeRefdLast(timestamp);
switch(leftGovernor.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
nofComps = ((TTCN3_Sequence_Type) leftGovernor).getNofComponents();
break;
case TYPE_ASN1_SEQUENCE:
nofComps = ((ASN1_Sequence_Type) leftGovernor).getNofComponents(timestamp);
break;
default:
return false;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(leftGovernor.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
compField = ((TTCN3_Sequence_Type) leftGovernor).getComponentByIndex(i);
break;
case TYPE_ASN1_SEQUENCE:
compField = ((ASN1_Sequence_Type) leftGovernor).getComponentByIndex(i);
break;
default:
return false;
}
final Identifier fieldName = compField.getIdentifier();
if (hasComponentWithName(fieldName)) {
final IValue leftValue = getComponentByName(fieldName).getValue();
if (otherSequence.hasComponentWithName(fieldName)) {
final IValue otherValue = otherSequence.getComponentByName(fieldName).getValue();
if ((Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && !Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) || (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && Value_type.OMIT_VALUE.equals(otherValue.getValuetype()))) {
return false;
}
if (!leftValue.checkEquality(timestamp, otherValue)) {
return false;
}
} else {
if (compField.hasDefault()) {
if (!leftValue.checkEquality(timestamp, compField.getDefault())) {
return false;
}
} else {
if (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype())) {
return false;
}
}
}
} else {
if (otherSequence.hasComponentWithName(fieldName)) {
final IValue otherValue = otherSequence.getComponentByName(fieldName).getValue();
if (compField.hasDefault()) {
if (Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) {
return false;
}
if (!compField.getDefault().checkEquality(timestamp, otherValue)) {
return false;
}
}
}
}
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
* generate_code_init_se in the compiler
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (convertedValue != null) {
return convertedValue.generateCodeInit(aData, source, name);
}
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
int nofComps = 0;
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
nofComps = ((TTCN3_Sequence_Type) type).getNofComponents();
break;
case TYPE_ASN1_SEQUENCE:
nofComps = ((ASN1_Sequence_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
if (nofComps == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
return source;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
compField = ((TTCN3_Sequence_Type) type).getComponentByIndex(i);
break;
case TYPE_ASN1_SEQUENCE:
compField = ((ASN1_Sequence_Type) type).getComponentByIndex(i);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
final Identifier fieldName = compField.getIdentifier();
IValue fieldValue;
if (hasComponentWithName(fieldName)) {
fieldValue = getComponentByName(fieldName).getValue();
if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
continue;
} else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
fieldValue = null;
}
} else // TODO add support for asn default values when needed
{
continue;
}
final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
if (fieldValue != null) {
// TODO handle the case when temporary reference is needed
final StringBuilder embeddedName = new StringBuilder();
embeddedName.append(name);
embeddedName.append(".get");
embeddedName.append(javaGetterName);
embeddedName.append("()");
if (compField.isOptional()) /*&& fieldValue.isCompound() */
{
embeddedName.append(".get()");
}
// TODO add extra handling for optional fields
fieldValue.generateCodeInit(aData, source, embeddedName.toString());
} else {
aData.addBuiltinTypeImport("Base_Template.template_sel");
source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
}
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
if (convertedValue != null && convertedValue != this) {
final IValue temp = convertedValue.getReferencedSubValue(timestamp, reference, actualSubReference, refChain);
if (temp != null && temp.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
return temp;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return null;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
return null;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
CompField compField;
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
if (values.hasNamedValueWithName(fieldId)) {
return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
compField = ((TTCN3_Sequence_Type) type).getComponentByName(fieldId.getDisplayName());
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result;
}
if (!reference.getUsedInIsbound()) {
subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound record field `{0}''", fieldId.getDisplayName()));
}
return null;
case TYPE_ASN1_SEQUENCE:
if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
if (values.hasNamedValueWithName(fieldId)) {
return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result;
} else if (compField.hasDefault()) {
return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
default:
return null;
}
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
Aggregations