Search in sources :

Example 56 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Choice_Type method generateCodeIsPresentBoundChosen.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, final String field) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return;
    }
    if (subReferenceIndex >= subreferences.size()) {
        return;
    }
    final StringBuilder closingBrackets = new StringBuilder();
    if (isTemplate) {
        boolean anyvalueReturnValue = true;
        if (optype == Operation_type.ISPRESENT_OPERATION) {
            anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
        } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
            anyvalueReturnValue = false;
        }
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
        expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
        expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
        expression.expression.append("break;\n");
        expression.expression.append("case ANY_VALUE:\n");
        expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
        expression.expression.append("break;\n");
        expression.expression.append("case SPECIFIC_VALUE:{\n");
        closingBrackets.append("break;}\n");
        closingBrackets.append("default:\n");
        closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
        closingBrackets.append("break;\n");
        closingBrackets.append("}\n");
        closingBrackets.append("}\n");
    }
    final ISubReference subReference = subreferences.get(subReferenceIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2}.union_selection_type.ALT_{3});\n", globalId, externalId, getGenNameValue(aData, expression.expression, myScope), FieldSubReference.getJavaGetterName(fieldId.getName())));
    expression.expression.append("}\n");
    final CompField compField = getComponentByName(fieldId.getName());
    final Type nextType = compField.getType();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    closingBrackets.insert(0, "}\n");
    final String temporalId = aData.getTemporaryVariableName();
    final String temporalId2 = aData.getTemporaryVariableName();
    expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
    expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
    if (optype == Operation_type.ISBOUND_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
    } else if (optype == Operation_type.ISPRESENT_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
    } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
            expression.expression.append("}\n");
        }
    }
    nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
    expression.expression.append(closingBrackets);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) 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) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference)

Example 57 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Choice_Type method checkThisValueChoice.

private boolean checkThisValueChoice(final CompilationTimeStamp timestamp, final Choice_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean strElem) {
    boolean selfReference = false;
    final Identifier name = value.getName();
    if (!hasComponentWithName(name.getName())) {
        if (value.isAsn()) {
            value.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTCHOICE, name.getDisplayName(), getFullName()));
            value.setIsErroneous(true);
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTUNION, name.getDisplayName(), getFullName()));
            value.setIsErroneous(true);
        }
        return selfReference;
    }
    IValue alternativeValue = value.getValue();
    if (alternativeValue == null) {
        return selfReference;
    }
    final Type alternativeType = getComponentByName(name.getName()).getType();
    alternativeValue.setMyGovernor(alternativeType);
    alternativeValue = alternativeType.checkThisValueRef(timestamp, alternativeValue);
    selfReference = alternativeType.checkThisValue(timestamp, alternativeValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, false, strElem));
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) 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) IValue(org.eclipse.titan.designer.AST.IValue)

Example 58 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Sequence_Type method checkThisNamedTemplateList.

