Search in sources :

Example 26 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Choice_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final List<FieldInfo> fieldInfos = new ArrayList<FieldInfo>();
    boolean hasOptional = false;
    for (final CompField compField : compFieldMap.fields) {
        final IType cfType = compField.getType();
        final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
        hasOptional |= compField.isOptional();
        fieldInfos.add(fi);
    }
    for (final CompField compField : compFieldMap.fields) {
        final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
        compField.getType().generateCode(aData, tempSource);
    }
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    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);
                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;
                    }
                    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());
                }
            }
        }
    }
    UnionGenerator.generateValueClass(aData, source, genName, displayName, fieldInfos, hasOptional, hasRaw, raw);
    UnionGenerator.generateTemplateClass(aData, source, genName, displayName, fieldInfos, hasOptional);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
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) ArrayList(java.util.ArrayList) RawASTStruct.rawAST_coding_fields(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields) IType(org.eclipse.titan.designer.AST.IType) 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) 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) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.UnionGenerator.FieldInfo) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag)

Example 27 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Enumerated_Type method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 */
@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String ownName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    final ArrayList<Enum_field> fields = new ArrayList<EnumeratedGenerator.Enum_field>(items.getItems().size());
    for (int i = 0; i < items.getItems().size(); i++) {
        final EnumItem tempItem = items.getItems().get(i);
        fields.add(new Enum_field(tempItem.getId().getName(), tempItem.getId().getDisplayName(), ((Integer_Value) tempItem.getValue()).getValue()));
    }
    final Enum_Defs e_defs = new Enum_Defs(fields, ownName, displayName, getGenNameTemplate(aData, source, myScope), hasRaw);
    EnumeratedGenerator.generateValueClass(aData, source, e_defs);
    EnumeratedGenerator.generateTemplateClass(aData, source, e_defs);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : Enum_field(org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_field) ArrayList(java.util.ArrayList) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Enum_Defs(org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_Defs)

Example 28 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Sequence_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String className = getGenNameOwn();
    final String classReadableName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final List<FieldInfo> namesList = new ArrayList<FieldInfo>();
    boolean hasOptional = false;
    for (final CompField compField : compFieldMap.fields) {
        final IType cfType = compField.getType();
        final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), false, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
        hasOptional |= compField.isOptional();
        namesList.add(fi);
    }
    for (final CompField compField : compFieldMap.fields) {
        final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
        compField.getType().generateCode(aData, tempSource);
    }
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    final RawASTStruct raw = convertRAWCodingAttributes(aData, source, hasRaw, namesList);
    RecordSetCodeGenerator.generateValueClass(aData, source, className, classReadableName, namesList, hasOptional, false, hasRaw, raw);
    RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, false);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : RawASTStruct(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct) ArrayList(java.util.ArrayList) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.RecordSetCodeGenerator.FieldInfo) IType(org.eclipse.titan.designer.AST.IType)

Example 29 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Type method checkCodingAttributes.

@Override
public /**
 * {@inheritDoc}
 */
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (refdLast == null || refdLast.getIsErroneous(CompilationTimeStamp.getBaseTimestamp()) || refdLast == this) {
        return;
    }
    // check raw attributes
    if (subType != null) {
        final int restrictionLength = subType.get_length_restriction();
        if (restrictionLength != -1) {
            if (rawAttribute == null) {
                rawAttribute = new RawAST(getDefaultRawFieldLength());
            }
            if (rawAttribute.fieldlength == 0) {
                rawAttribute.fieldlength = restrictionLength;
                rawAttribute.length_restriction = -1;
            } else {
                rawAttribute.length_restriction = restrictionLength;
            }
        }
    }
    if (rawAttribute == null) {
        return;
    }
    refd.forceRaw(timestamp);
    if (rawAttribute.fieldlength == 0 && rawAttribute.length_restriction != -1) {
        switch(refdLast.getTypetype()) {
            case TYPE_BITSTRING:
                rawAttribute.fieldlength = rawAttribute.length_restriction;
                rawAttribute.length_restriction = -1;
                break;
            case TYPE_HEXSTRING:
                rawAttribute.fieldlength = rawAttribute.length_restriction * 4;
                rawAttribute.length_restriction = -1;
                break;
            case TYPE_OCTETSTRING:
                rawAttribute.fieldlength = rawAttribute.length_restriction * 8;
                rawAttribute.length_restriction = -1;
                break;
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                rawAttribute.fieldlength = rawAttribute.length_restriction * 8;
                rawAttribute.length_restriction = -1;
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_SET_OF:
                rawAttribute.fieldlength = rawAttribute.length_restriction;
                rawAttribute.length_restriction = -1;
                break;
            default:
                break;
        }
    }
    if (refChain.contains(this)) {
        return;
    }
    refdLast.checkCodingAttributes(timestamp, refChain);
}
Also used : RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST)

Example 30 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    final IType tempType = getTypeRefdLast(timestamp);
    if (tempType != this) {
        selfReference = tempType.checkThisValue(timestamp, value, lhs, new ValueCheckingOptions(valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.omit_allowed, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem));
        final Definition def = value.getDefiningAssignment();
        if (def != null) {
            final String referingModuleName = getMyScope().getModuleScope().getName();
            if (!def.referingHere.contains(referingModuleName)) {
                def.referingHere.add(referingModuleName);
            }
        }
    }
    if (valueCheckingOptions.sub_check && (subType != null)) {
        subType.checkThisValue(timestamp, value);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)14 IType (org.eclipse.titan.designer.AST.IType)11 RawAST (org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST)9 ArrayList (java.util.ArrayList)7 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)4 RawASTStruct (org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct)3 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)3 PatternString (org.eclipse.titan.designer.AST.TTCN3.templates.PatternString)3 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)3 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)3 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)3 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 Assignment (org.eclipse.titan.designer.AST.Assignment)2 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Scope (org.eclipse.titan.designer.AST.Scope)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2