Search in sources :

Example 21 with SubType

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

the class SubType method check.

/**
 * Does the semantic checking of the sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 */
public void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (parsedRestrictions != null) {
        int addedCount = 0;
        boolean hasSingle = false, hasRange = false;
        for (int i = 0, size = parsedRestrictions.size(); i < size; i++) {
            boolean added = false;
            final ParsedSubType parsed = parsedRestrictions.get(i);
            switch(parsed.getSubTypetype()) {
                case SINGLE_PARSEDSUBTYPE:
                    hasSingle = true;
                    added = addTtcnSingle(timestamp, ((Single_ParsedSubType) parsed).getValue(), i);
                    break;
                case RANGE_PARSEDSUBTYPE:
                    hasRange = true;
                    final Range_ParsedSubType rpst = (Range_ParsedSubType) parsed;
                    added = addTtcnRange(timestamp, rpst.getMin(), rpst.getMinExclusive(), rpst.getMax(), rpst.getMaxExclusive(), i);
                    break;
                case LENGTH_PARSEDSUBTYPE:
                    added = addTtcnLength(timestamp, ((Length_ParsedSubType) parsed).getLength(), i);
                    break;
                case PATTERN_PARSEDSUBTYPE:
                    added = addTtcnPattern(timestamp, ((Pattern_ParsedSubType) parsed).getPattern(), i);
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR();
            }
            if (added) {
                addedCount++;
            }
        }
        switch(subtypeType) {
            case ST_CHARSTRING:
            case ST_UNIVERSAL_CHARSTRING:
                if (hasSingle && hasRange) {
                    myOwner.getLocation().reportSemanticError(MessageFormat.format("Mixing of value list and range subtyping is not allowed for type `{0}''", myOwner.getTypename()));
                    isErroneous = true;
                    return;
                }
                break;
            default:
                // TTCN-3 BNF itself
                break;
        }
        if (addedCount < parsedRestrictions.size()) {
            isErroneous = true;
            return;
        }
        if (getIsErroneous(timestamp)) {
            return;
        }
    }
    // create the intersection of the two sub-types
    if ((parentSubtype != null) && !parentSubtype.getIsErroneous(timestamp)) {
        // check for circular sub-type reference
        if (!addParentSubtype(parentSubtype)) {
            isErroneous = true;
            return;
        }
        if (parentSubtype.subtypeType != subtypeType) {
            ErrorReporter.INTERNAL_ERROR();
            return;
        }
        if (parentSubtype.subtypeConstraint != null) {
            if (subtypeConstraint == null) {
                subtypeConstraint = parentSubtype.subtypeConstraint;
            } else {
                // both own and inherited sub-type constraints exist
                if (subtypeConstraint.isSubset(parentSubtype.subtypeConstraint) == TernaryBool.TFALSE) {
                    final String message = MessageFormat.format("The subtype restriction is not a subset of the restriction on the parent type. Subtype {0} is not subset of subtype {1}", subtypeConstraint.toString(), parentSubtype.subtypeConstraint.toString());
                    getParsedLocation().reportSemanticError(message);
                    isErroneous = true;
                    return;
                }
                subtypeConstraint = subtypeConstraint.intersection(parentSubtype.subtypeConstraint);
            }
        }
        if (parentSubtype.lengthRestriction != null) {
            if (lengthRestriction == null) {
                lengthRestriction = parentSubtype.lengthRestriction;
            } else {
                lengthRestriction = lengthRestriction.intersection(parentSubtype.lengthRestriction);
            }
        }
    }
    // set is empty or full
    if (subtypeConstraint != null) {
        if (subtypeConstraint.isEmpty() == TernaryBool.TTRUE) {
            getParsedLocation().reportSemanticError("The subtype is an empty set");
            isErroneous = true;
            return;
        }
        if (subtypeConstraint.isFull() == TernaryBool.TTRUE) {
            getParsedLocation().reportSemanticWarning(MessageFormat.format("The subtype of type `{0}'' is a full set, it does not constrain the root type.", myOwner.getTypename()));
            subtypeConstraint = null;
        }
    }
    if ((lengthRestriction != null) && (lengthRestriction.isFull() == TernaryBool.TTRUE)) {
        lengthRestriction = null;
    }
}
Also used : PatternString(org.eclipse.titan.designer.AST.TTCN3.templates.PatternString)

