use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method isSubtypeCompatible.
/**
* Checks that the provided type is sub-type compatible with the actual
* set of type.
* <p>
* In case of sequence/set/array this means that the number of their
* fields fulfills the length restriction of the set of type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param other
* the type to check against.
*
* @return true if they are sub-type compatible, false otherwise.
*/
public boolean isSubtypeCompatible(final CompilationTimeStamp timestamp, final IType other) {
if (subType == null || other == null) {
return true;
}
long nofComponents;
switch(other.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
nofComponents = ((ASN1_Sequence_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SEQUENCE:
nofComponents = ((TTCN3_Sequence_Type) other).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComponents = ((ASN1_Set_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SET:
nofComponents = ((TTCN3_Set_Type) other).getNofComponents();
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
if (other.getSubtype() == null) {
return true;
}
return subType.isCompatible(timestamp, other.getSubtype());
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) other).getDimension();
if (dimension.getIsErroneous(timestamp)) {
return false;
}
nofComponents = dimension.getSize();
break;
}
default:
return false;
}
final List<ParsedSubType> tempRestrictions = new ArrayList<ParsedSubType>(1);
final Integer_Value length = new Integer_Value(nofComponents);
tempRestrictions.add(new Length_ParsedSubType(new SingleLenghtRestriction(length)));
final SubType tempSubtype = new SubType(getSubtypeType(), this, tempRestrictions, null);
tempSubtype.check(timestamp);
return subType.isCompatible(timestamp, tempSubtype);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_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