Search in sources :

Example 41 with ITTCN3Template

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

the class TTCN3_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 42 with ITTCN3Template

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

the class SpecificValue_Template method checkSpecificValue.

@Override
public /**
 * {@inheritDoc}
 */
void checkSpecificValue(final CompilationTimeStamp timestamp, final boolean allowOmit) {
    if (specificValue == null) {
        return;
    }
    switch(specificValue.getValuetype()) {
        case EXPRESSION_VALUE:
            // checked later
            break;
        case OMIT_VALUE:
            if (!allowOmit) {
                getLocation().reportSemanticError(OmitValue_Template.SPECIFICVALUEEXPECTED);
            }
            return;
        default:
            return;
    }
    final Expression_Value expressionValue = (Expression_Value) specificValue;
    if (!Operation_type.APPLY_OPERATION.equals(expressionValue.getOperationType())) {
        return;
    }
    expressionValue.setLoweridToReference(timestamp);
    IType type = ((ApplyExpression) expressionValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type == null) {
        return;
    }
    type = type.getTypeRefdLast(timestamp);
    if (Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
        final ITTCN3Template template = setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
        template.checkSpecificValue(timestamp, allowOmit);
    }
}
Also used : Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) ApplyExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ApplyExpression) IType(org.eclipse.titan.designer.AST.IType)

Example 43 with ITTCN3Template

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

the class TTCN3Template method getReferencedArrayTemplate.

/**
 * Checks whether array indexing is allowed for a given template sub
 * reference or not.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param arrayIndex
 *                the index to check.
 * @param referenceChain
 *                the reference chain use to detect circular references.
 */
protected ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
    switch(getTemplatetype()) {
        case OMIT_VALUE:
        case ANY_VALUE:
        case ANY_OR_OMIT:
        case VALUE_LIST:
        case COMPLEMENTED_LIST:
        case SUPERSET_MATCH:
        case SUBSET_MATCH:
            arrayIndex.getLocation().reportSemanticError(MessageFormat.format("Reference with index to an element of {0} `{1}''", getTemplateTypeName(), getFullName()));
            break;
        default:
            break;
    }
    IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
    indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
    if (indexValue.getIsErroneous(timestamp)) {
        return null;
    }
    long index = 0;
    if (!indexValue.isUnfoldable(timestamp)) {
        if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
            index = ((Integer_Value) indexValue).getValue();
        } else {
            arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
            return null;
        }
    } else {
        return null;
    }
    final IType tempType = myGovernor.getTypeRefdLast(timestamp);
    if (tempType.getIsErroneous(timestamp)) {
        return null;
    }
    switch(tempType.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            if (index < 0) {
                final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            } else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
                return null;
            } else {
                final int nofElements = ((Template_List) this).getNofTemplates();
                if (index > nofElements) {
                    final String message = MessageFormat.format("Index overflow in a template of `sequence of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
            }
            break;
        case TYPE_SET_OF:
            if (index < 0) {
                final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            } else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
                return null;
            } else {
                final int nofElements = ((Template_List) this).getNofTemplates();
                if (index > nofElements) {
                    final String message = MessageFormat.format("Index overflow in a template of `set of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
            }
            break;
        case TYPE_ARRAY:
            {
                final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
                dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                if (Template_type.TEMPLATE_LIST.equals(getTemplatetype()) && !dimension.getIsErroneous(timestamp)) {
                    // re-base the index
                    index -= dimension.getOffset();
                    if (index < 0 || index > ((Template_List) this).getNofTemplates()) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
                        return null;
                    }
                } else {
                    return null;
                }
                break;
            }
        default:
            {
                final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            }
    }
    if (this instanceof Template_List) {
        final TTCN3Template returnValue = ((Template_List) this).getTemplateByIndex((int) index);
        if (Template_type.TEMPLATE_NOTUSED.equals(returnValue.getTemplatetype())) {
            if (baseTemplate != null) {
                return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
            }
            return null;
        }
        return returnValue;
    } else {
        return null;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) IType(org.eclipse.titan.designer.AST.IType)

Example 44 with ITTCN3Template

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

the class TemplateInstance method reArrangeInitCode.

/**
 * Walks through the templateinstance recursively and appends the java
 * initialization sequence of all (directly or indirectly) referenced
 * non-parameterized templates and the default values of all
 * parameterized templates to source and returns the resulting string.
 * Only objects belonging to module usageModule are initialized.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source for code generated
 * @param usageModule the module where the template is to be used.
 */
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
    if (derivedReference != null) {
        final List<ISubReference> subreferences = derivedReference.getSubreferences();
        if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
            final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
            final ActualParameterList actualParameterList = subreference.getActualParameters();
            if (actualParameterList != null) {
                actualParameterList.reArrangeInitCode(aData, source, usageModule);
            }
        }
        final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment == null) {
            return;
        }
        if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
            final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
            if (formalParameterList != null) {
                // the referred template is parameterized
                // the embedded referenced templates shall be visited
                template.reArrangeInitCode(aData, source, usageModule);
            // FIXME implement
            } else {
                // its entire body has to be initialized now
                if (assignment.getMyScope().getModuleScope() == usageModule) {
                    template.generateCodeInit(aData, source, template.get_lhs_name());
                }
            }
        }
    }
    if (templateBody != null) {
        templateBody.reArrangeInitCode(aData, source, usageModule);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 45 with ITTCN3Template

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

the class Template_List method getReferencedArrayTemplate.

@Override
protected /**
 * {@inheritDoc}
 */
ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
    IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
    indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
    if (indexValue.getIsErroneous(timestamp)) {
        return null;
    }
    long index = 0;
    if (!indexValue.isUnfoldable(timestamp)) {
        if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
            index = ((Integer_Value) indexValue).getValue();
        } else {
            arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
            return null;
        }
    } else {
        return null;
    }
    final IType tempType = myGovernor.getTypeRefdLast(timestamp);
    if (tempType.getIsErroneous(timestamp)) {
        return null;
    }
    switch(tempType.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            {
                if (index < 0) {
                    final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                final int nofElements = getNofTemplates();
                if (!(index < nofElements)) {
                    final String message = MessageFormat.format("Index overflow in a template of `sequence of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                break;
            }
        case TYPE_SET_OF:
            {
                if (index < 0) {
                    final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                final int nofElements = getNofTemplates();
                if (!(index < nofElements)) {
                    final String message = MessageFormat.format("Index overflow in a template of `set of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                break;
            }
        case TYPE_ARRAY:
            {
                final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
                dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                if (!dimension.getIsErroneous(timestamp)) {
                    // re-base the index
                    index -= dimension.getOffset();
                    if (index < 0 || !(index < getNofTemplates())) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
                        return null;
                    }
                } else {
                    return null;
                }
                break;
            }
        default:
            {
                final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            }
    }
    final ITTCN3Template returnValue = getTemplateByIndex((int) index);
    if (Template_type.TEMPLATE_NOTUSED.equals(returnValue.getTemplatetype())) {
        if (baseTemplate != null) {
            return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
        }
        return null;
    }
    return returnValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) IType(org.eclipse.titan.designer.AST.IType)

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