Example 22 with SubType

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

the class SubType method checkThisValue.

/**
 * Checks if a given value is valid according to this sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 */
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
    if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
        return;
    }
    if (value.getIsErroneous(timestamp)) {
        return;
    }
    final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    boolean isValid = true;
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            if (subtypeType != SubType_type.ST_INTEGER) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case REAL_VALUE:
            if (subtypeType == SubType_type.ST_FLOAT) {
                isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
                break;
            } else if (subtypeType == SubType_type.ST_INTEGER) {
                final Real_Value real = (Real_Value) last;
                if (real.isNegativeInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
                    break;
                } else if (real.isPositiveInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
                    break;
                }
            }
            ErrorReporter.INTERNAL_ERROR();
            return;
        case BOOLEAN_VALUE:
            if (subtypeType != SubType_type.ST_BOOLEAN) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
            break;
        case VERDICT_VALUE:
            if (subtypeType != SubType_type.ST_VERDICTTYPE) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
            break;
        case BITSTRING_VALUE:
            if (subtypeType != SubType_type.ST_BITSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
            break;
        case HEXSTRING_VALUE:
            if (subtypeType != SubType_type.ST_HEXSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
            break;
        case OCTETSTRING_VALUE:
            if (subtypeType != SubType_type.ST_OCTETSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
            break;
        case CHARSTRING_VALUE:
            switch(subtypeType) {
                case ST_CHARSTRING:
                    isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
                    break;
                case ST_UNIVERSAL_CHARSTRING:
                    isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR();
                    return;
            }
            break;
        case UNIVERSALCHARSTRING_VALUE:
            if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
            break;
        case SEQUENCEOF_VALUE:
        case SETOF_VALUE:
        case OBJECTID_VALUE:
        case ENUMERATED_VALUE:
        case CHOICE_VALUE:
        case SEQUENCE_VALUE:
        case SET_VALUE:
        case FUNCTION_REFERENCE_VALUE:
        case ALTSTEP_REFERENCE_VALUE:
        case TESTCASE_REFERENCE_VALUE:
            if (value.isUnfoldable(timestamp)) {
                return;
            }
            isValid = subtypeConstraint.isElement(last);
            break;
        default:
            return;
    }
    if (!isValid) {
        value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
    }
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 23 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 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, true, hasRaw, raw);
    RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, true);
    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 24 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 generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    aData.addBuiltinTypeImport("TitanFloat");
    final String genName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final FunctionReferenceDefinition def = new FunctionReferenceDefinition(genName, displayName);
    def.returnType = null;
    def.type = fatType.TESTCASE;
    def.runsOnSelf = false;
    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());
    if (formalParList.getNofParameters() > 0) {
        def.formalParList = def.formalParList + ", ";
        def.actualParList = def.actualParList + ", ";
    }
    def.formalParList = def.formalParList + "boolean has_timer, TitanFloat timer_value";
    def.actualParList = def.actualParList + "has_timer, timer_value";
    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 25 with SubType

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

the class Type method checkSubtypeRestrictions.

/**
 * create and check subtype, called by the check function of the type
 */
protected void checkSubtypeRestrictions(final CompilationTimeStamp timestamp, final SubType.SubType_type subtypeType, final SubType parentSubtype) {
    if (getIsErroneous(timestamp)) {
        return;
    }
    // do
    if ((parsedRestrictions == null) && (parentSubtype == null)) {
        return;
    }
    // if the type has no subtype type
    if (subtypeType == SubType.SubType_type.ST_NONE) {
        getLocation().reportSemanticError(MessageFormat.format("TTCN-3 subtype constraints are not applicable to type `{0}''", getTypename()));
        setIsErroneous(true);
        return;
    }
    subType = new SubType(subtypeType, this, parsedRestrictions, parentSubtype);
    subType.check(timestamp);
}
Also used : ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)

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