Search in sources :

Example 1 with AbstractOfType

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

the class Type method fieldIsOptional.

@Override
public /**
 * {@inheritDoc}
 */
boolean fieldIsOptional(final List<ISubReference> subReferences) {
    // TODO there must be a better implementation
    if (subReferences == null) {
        return false;
    }
    if (subReferences.isEmpty()) {
        return false;
    }
    final ISubReference lastSubReference = subReferences.get(subReferences.size() - 1);
    if (!(lastSubReference instanceof FieldSubReference)) {
        return false;
    }
    IType type = this;
    CompField compField = null;
    for (int i = 1; i < subReferences.size(); i++) {
        if (type != null) {
            type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        }
        final ISubReference subreference = subReferences.get(i);
        if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
            final Identifier id = ((FieldSubReference) subreference).getId();
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
                        break;
                    case TYPE_ANYTYPE:
                        compField = ((Anytype_Type) type).getComponentByName(id.getName());
                        break;
                    case TYPE_OPENTYPE:
                        compField = ((Open_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SEQUENCE:
                        ((ASN1_Sequence_Type) type).parseBlockSequence();
                        compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SET:
                        ((ASN1_Set_Type) type).parseBlockSet();
                        compField = ((ASN1_Set_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_CHOICE:
                        ((ASN1_Choice_Type) type).parseBlockChoice();
                        compField = ((ASN1_Choice_Type) type).getComponentByName(id);
                        break;
                    default:
                        // TODO fatal error:
                        return false;
                }
                if (compField == null) {
                    // TODO fatal error
                    return false;
                }
                type = compField.getType();
            }
        } else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
            final Value value = ((ArraySubReference) subreference).getValue();
            // TODO actually should get the last governor
            final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_SEQUENCE_OF:
                    case TYPE_SET_OF:
                        type = ((AbstractOfType) type).getOfType();
                        break;
                    case TYPE_ARRAY:
                        type = ((Array_Type) type).getElementType();
                        break;
                    default:
                        type = null;
                        return false;
                }
            }
        }
    }
    if (compField != null && compField.isOptional()) {
        return true;
    }
    return false;
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) AbstractOfType(org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 2 with AbstractOfType

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

the class Reference method generateCode.

// originally fieldOrArrayRefs
private void generateCode(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final boolean isConst, IType type) {
    for (int i = 1; i < subReferences.size(); i++) {
        if (type != null) {
            type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        }
        final ISubReference subreference = subReferences.get(i);
        if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
            final Identifier id = ((FieldSubReference) subreference).getId();
            expression.expression.append(".");
            if (isConst) {
                expression.expression.append("constGet");
            } else {
                expression.expression.append("get");
            }
            expression.expression.append(FieldSubReference.getJavaGetterName(id.getName()));
            expression.expression.append("()");
            if (type != null) {
                CompField compField = null;
                switch(type.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
                        break;
                    case TYPE_ANYTYPE:
                        compField = ((Anytype_Type) type).getComponentByName(id.getName());
                        break;
                    case TYPE_OPENTYPE:
                        compField = ((Open_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SEQUENCE:
                        ((ASN1_Sequence_Type) type).parseBlockSequence();
                        compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SET:
                        ((ASN1_Set_Type) type).parseBlockSet();
                        compField = ((ASN1_Set_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_CHOICE:
                        ((ASN1_Choice_Type) type).parseBlockChoice();
                        compField = ((ASN1_Choice_Type) type).getComponentByName(id);
                        break;
                    default:
                        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
                        return;
                }
                if (i < subReferences.size() - 1 && compField != null && compField.isOptional() && !isTemplate) {
                    if (isConst) {
                        expression.expression.append(".constGet()");
                    } else {
                        expression.expression.append(".get()");
                    }
                    type = compField.getType();
                }
            }
        } else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
            final Value value = ((ArraySubReference) subreference).getValue();
            // TODO actually should get the last governor
            final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            // generate "getAt" functions instead of operator[]
            if (isConst) {
                expression.expression.append(".constGetAt(");
            } else {
                expression.expression.append(".getAt(");
            }
            value.generateCodeExpression(aData, expression, false);
            expression.expression.append(")");
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_SEQUENCE_OF:
                    case TYPE_SET_OF:
                        type = ((AbstractOfType) type).getOfType();
                        break;
                    case TYPE_ARRAY:
                        type = ((Array_Type) type).getElementType();
                        break;
                    default:
                        type = null;
                }
            }
        }
    }
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) AbstractOfType(org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Aggregations

ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)2 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)2 AbstractOfType (org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType)2 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)1 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)1 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)1