Search in sources :

Example 16 with LengthRestriction

use of org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction in project titan.EclipsePlug-ins by eclipse.

the class SubType method checkThisTemplateLengthRestriction.

private void checkThisTemplateLengthRestriction(final CompilationTimeStamp timestamp, final TTCN3Template template) {
    final LengthRestriction lengthRestriction = template.getLengthRestriction();
    if ((lengthRestriction == null) || (subtypeConstraint == null)) {
        return;
    }
    // if there is a length restriction on the template then check
    // if
    // the intersection of the two restrictions is not empty
    SizeLimit tmplMinLen, tmplMaxLen;
    lengthRestriction.check(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (lengthRestriction instanceof SingleLenghtRestriction) {
        final SingleLenghtRestriction realRestriction = (SingleLenghtRestriction) lengthRestriction;
        final IValue lower = realRestriction.getRestriction(timestamp);
        if (lower.getIsErroneous(timestamp)) {
            return;
        }
        final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = lower.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, chain);
        chain.release();
        if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
            return;
        }
        final BigInteger length = ((Integer_Value) last).getValueValue();
        tmplMinLen = new SizeLimit(length);
        tmplMaxLen = tmplMinLen;
    } else {
        final RangeLenghtRestriction realRestriction = (RangeLenghtRestriction) lengthRestriction;
        final IValue lower = realRestriction.getLowerValue(timestamp);
        IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue lastLower = lower.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, chain);
        chain.release();
        if (lastLower.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lastLower.getValuetype())) {
            return;
        }
        final IValue upper = realRestriction.getUpperValue(timestamp);
        if (upper == null) {
            return;
        }
        chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue lastUpper = upper.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, chain);
        chain.release();
        if (lastUpper.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lastUpper.getValuetype())) {
            return;
        }
        tmplMinLen = new SizeLimit(((Integer_Value) lastLower).getValueValue());
        tmplMaxLen = new SizeLimit(((Integer_Value) lastUpper).getValueValue());
    }
    SubtypeConstraint tmplConstraint;
    switch(subtypeType) {
        case ST_BITSTRING:
            tmplConstraint = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, tmplMinLen, tmplMaxLen);
            break;
        case ST_HEXSTRING:
            tmplConstraint = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, tmplMinLen, tmplMaxLen);
            break;
        case ST_OCTETSTRING:
            tmplConstraint = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, tmplMinLen, tmplMaxLen);
            break;
        case ST_CHARSTRING:
            tmplConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.SIZE_CONSTRAINT, new RangeListConstraint(tmplMinLen, tmplMaxLen));
            break;
        case ST_UNIVERSAL_CHARSTRING:
            tmplConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.SIZE_CONSTRAINT, new RangeListConstraint(tmplMinLen, tmplMaxLen));
            break;
        case ST_RECORDOF:
        case ST_SETOF:
            tmplConstraint = new ValueListAndSizeConstraint(tmplMinLen, tmplMaxLen);
            break;
        default:
            return;
    }
    if (subtypeConstraint.intersection(tmplConstraint).isEmpty() == TernaryBool.TTRUE) {
        template.getLocation().reportSemanticWarning(MessageFormat.format("Template's length restriction {0} is outside of the type's subtype constraint {1}", (new RangeListConstraint(tmplMinLen, tmplMaxLen)).toString(), subtypeConstraint.toString()));
    }
}
Also used : LengthRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction) IValue(org.eclipse.titan.designer.AST.IValue) RangeLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.RangeLenghtRestriction) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) BigInteger(java.math.BigInteger)

Example 17 with LengthRestriction

use of org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction in project titan.EclipsePlug-ins by eclipse.

the class SubType method checkThisTemplateGeneric.

/**
 * Does the semantic checking of the provided template according to the
 * a specific sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param template
 *                the template to be checked by the type.
 */
