Search in sources :

Example 1 with Range_ParsedSubType

use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType 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)

Aggregations

PatternString (org.eclipse.titan.designer.AST.TTCN3.templates.PatternString)1