Search in sources :

Example 46 with ITTCN3Template

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

the class Float_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    if (getIsErroneous(timestamp)) {
        return false;
    }
    if (Template_type.VALUE_RANGE.equals(template.getTemplatetype())) {
        final ValueRange range = ((Value_Range_Template) template).getValueRange();
        final IValue lower = checkBoundary(timestamp, range.getMin());
        final IValue upper = checkBoundary(timestamp, range.getMax());
        range.setTypeType(getTypetypeTtcn3());
        if (lower != null && upper != null) {
            if (((Real_Value) lower).getValue() > ((Real_Value) upper).getValue()) {
                template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
            }
        }
    // TODO: some checks are still missing
    } else {
        template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
    }
    return false;
}
Also used : ValueRange(org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange) IValue(org.eclipse.titan.designer.AST.IValue) Value_Range_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Value_Range_Template)

Example 47 with ITTCN3Template

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

the class Integer_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    switch(template.getTemplatetype()) {
        case VALUE_RANGE:
            final ValueRange range = ((Value_Range_Template) template).getValueRange();
            final IValue lower = checkBoundary(timestamp, range.getMin(), BOUNDARY_TYPE.LOWER);
            final IValue upper = checkBoundary(timestamp, range.getMax(), BOUNDARY_TYPE.UPPER);
            range.setTypeType(getTypetypeTtcn3());
            // Template references are not checked.
            if (lower != null && Value.Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && upper != null && Value.Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
                if (!getIsErroneous(timestamp) && ((Integer_Value) lower).getValue() > ((Integer_Value) upper).getValue()) {
                    template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
                    template.setIsErroneous(true);
                }
            }
            // TODO some checks are still missing
            break;
        case VALUE_LIST:
            final ValueList_Template temp = (ValueList_Template) template;
            for (int i = 0; i < temp.getNofTemplates(); i++) {
                final TTCN3Template tmp = temp.getTemplateByIndex(i);
                selfReference |= checkThisTemplate(timestamp, tmp, isModified, implicitOmit, lhs);
            }
            break;
        case ANY_OR_OMIT:
        case ANY_VALUE:
            // Allowed
            break;
        default:
            template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
            template.setIsErroneous(true);
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
        template.setIsErroneous(true);
    }
    return selfReference;
}
Also used : ValueRange(org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Value_Range_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Value_Range_Template) ValueList_Template(org.eclipse.titan.designer.AST.TTCN3.templates.ValueList_Template)

Example 48 with ITTCN3Template

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

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

the class ASN1_Sequence_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    boolean selfReference = false;
    switch(template.getTemplatetype()) {
        case TEMPLATE_LIST:
            final ITTCN3Template transformed = template.setTemplatetype(timestamp, Template_type.NAMED_TEMPLATE_LIST);
            selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) transformed, isModified, implicitOmit, lhs);
            break;
        case NAMED_TEMPLATE_LIST:
            selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) template, isModified, implicitOmit, lhs);
            break;
        default:
            template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
            break;
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)

Example 50 with ITTCN3Template

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

the class ASN1_Set_Type method checkThisNamedTemplateList.

/**
 * Checks the provided named template list against this type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param templateList
 *                the template list to check
 * @param isModified
 *                true if the template is modified otherwise false.
 * @param implicitOmit
 *                true it the template has implicit omit attribute set,
 *                false otherwise.
 * @param lhs
 *                the assignment to check against
 * @return true if the value contains a reference to lhs
 */
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List templateList, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    templateList.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
    final int nofTypeComponents = getNofComponents(timestamp);
    final int nofTemplateComponents = templateList.getNofTemplates();
    for (int i = 0; i < nofTemplateComponents; i++) {
        final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
        final Identifier identifier = namedTemplate.getName();
        final String templateName = identifier.getName();
        if (hasComponentWithName(identifier)) {
            if (componentMap.containsKey(templateName)) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDFIRST, identifier.getDisplayName()));
                componentMap.get(templateName).getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
            } else {
                componentMap.put(templateName, namedTemplate);
            }
            final CompField componentField = getComponentByName(identifier);
            final Type type = componentField.getType();
            if (type != null && !type.getIsErroneous(timestamp)) {
                ITTCN3Template componentTemplate = namedTemplate.getTemplate();
                componentTemplate.setMyGovernor(type);
                componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
                boolean isOptional = componentField.isOptional();
                if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
                    isOptional = true;
                }
                selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
            }
        } else {
            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
        }
    }
    if (!isModified && strictConstantCheckingSeverity) {
        // check missing fields
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier identifier = getComponentIdentifierByIndex(i);
            if (!componentMap.containsKey(identifier.getName())) {
                if (getComponentByIndex(i).isOptional() && implicitOmit) {
                    templateList.addNamedValue(new NamedTemplate(new Identifier(Identifier_type.ID_TTCN, identifier.getDisplayName()), new OmitValue_Template(), false));
                } else {
                    templateList.getLocation().reportSemanticError(MessageFormat.format(MISSINGTEMPLATEFIELD, identifier.getDisplayName(), getTypename()));
                }
            }
        }
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) HashMap(java.util.HashMap) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)67 IType (org.eclipse.titan.designer.AST.IType)42 IValue (org.eclipse.titan.designer.AST.IValue)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)19 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)19 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Type (org.eclipse.titan.designer.AST.Type)13 ISubReference (org.eclipse.titan.designer.AST.ISubReference)12 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)12 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)12 Reference (org.eclipse.titan.designer.AST.Reference)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)6 HashMap (java.util.HashMap)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)5