Search in sources :

Example 16 with TTCN3Template

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

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

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

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

the class TemplateParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
        // TODO : find a more sophisticated way of storing symbols (e.g. SymbolTable)
        myASTVisitor.nodeNameNodeTypeHashMap.put(name, "template");
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        template = new Template(name, type);
        return Action.skip(Type.class, this);
    }
    if (node instanceof FormalParameterList) {
        return new FormalParameterParser(this, template);
    }
    // is a modification
    if (node instanceof Reference) {
        Reference reference = (Reference) node;
        String basename = reference.getId().toString();
        Template base = registry.find(basename);
        // TODO : templates need a base value as a fallback
        // TODO : this base value should be used as a reference, to diff against
        // TODO : this was a hotfix for the union types to work
        String type = base.getValue().getType();
        template.setValue(new Value(type, (code, indent) -> code.append("(", type, ") ").append(basename, "()")));
        isModification = true;
        return Action.skip(Reference.class, this);
    }
    if (node instanceof TTCN3Template) {
        if (isModification) {
            return ModificationParser.getScope(this, template, "", type, node);
        }
        return TemplateValueParser.getScope(this, template, type, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Reference(org.eclipse.titan.designer.AST.Reference) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Identifier(org.eclipse.titan.designer.AST.Identifier) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Type(org.eclipse.titan.designer.AST.Type) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 20 with TTCN3Template

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

the class SelectCase method generateCode.

/**
 * Add generated java code for a single select case.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source code generated
 * @param name the name to compare the branch variables to (expression or temporary name)
 * @param unReachable tells whether this branch is already unreachable because of previous conditions
 */
public void generateCode(final JavaGenData aData, final StringBuilder source, final String name, final AtomicBoolean unreach) {
    ExpressionStruct expression = new ExpressionStruct();
    StringBuilder condition = new StringBuilder();
    if (templateInstances != null) {
        for (int i = 0; i < templateInstances.getNofTis(); i++) {
            final String tmp = aData.getTemporaryVariableName();
            final TemplateInstance templateInstance = templateInstances.getInstanceByIndex(i);
            final TTCN3Template templateBody = templateInstance.getTemplateBody();
            final boolean isValue = templateInstance.getDerivedReference() == null && templateBody.isValue(CompilationTimeStamp.getBaseTimestamp());
            final IType last = templateInstance.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            if (i > 0) {
                condition.append(" || ");
            }
            if (isValue) {
                final String genName = last.getGenNameValue(aData, expression.expression, last.getMyScope());
                expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
                IValue value = templateBody.getValue();
                value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
                value.generateCodeExpressionMandatory(aData, expression, true);
                expression.expression.append(");\n");
                condition.append(MessageFormat.format("{0}.operatorEquals({1})", tmp, name));
            } else {
                final String genName = last.getGenNameTemplate(aData, expression.expression, last.getMyScope());
                expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
                templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
                expression.expression.append(");\n");
                condition.append(MessageFormat.format("{0}.match({1})", tmp, name));
            }
        }
        source.append(expression.preamble);
        source.append(expression.expression);
        source.append(expression.postamble);
        getLocation().update_location_object(aData, source);
        source.append("if (").append(condition).append(") {\n");
        statementBlock.generateCode(aData, source);
        source.append("}\n");
    } else {
        statementBlock.generateCode(aData, source);
        unreach.set(true);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)23 IValue (org.eclipse.titan.designer.AST.IValue)18 Reference (org.eclipse.titan.designer.AST.Reference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)12 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IType (org.eclipse.titan.designer.AST.IType)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)9 ArrayList (java.util.ArrayList)4 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 Type (org.eclipse.titan.designer.AST.Type)4 Identifier (org.eclipse.titan.designer.AST.Identifier)3 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)3 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)3 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)3 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)2