Search in sources :

Example 11 with ArrayDimension

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.

the class Port_Type method generateCodePort.

/**
 * Generate the classes to represent a port array.
 *
 * @param aData only used to update imports if needed
 * @param source where the source code should be generated
 * @param dimensions the dimensions of the array to use.
 */
public void generateCodePort(final JavaGenData aData, final StringBuilder source, final ArrayDimensions dimensions) {
    String className = getGenNameValue(aData, source, myScope);
    String elementName;
    for (int i = 0; i < dimensions.size(); i++) {
        final ArrayDimension dimension = dimensions.get(i);
        if (i == dimensions.size() - 1) {
            elementName = getGenNameOwn();
        } else {
            elementName = aData.getTemporaryVariableName();
        }
        source.append(MessageFormat.format("public static class {0} extends TitanPortArray<{1}> '{'\n", className, elementName));
        source.append(MessageFormat.format("public {0}() '{'\n", className));
        source.append(MessageFormat.format("super({0}.class, {1} , {2});\n", elementName, dimension.getSize(), dimension.getOffset()));
        source.append("}\n");
        source.append(MessageFormat.format("public {0}({0} otherValue) '{'\n", className));
        source.append("super(otherValue);\n");
        source.append("}\n");
        source.append("}\n\n");
        className = elementName;
    }
    aData.addBuiltinTypeImport("TitanPortArray");
}
Also used : ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 12 with ArrayDimension

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension 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);
}
Also used : ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ArrayList(java.util.ArrayList) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 13 with ArrayDimension

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.

the class Array_Type method generateCodeTemplate.

/**
 * Generate the template class to represent an array.
 * (Also generates the template classes of the of type if it is an array)
 *
 * @param aData only used to update imports if needed
 * @param source where the source code should be generated
 */
public void generateCodeTemplate(final JavaGenData aData, final StringBuilder source) {
    final String className = getGenNameValue(aData, source, myScope);
    final String classTemplateName = getGenNameTemplate(aData, source, myScope);
    final IType elementType = getElementType();
    final String ofValueType = elementType.getGenNameValue(aData, source, getMyScope());
    final String ofTemplateType = elementType.getGenNameTemplate(aData, source, getMyScope());
    if (elementType.getTypetype() == Type_type.TYPE_ARRAY) {
        ((Array_Type) elementType).generateCodeTemplate(aData, source);
    }
    final ArrayDimension dim = getDimension();
    aData.addBuiltinTypeImport("TitanTemplateArray");
    source.append(MessageFormat.format("public static class {0} extends TitanTemplateArray<{1}, {2}> '{'\n", classTemplateName, ofValueType, ofTemplateType));
    source.append(MessageFormat.format("public {0}() '{'\n", classTemplateName));
    source.append(MessageFormat.format("super({0}.class, {1}.class, {2}, {3});\n", ofValueType, ofTemplateType, dim.getSize(), dim.getOffset()));
    source.append("}\n");
    source.append(MessageFormat.format("public {0} valueOf() '{'\n", className));
    source.append(MessageFormat.format("return ({0})super.valueOf();\n", className));
    source.append("}\n");
    source.append("}\n");
}
Also used : ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

ArrayDimension (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)10 IValue (org.eclipse.titan.designer.AST.IValue)8 IType (org.eclipse.titan.designer.AST.IType)6 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 BigInteger (java.math.BigInteger)3 Value (org.eclipse.titan.designer.AST.Value)3 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 SingleLenghtRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)1 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)1 Length_ParsedSubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType)1 ParsedSubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType)1 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)1 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)1