Search in sources :

Example 1 with UnivCharString_Pattern_Template

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

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

the class UniversalCharstring_Type method checkThisTemplateString.

/**
 * Checks if the provided template is valid for the provided type.
 * <p>
 * The type must be equivalent with the TTCN-3 universal charstring type
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 * @param type the universal charstring type used for the check.
 * @param template the template to be checked by the type.
 * @param isModified true if the template is a modified template
 */
public static void checkThisTemplateString(final CompilationTimeStamp timestamp, final Type type, final ITTCN3Template template, final boolean isModified) {
    template.setMyGovernor(type);
    PatternString ps = null;
    switch(template.getTemplatetype()) {
        case VALUE_RANGE:
            {
                final ValueRange range = ((Value_Range_Template) template).getValueRange();
                final IValue lower = checkBoundary(timestamp, type, range.getMin(), template, "lower");
                final IValue upper = checkBoundary(timestamp, type, range.getMax(), template, "upper");
                range.setTypeType(type.getTypetypeTtcn3());
                if (lower != null && upper != null) {
                    UniversalCharstring value1;
                    if (Value_type.CHARSTRING_VALUE.equals(lower.getValuetype())) {
                        value1 = new UniversalCharstring(((Charstring_Value) lower).getValue());
                    } else {
                        value1 = ((UniversalCharstring_Value) lower).getValue();
                    }
                    UniversalCharstring value2;
                    if (Value_type.CHARSTRING_VALUE.equals(upper.getValuetype())) {
                        value2 = new UniversalCharstring(((Charstring_Value) upper).getValue());
                    } else {
                        value2 = ((UniversalCharstring_Value) upper).getValue();
                    }
                    if (value1.compareWith(value2) > 0) {
                        template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
                    }
                }
                break;
            }
        case CSTR_PATTERN:
            {
                // Change the pattern type
                final CharString_Pattern_Template cstrpt = (CharString_Pattern_Template) template;
                ps = cstrpt.getPatternstring();
                ps.setPatterntype(PatternType.UNIVCHARSTRING_PATTERN);
                // FIXME might need some implementation
                break;
            }
        case USTR_PATTERN:
            // FIXME implement as soon as charstring pattern templates become handled
            ps = ((UnivCharString_Pattern_Template) template).getPatternstring();
            break;
        default:
            template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), type.getTypename()));
            break;
    }
}
Also used : ValueRange(org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) PatternString(org.eclipse.titan.designer.AST.TTCN3.templates.PatternString) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) CharString_Pattern_Template(org.eclipse.titan.designer.AST.TTCN3.templates.CharString_Pattern_Template) UnivCharString_Pattern_Template(org.eclipse.titan.designer.AST.TTCN3.templates.UnivCharString_Pattern_Template)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)1 CharString_Pattern_Template (org.eclipse.titan.designer.AST.TTCN3.templates.CharString_Pattern_Template)1 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)1 PatternString (org.eclipse.titan.designer.AST.TTCN3.templates.PatternString)1 SubsetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template)1 SupersetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template)1 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)1 Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Template_List)1 UnivCharString_Pattern_Template (org.eclipse.titan.designer.AST.TTCN3.templates.UnivCharString_Pattern_Template)1 ValueRange (org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange)1 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)1 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)1