/**
 * Checks the provided named template list against this type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param templateList
 *                the template list to check
 * @param isModified
 *                is the template modified or not ?
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the template, false otherwise
 */
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List templateList, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    templateList.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
    final int nofTypeComponents = getNofComponents();
    final int nofTemplateComponents = templateList.getNofTemplates();
    boolean inSync = true;
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    CompField lastComponentField = null;
    int nextIndex = 0;
    for (int i = 0; i < nofTemplateComponents; i++) {
        final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
        final Identifier identifier = namedTemplate.getName();
        final String templateName = identifier.getName();
        if (realComponents.containsKey(templateName)) {
            if (componentMap.containsKey(templateName)) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDFIRST, identifier.getDisplayName()));
                componentMap.get(templateName).getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
            } else {
                componentMap.put(templateName, namedTemplate);
            }
            final CompField componentField = getComponentByName(identifier.getName());
            if (inSync) {
                if (isModified) {
                    boolean found = false;
                    for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                        final CompField componentField2 = getComponentByIndex(j);
                        if (templateName.equals(componentField2.getIdentifier().getName())) {
                            lastComponentField = componentField2;
                            nextIndex = j + 1;
                            found = true;
                        }
                    }
                    if (!found && lastComponentField != null) {
                        final String message = MessageFormat.format(INCORRECTTEMPLATEFIELDORDER, identifier.getDisplayName(), lastComponentField.getIdentifier().getDisplayName(), getFullName());
                        namedTemplate.getLocation().reportSemanticError(message);
                        inSync = false;
                    }
                } else if (strictConstantCheckingSeverity) {
                    final CompField componentField2 = getComponentByIndex(i);
                    if (componentField2 != componentField) {
                        if (!componentField2.isOptional() || (componentField2.isOptional() && !implicitOmit)) {
                            final String message = MessageFormat.format(UNEXPECTEDTEMPLATEFIELD, identifier.getDisplayName(), componentField2.getIdentifier().getDisplayName());
                            namedTemplate.getLocation().reportSemanticError(message);
                            inSync = false;
                        }
                    }
                }
            }
            Type type = componentField.getType();
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            type = (Type) type.getTypeRefdLast(timestamp);
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            ITTCN3Template componentTemplate = namedTemplate.getTemplate();
            componentTemplate.setMyGovernor(type);
            componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
            final boolean isOptional = componentField.isOptional();
            selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
        } else {
            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
            inSync = false;
        }
    }
    if (!isModified && strictConstantCheckingSeverity) {
        // check missing fields
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier identifier = getComponentIdentifierByIndex(i);
            if (identifier == null) {
                continue;
            }
            if (!componentMap.containsKey(identifier.getName())) {
                if (getComponentByIndex(i).isOptional() && implicitOmit) {
                    templateList.addNamedValue(new NamedTemplate(new Identifier(Identifier_type.ID_TTCN, identifier.getDisplayName()), new OmitValue_Template(), false));
                } else {
                    templateList.getLocation().reportSemanticError(MessageFormat.format(MISSINGTEMPLATEFIELD, identifier.getDisplayName(), getTypename()));
                }
            }
        }
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) HashMap(java.util.HashMap) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Example 59 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Sequence_Type method getRawLength.

@Override
public /**
 * {@inheritDoc}
 */
int getRawLength() {
    int rawLength = 0;
    for (int i = 0; i < getNofComponents(); i++) {
        final CompField cf = getComponentByIndex(i);
        if (cf.isOptional()) {
            rawLength = -1;
            return rawLength;
        }
        final int l = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp()).getRawLength();
        if (l == -1) {
            rawLength = -1;
            return rawLength;
        }
        final Type t = cf.getType();
        if (t.rawAttribute != null && (t.rawAttribute.pointerto != null || t.rawAttribute.lengthto != null)) {
            rawLength = -1;
            return rawLength;
        }
        rawLength += l;
    }
    return rawLength;
}
Also used : ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType)

Example 60 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Set_Seq_Choice_BaseType method convertRAWCodingAttributes.