public void checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final ITTCN3Template template) {
    if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
        return;
    }
    if (template.getIsErroneous(timestamp)) {
        return;
    }
    final TTCN3Template t = template.getTemplateReferencedLast(timestamp);
    if (t.getIsErroneous(timestamp)) {
        return;
    }
    switch(t.getTemplatetype()) {
        case OMIT_VALUE:
        case ANY_OR_OMIT:
        case ANY_VALUE:
        case VALUE_LIST:
        case COMPLEMENTED_LIST:
        case SPECIFIC_VALUE:
        case TEMPLATE_REFD:
        case TEMPLATE_INVOKE:
            break;
        case TEMPLATE_LIST:
            if ((subtypeType == SubType_type.ST_RECORDOF) || (subtypeType == SubType_type.ST_SETOF)) {
                if ((lengthRestriction == null) || (lengthRestriction.isEmpty() == TernaryBool.TTRUE)) {
                    break;
                }
                final SizeLimit minLimit = (SizeLimit) lengthRestriction.getMinimal();
                final SizeLimit maxLimit = (SizeLimit) lengthRestriction.getMaximal();
                final Template_List list = (Template_List) template;
                final int fixComponents = list.getNofTemplatesNotAnyornone(timestamp);
                if (!list.templateContainsAnyornone() && (fixComponents < minLimit.getSize().intValue())) {
                    template.getLocation().reportSemanticError(MessageFormat.format("At least {0} elements must be present in the list", minLimit.getSize().intValue()));
                    return;
                } else if (!maxLimit.getInfinity() && (fixComponents > maxLimit.getSize().intValue())) {
                    template.getLocation().reportSemanticError(MessageFormat.format("There must not be more than {0} elements in the list", maxLimit.getSize().intValue()));
                    return;
                }
            }
            // and set types
            break;
        case INDEXED_TEMPLATE_LIST:
        case NAMED_TEMPLATE_LIST:
        case VALUE_RANGE:
            // FIXME implement checking
            break;
        case SUPERSET_MATCH:
            {
                if (subtypeType != SubType_type.ST_SETOF) {
                    template.getLocation().reportSemanticError("'superset' template matching mechanism can be used only with 'set of' types");
                }
                final SupersetMatch_Template temp = (SupersetMatch_Template) template;
                for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                    checkThisTemplateGeneric(timestamp, temp.getTemplateByIndex(i));
                }
                break;
            }
        case SUBSET_MATCH:
            {
                if (subtypeType != SubType_type.ST_SETOF) {
                    template.getLocation().reportSemanticError("'subset' template matching mechanism can be used only with 'set of' types");
                }
                final SubsetMatch_Template temp = (SubsetMatch_Template) template;
                for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                    checkThisTemplateGeneric(timestamp, temp.getTemplateByIndex(i));
                }
                break;
            }
        case BSTR_PATTERN:
            checkThisTemplatePattern(template, "bitstring", ((BitString_Pattern_Template) template).getMinLengthOfPattern(), ((BitString_Pattern_Template) template).containsAnyornoneSymbol());
            break;
        case HSTR_PATTERN:
            checkThisTemplatePattern(template, "hexstring", ((HexString_Pattern_Template) template).getMinLengthOfPattern(), ((HexString_Pattern_Template) template).containsAnyornoneSymbol());
            break;
        case OSTR_PATTERN:
            checkThisTemplatePattern(template, "octetstring", ((OctetString_Pattern_Template) template).getMinLengthOfPattern(), ((OctetString_Pattern_Template) template).containsAnyornoneSymbol());
            break;
        case CSTR_PATTERN:
            checkThisTemplatePattern(template, "charstring", ((CharString_Pattern_Template) template).getMinLengthOfPattern(), ((CharString_Pattern_Template) template).patternContainsAnyornoneSymbol());
            break;
        case USTR_PATTERN:
            checkThisTemplatePattern(template, "universal charstring", ((UnivCharString_Pattern_Template) template).getMinLengthOfPattern(), ((UnivCharString_Pattern_Template) template).patternContainsAnyornoneSymbol());
            break;
        default:
            break;
    }
    checkThisTemplateLengthRestriction(timestamp, t);
}
Also used : Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) SubsetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) SupersetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template)

Example 18 with LengthRestriction

use of org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction 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 19 with LengthRestriction

use of org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction in project titan.EclipsePlug-ins by eclipse.

the class SubType method addTtcnLength.

private boolean addTtcnLength(final CompilationTimeStamp timestamp, final LengthRestriction lengthRestriction, final int restrictionIndex) {
    lengthRestriction.setMyScope(myOwner.getMyScope());
    final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<length_restriction_" + restrictionIndex + ">");
    lengthRestriction.setFullNameParent(bridge);
    lengthRestriction.check(timestamp, Expected_Value_type.EXPECTED_CONSTANT);
    IValue lower = null, upper = null;
    if (lengthRestriction instanceof SingleLenghtRestriction) {
        lower = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
        if (lower == null || lower.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lower.getValuetype()) || lower.isUnfoldable(timestamp)) {
            return false;
        }
        if (!checkBoundaryValid(lower, "length restriction value")) {
            return false;
        }
        final SizeLimit boundaryLimit = new SizeLimit(((Integer_Value) lower).getValueValue());
        return setTtcnLength(boundaryLimit, boundaryLimit);
    }
    lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
    if (lower == null || lower.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lower.getValuetype()) || lower.isUnfoldable(timestamp)) {
        return false;
    }
    if (!checkBoundaryValid(lower, "lower boundary")) {
        return false;
    }
    upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
    if (upper != null) {
        if (upper.getMyScope() == null) {
            upper.setMyScope(myOwner.getMyScope());
        }
        if (upper.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(upper.getValuetype()) || upper.isUnfoldable(timestamp)) {
            return false;
        }
        if (!checkBoundaryValid(upper, "upper boundary")) {
            return false;
        }
        return setTtcnLength(new SizeLimit(((Integer_Value) lower).getValueValue()), new SizeLimit(((Integer_Value) upper).getValueValue()));
    }
    // upper is infinity
    return setTtcnLength(new SizeLimit(((Integer_Value) lower).getValueValue()), SizeLimit.MAXIMUM);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 20 with LengthRestriction

use of org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction in project titan.EclipsePlug-ins by eclipse.

the class CompositeTemplate method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (lengthRestriction != null) {
        lengthRestriction.updateSyntax(reparser, false);
        reparser.updateLocation(lengthRestriction.getLocation());
    }
    if (baseTemplate instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
        reparser.updateLocation(baseTemplate.getLocation());
    } else if (baseTemplate != null) {
        throw new ReParseException();
    }
    templates.updateSyntax(reparser, false);
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)8 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 IIncrementallyUpdateable (org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable)7 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)7 IType (org.eclipse.titan.designer.AST.IType)6 Reference (org.eclipse.titan.designer.AST.Reference)6 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)6 IValue (org.eclipse.titan.designer.AST.IValue)5 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)5 ArrayList (java.util.ArrayList)4 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)4 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)4 SingleLenghtRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 LengthRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction)2 RangeLenghtRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.RangeLenghtRestriction)2 SubsetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template)2 SupersetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template)2