Search in sources :

Example 31 with SubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType 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 32 with SubType

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

the class Altstep_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Altstep altstep = null;
    switch(last.getValuetype()) {
        case ALTSTEP_REFERENCE_VALUE:
            altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
            if (altstep == null) {
                setIsErroneous(true);
                return selfReference;
            }
            altstep.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(ALTSTEPREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
    final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnSelf) {
            // check against the runs on component type of the scope of the value
            final Scope valueScope = value.getMyScope();
            if (valueScope == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
            if (runsOnScope != null) {
                final Component_Type componentType = runsOnScope.getComponentType();
                if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope " + "expects component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            } else {
                // compatibility using this component type as the scope
                if (valueScope instanceof ComponentTypeBody) {
                    final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                    if (!runsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' " + "clause and the current component definition is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' clause and the current scope does not have a `runs on'' clause," + " but {1} runs on `{2}''", getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            }
        } else {
            if (runsOnRef == null) {
                value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                value.setIsErroneous(true);
            } else {
                if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                }
            }
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 33 with SubType

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

the class Altstep_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 FunctionReferenceDefinition def = new FunctionReferenceDefinition(genName, displayName);
    def.returnType = null;
    def.type = fatType.ALTSTEP;
    def.runsOnSelf = runsOnSelf;
    def.isStartable = false;
    def.formalParList = formalParList.generateCode(aData).toString();
    def.actualParList = formalParList.generateCodeActualParlist("").toString();
    def.parameterTypeNames = new ArrayList<String>(formalParList.getNofParameters());
    def.parameterNames = new ArrayList<String>(formalParList.getNofParameters());
    for (int i = 0; i < formalParList.getNofParameters(); i++) {
        final FormalParameter formalParameter = formalParList.getParameterByIndex(i);
        switch(formalParameter.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_INOUT:
            case A_PAR_VAL_OUT:
                def.parameterTypeNames.add(formalParameter.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, getMyScope()));
                break;
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_INOUT:
            case A_PAR_TEMP_OUT:
                def.parameterTypeNames.add(formalParameter.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, getMyScope()));
                break;
            default:
                break;
        }
        def.parameterNames.add(formalParameter.getIdentifier().getName());
    }
    FunctionReferenceGenerator.generateValueClass(aData, source, def);
    FunctionReferenceGenerator.generateTemplateClass(aData, source, def);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) FunctionReferenceDefinition(org.eclipse.titan.designer.AST.TTCN3.types.FunctionReferenceGenerator.FunctionReferenceDefinition)

Example 34 with SubType

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

the class TTCN3_Set_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 = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (((SequenceOf_Value) last).isIndexed()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for set type `{0}''", getFullName()));
                value.setIsErroneous(true);
            } else {
                final SequenceOf_Value tempValue = (SequenceOf_Value) last;
                if (tempValue.getNofComponents() == 0) {
                    if (compFieldMap != null && compFieldMap.getComponentFieldMap(timestamp).isEmpty()) {
                        last = last.setValuetype(timestamp, Value_type.SET_VALUE);
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format(NONEMPTYEXPECTED, getFullName()));
                        value.setIsErroneous(true);
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? VALUELISTNOTATIONERRORASN1 : VALUELISTNOTATIONERRORTTCN3, getFullName()));
                    value.setIsErroneous(true);
                }
            }
            break;
        case SET_VALUE:
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case UNDEFINED_BLOCK:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? SETVALUEXPECTEDASN1 : SETVALUEXPECTEDTTCN3, getFullName()));
            value.setIsErroneous(true);
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Set_Value(org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)

Example 35 with SubType

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

the class Testcase_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Testcase testcase = null;
    switch(last.getValuetype()) {
        case TESTCASE_REFERENCE_VALUE:
            testcase = ((Testcase_Reference_Value) last).getReferredTestcase();
            if (testcase == null) {
                setIsErroneous(true);
                return selfReference;
            }
            testcase.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(TESTCASEREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    final Component_Type temporalRunsOnType = testcase.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), testcase.getAssignmentName(), temporalRunsOnType.getTypename()));
            value.setIsErroneous(true);
        }
    }
    formalParList.checkCompatibility(timestamp, testcase.getFormalParameterList(), value.getLocation());
    Component_Type temporalSystemType = testcase.getSystemType(timestamp);
    if (temporalSystemType == null) {
        temporalSystemType = temporalRunsOnType;
    }
    if (systemRef == null) {
        if (temporalSystemType != null && runsOnType != null && !temporalSystemType.isCompatible(timestamp, runsOnType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCLAUSEMISMATCHERROR, getTypename(), runsOnType.getTypename(), testcase.getAssignmentName(), temporalSystemType.getTypename()));
            value.setIsErroneous(true);
        }
    } else {
        if (temporalSystemType != null && systemType != null && !temporalSystemType.isCompatible(timestamp, systemType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCLAUSEMISMATCHERROR, getTypename(), systemType.getTypename(), testcase.getAssignmentName(), temporalSystemType.getTypename()));
            value.setIsErroneous(true);
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)

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