// FIXME comment
protected RawASTStruct convertRAWCodingAttributes(final JavaGenData aData, final StringBuilder source, final boolean hasRaw, final List<FieldInfo> namesList) {
    RawASTStruct raw = null;
    if (hasRaw) {
        RawAST dummy_raw;
        if (rawAttribute == null) {
            dummy_raw = new RawAST(getDefaultRawFieldLength());
        } else {
            dummy_raw = rawAttribute;
        }
        raw = new RawASTStruct(dummy_raw);
        // building taglist
        final int taglistSize = dummy_raw.taglist == null ? 0 : dummy_raw.taglist.size();
        for (int c = 0; c < taglistSize; c++) {
            final rawAST_single_tag singleTag = dummy_raw.taglist.get(c);
            final rawAST_coding_taglist codingSingleTag = raw.taglist.list.get(c);
            if (singleTag.keyList != null) {
                codingSingleTag.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(singleTag.keyList.size());
            }
            codingSingleTag.fieldname = singleTag.fieldName.getName();
            codingSingleTag.varName = FieldSubReference.getJavaGetterName(codingSingleTag.fieldname);
            final Identifier idf = singleTag.fieldName;
            codingSingleTag.fieldnum = getComponentIndexByName(idf);
            final int keyListSize = singleTag.keyList == null ? 0 : singleTag.keyList.size();
            for (int a = 0; a < keyListSize; a++) {
                final rawAST_tag_field_value key = singleTag.keyList.get(a);
                final RawASTStruct.rawAST_coding_field_list codingKey = new RawASTStruct.rawAST_coding_field_list();
                codingSingleTag.fields.add(codingKey);
                codingKey.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(key.keyField.names.size());
                // codingKey.value = key.value;
                final ExpressionStruct expression = new ExpressionStruct();
                key.v_value.generateCodeExpression(aData, expression, true);
                codingKey.expression = expression;
                codingKey.isOmitValue = key.v_value.getValuetype() == Value_type.OMIT_VALUE;
                codingKey.start_pos = 0;
                final CompField cf = getComponentByIndex(codingSingleTag.fieldnum);
                IType t = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                final RawASTStruct.rawAST_coding_fields tempField = new rawAST_coding_fields();
                tempField.nthfield = codingSingleTag.fieldnum;
                tempField.nthfieldname = singleTag.fieldName.getName();
                tempField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                tempField.type = t.getGenNameValue(aData, source, myScope);
                tempField.typedesc = t.getGenNameTypeDescriptor(aData, source, myScope);
                if (cf.isOptional()) {
                    tempField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                } else {
                    tempField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                }
                codingKey.fields.add(tempField);
                for (int b = 0; b < key.keyField.names.size(); b++) {
                    final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
                    codingKey.fields.add(newField);
                    final Identifier idf2 = key.keyField.names.get(b);
                    int comp_index = 0;
                    CompField cf2;
                    switch(t.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                            comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
                            cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
                            newField.nthfield = comp_index;
                            newField.nthfieldname = idf2.getName();
                            newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                            break;
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
                            cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
                            newField.nthfield = comp_index;
                            newField.nthfieldname = idf2.getName();
                            if (cf2.isOptional()) {
                                newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                            } else {
                                newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                            }
                            break;
                        default:
                            // internal error
                            return null;
                    }
                    final IType field_type = cf2.getType();
                    newField.type = field_type.getGenNameValue(aData, source, myScope);
                    newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
                    if (field_type.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE && ((TTCN3_Sequence_Type) field_type).rawAttribute != null && (((TTCN3_Sequence_Type) field_type).rawAttribute.pointerto == null || ((TTCN3_Sequence_Type) field_type).rawAttribute.lengthto != null)) {
                        codingKey.start_pos = -1;
                    }
                    if (t.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE) {
                        IType t2;
                        for (int i = 0; i < comp_index && codingKey.start_pos >= 0; i++) {
                            t2 = ((TTCN3_Sequence_Type) t).getComponentByIndex(i).getType();
                            if (t2.getRawLength() >= 0) {
                                if (((Type) t2).rawAttribute != null) {
                                    codingKey.start_pos += ((Type) t2).rawAttribute.padding;
                                }
                                codingKey.start_pos += ((Type) t2).getRawLength();
                            } else {
                                codingKey.start_pos = -1;
                            }
                        }
                    }
                    t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                }
            }
        }
        // building presence list
        final int presenceListSize = dummy_raw.presence == null || dummy_raw.presence.keyList == null ? 0 : dummy_raw.presence.keyList.size();
        for (int a = 0; a < presenceListSize; a++) {
            final rawAST_tag_field_value fieldValue = dummy_raw.presence.keyList.get(a);
            final rawAST_coding_field_list presences = new rawAST_coding_field_list();
            raw.presence.fields.add(presences);
            final ExpressionStruct expression = new ExpressionStruct();
            fieldValue.v_value.generateCodeExpression(aData, expression, true);
            presences.expression = expression;
            presences.isOmitValue = fieldValue.v_value.getValuetype() == Value_type.OMIT_VALUE;
            final int keySize = fieldValue.keyField == null || fieldValue.keyField.names == null ? 0 : fieldValue.keyField.names.size();
            presences.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(keySize);
            IType t = this;
            for (int b = 0; b < keySize; b++) {
                final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
                presences.fields.add(newField);
                final Identifier idf2 = fieldValue.keyField.names.get(b);
                int comp_index = 0;
                CompField cf2;
                switch(t.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                        comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
                        cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
                        newField.nthfield = comp_index;
                        newField.nthfieldname = idf2.getName();
                        newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                        break;
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
                        cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
                        newField.nthfield = comp_index;
                        newField.nthfieldname = idf2.getName();
                        if (cf2.isOptional()) {
                            newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                        } else {
                            newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                        }
                        break;
                    default:
                        // internal error
                        return null;
                }
                final IType field_type = cf2.getType();
                newField.type = field_type.getGenNameValue(aData, source, myScope);
                newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
                t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            }
        }
        final int extBiGroupSize = dummy_raw.ext_bit_groups == null ? 0 : dummy_raw.ext_bit_groups.size();
        for (int c = 0; c < extBiGroupSize; c++) {
            final rawAST_ext_bit_group tempGroup = dummy_raw.ext_bit_groups.get(c);
            final Identifier idf = tempGroup.from;
            final Identifier idf2 = tempGroup.to;
            final rawAST_coding_ext_group codingGroup = new rawAST_coding_ext_group();
            raw.ext_bit_groups.add(codingGroup);
            codingGroup.ext_bit = tempGroup.ext_bit;
            codingGroup.from = getComponentIndexByName(idf);
            codingGroup.to = getComponentIndexByName(idf2);
        }
        for (int i = 0; i < getNofComponents(); i++) {
            final FieldInfo element_i = namesList.get(i);
            final CompField cf = getComponentByIndex(i);
            final IType t_field = cf.getType();
            final IType t_field_last = t_field.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final RawAST rawpar = t_field.getRawAttribute();
            if (rawpar != null) {
                element_i.raw = new RawASTStruct(rawpar);
                final int lengthtoNum = rawpar.lengthto == null ? 0 : rawpar.lengthto.size();
                for (int j = 0; j < lengthtoNum; j++) {
                    final Identifier idf = rawpar.lengthto.get(j);
                    element_i.raw.lengthto.add(getComponentIndexByName(idf));
                }
                if (lengthtoNum > 0 && rawpar.lengthindex != null) {
                    final Identifier idf = rawpar.lengthindex.names.get(0);
                    int comp_index = 0;
                    CompField cf2;
                    switch(t_field_last.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                            comp_index = ((TTCN3_Choice_Type) t_field_last).getComponentIndexByName(idf);
                            cf2 = ((TTCN3_Choice_Type) t_field_last).getComponentByIndex(comp_index);
                            element_i.raw.lengthindex.nthfield = comp_index;
                            element_i.raw.lengthindex.nthfieldname = idf.getName();
                            break;
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t_field_last).getComponentIndexByName(idf);
                            cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t_field_last).getComponentByIndex(comp_index);
                            element_i.raw.lengthindex.nthfield = comp_index;
                            element_i.raw.lengthindex.nthfieldname = idf.getName();
                            break;
                        default:
                            // internal error
                            return null;
                    }
                    final Type t_field2 = cf2.getType();
                    if (t_field2.getTypetype() == Type_type.TYPE_TTCN3_CHOICE) {
                        element_i.raw.lengthindex.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                    } else if (cf2.isOptional()) {
                        element_i.raw.lengthindex.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                    } else {
                        element_i.raw.lengthindex.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                    }
                    element_i.raw.lengthindex.type = t_field2.getGenNameValue(aData, source, myScope);
                    element_i.raw.lengthindex.typedesc = t_field2.getGenNameTypeDescriptor(aData, source, myScope);
                }
                if (lengthtoNum > 0 && rawpar.lengthindex == null) {
                    switch(t_field_last.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            final int componentsNumber = ((TTCN3_Set_Seq_Choice_BaseType) t_field_last).getNofComponents();
                            element_i.raw.union_member_num = componentsNumber;
                            element_i.raw.member_name = new ArrayList<String>(componentsNumber + 1);
                            element_i.raw.member_name.add(t_field_last.getGenNameValue(aData, source, myScope));
                            for (int m = 1; m < componentsNumber + 1; m++) {
                                final CompField compf = ((TTCN3_Set_Seq_Choice_BaseType) t_field_last).getComponentByIndex(m - 1);
                                element_i.raw.member_name.add(compf.getIdentifier().getName());
                            }
                            break;
                        default:
                            break;
                    }
                }
                if (rawpar.pointerto != null) {
                    final Identifier idf = rawpar.pointerto;
                    element_i.raw.pointerto = getComponentIndexByName(idf);
                    if (rawpar.ptrbase != null) {
                        final Identifier idf2 = rawpar.ptrbase;
                        element_i.raw.pointerbase = getComponentIndexByName(idf2);
                    } else {
                        element_i.raw.pointerbase = i;
                    }
                }
                // building presence list
                final int parPresenceListSize = rawpar.presence == null || rawpar.presence.keyList == null ? 0 : rawpar.presence.keyList.size();
                for (int a = 0; a < parPresenceListSize; a++) {
                    final rawAST_coding_field_list presences = new rawAST_coding_field_list();
                    element_i.raw.presence.fields.add(presences);
                    final rawAST_tag_field_value fieldValue = rawpar.presence.keyList.get(a);
                    final ExpressionStruct expression = new ExpressionStruct();
                    fieldValue.v_value.generateCodeExpression(aData, expression, true);
                    presences.expression = expression;
                    presences.isOmitValue = fieldValue.v_value.getValuetype() == Value_type.OMIT_VALUE;
                    presences.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(fieldValue.keyField.names.size());
                    IType t = this;
                    for (int b = 0; b < fieldValue.keyField.names.size(); b++) {
                        final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
                        presences.fields.add(newField);
                        final Identifier idf2 = fieldValue.keyField.names.get(b);
                        int comp_index = 0;
                        CompField cf2;
                        switch(t.getTypetype()) {
                            case TYPE_TTCN3_CHOICE:
                                comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
                                cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
                                newField.nthfield = comp_index;
                                newField.nthfieldname = idf2.getName();
                                newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                                break;
                            case TYPE_TTCN3_SEQUENCE:
                            case TYPE_TTCN3_SET:
                                comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
                                cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
                                newField.nthfield = comp_index;
                                newField.nthfieldname = idf2.getName();
                                if (cf2.isOptional()) {
                                    newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                                } else {
                                    newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                                }
                                break;
                            default:
                                // internal error
                                return null;
                        }
                        final IType field_type = cf2.getType();
                        newField.type = field_type.getGenNameValue(aData, source, myScope);
                        newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
                        t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                    }
                }
                // building crosstaglist
                final int crossTaglistSize = rawpar.crosstaglist == null ? 0 : rawpar.crosstaglist.size();
                for (int c = 0; c < crossTaglistSize; c++) {
                    final rawAST_single_tag singleTag = rawpar.crosstaglist.get(c);
                    final rawAST_coding_taglist codingSingleTag = element_i.raw.crosstaglist.list.get(c);
                    if (singleTag.keyList != null) {
                        codingSingleTag.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(singleTag.keyList.size());
                    }
                    codingSingleTag.fieldname = singleTag.fieldName.getName();
                    codingSingleTag.varName = FieldSubReference.getJavaGetterName(codingSingleTag.fieldname);
                    final Identifier idf = singleTag.fieldName;
                    switch(t_field_last.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            codingSingleTag.fieldnum = ((TTCN3_Set_Seq_Choice_BaseType) t_field_last).getComponentIndexByName(idf);
                            break;
                        case TYPE_ASN1_CHOICE:
                            codingSingleTag.fieldnum = ((ASN1_Set_Seq_Choice_BaseType) t_field_last).getComponentIndexByName(idf);
                            break;
                        default:
                            codingSingleTag.fieldnum = -1;
                            break;
                    }
                    final int keyListSize = singleTag.keyList == null ? 0 : singleTag.keyList.size();
                    for (int a = 0; a < keyListSize; a++) {
                        final rawAST_tag_field_value key = singleTag.keyList.get(a);
                        final RawASTStruct.rawAST_coding_field_list codingKey = new RawASTStruct.rawAST_coding_field_list();
                        codingSingleTag.fields.add(codingKey);
                        codingKey.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(key.keyField.names.size());
                        final ExpressionStruct expression = new ExpressionStruct();
                        key.v_value.generateCodeExpression(aData, expression, true);
                        codingKey.expression = expression;
                        codingKey.isOmitValue = key.v_value.getValuetype() == Value_type.OMIT_VALUE;
                        IType t = this;
                        for (int b = 0; b < key.keyField.names.size(); b++) {
                            final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
                            codingKey.fields.add(newField);
                            final Identifier idf2 = key.keyField.names.get(b);
                            int comp_index = 0;
                            CompField cf2;
                            switch(t.getTypetype()) {
                                case TYPE_TTCN3_CHOICE:
                                    comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
                                    cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
                                    newField.nthfield = comp_index;
                                    newField.nthfieldname = idf2.getName();
                                    newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                                    break;
                                case TYPE_TTCN3_SEQUENCE:
                                case TYPE_TTCN3_SET:
                                    comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
                                    cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
                                    newField.nthfield = comp_index;
                                    newField.nthfieldname = idf2.getName();
                                    if (cf2.isOptional()) {
                                        newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                                    } else {
                                        newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                                    }
                                    break;
                                default:
                                    // internal error
                                    return null;
                            }
                            final IType field_type = cf2.getType();
                            newField.type = field_type.getGenNameValue(aData, source, myScope);
                            newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
                            t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                        }
                    }
                }
                element_i.raw.length = t_field.getRawLength();
                element_i.hasRaw = true;
            } else {
                element_i.hasRaw = false;
            }
        }
    }
    return raw;
}
Also used : RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST) RawASTStruct.rawAST_coding_taglist(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist) RawAST.rawAST_ext_bit_group(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_ext_bit_group) RawASTStruct.rawAST_coding_ext_group(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_ext_group) RawASTStruct.rawAST_coding_fields(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields) IType(org.eclipse.titan.designer.AST.IType) RawASTStruct.rawAST_coding_field_list(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_list) ASN1_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType) 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) RawASTStruct.rawAST_coding_field_list(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_list) Identifier(org.eclipse.titan.designer.AST.Identifier) RawASTStruct(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct) RawASTStruct.rawAST_coding_fields(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) RawAST.rawAST_tag_field_value(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_tag_field_value) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.RecordSetCodeGenerator.FieldInfo)

Aggregations

Type (org.eclipse.titan.designer.AST.Type)69 IType (org.eclipse.titan.designer.AST.IType)56 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IValue (org.eclipse.titan.designer.AST.IValue)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)12 HashMap (java.util.HashMap)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)9 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 Reference (org.eclipse.titan.designer.AST.Reference)8 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)8 Attribute_Type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type)7 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)6 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)6 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6