Search in sources :

Example 6 with Anytype_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Anytype_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");
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)

Aggregations

ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)4 Anytype_Type (org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)3 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)3 IType (org.eclipse.titan.designer.AST.IType)3 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)3 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)3 IValue (org.eclipse.titan.designer.AST.IValue)2 AbstractOfType (org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType)2 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)2 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)2 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ASN1_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)1