Search in sources :

Example 26 with ITTCN3Template

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

the class FormalParameter method checkActualParameterTimer.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a timer parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param expectedValue
 *                the value kind expected from the actual parameter.
 *
 * @return the actual parameter created from the value, or null if there
 *         was an error.
 */
private ActualParameter checkActualParameterTimer(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    final IType parameterType = actualParameter.getType();
    if (parameterType != null) {
        actualParameter.getLocation().reportSemanticError(EXPLICITESPECIFICATIONFORTIMER);
        actualParameter.checkType(timestamp, null);
    }
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(INLINETEMPLATEFORTIMER);
        actualParameter.checkDerivedReference(timestamp, null);
    }
    final ITTCN3Template template = actualParameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true, null);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        switch(assignment.getAssignmentType()) {
            case A_TIMER:
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, expectedValue);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
                }
                break;
            case A_PAR_TIMER:
                if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR2, assignment.getDescription()));
                }
                break;
            default:
                reference.getLocation().reportSemanticError(MessageFormat.format(TIMEREXPECTED1, assignment.getAssignmentName()));
                break;
        }
        return new Referenced_ActualParameter(reference);
    }
    actualParameter.getLocation().reportSemanticError(TIMEREXPECTED2);
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) IType(org.eclipse.titan.designer.AST.IType)

Example 27 with ITTCN3Template

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

the class Assignment_Statement method checkTemplateAssignment.

private void checkTemplateAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    IType type = getType(timestamp, assignment);
    if (type == null) {
        isErroneous = true;
        return;
    }
    // temp
    type.check(timestamp);
    type = type.getFieldType(timestamp, reference, 1, expectedValue, false);
    if (type == null) {
        isErroneous = true;
        return;
    }
    template.setMyGovernor(type);
    final ITTCN3Template temporalTemplate = type.checkThisTemplateRef(timestamp, template, expectedValue, referenceChain);
    selfReference = temporalTemplate.checkThisTemplateGeneric(timestamp, type, true, true, true, true, false, assignment);
    checkTemplateRestriction(timestamp);
    if (reference.refersToStringElement()) {
        if (!template.isValue(timestamp)) {
            template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
            template.setIsErroneous(true);
            // isErroneous = true; //????
            return;
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IType(org.eclipse.titan.designer.AST.IType)

Example 28 with ITTCN3Template

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

the class ASN1_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;
    }
    if (Template_type.VALUE_RANGE.equals(template.getTemplatetype())) {
        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());
        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);
            }
        }
    // 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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) Value_Range_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Value_Range_Template)

Example 29 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 checkThisNamedTemplateList.

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();
    boolean inSync = true;
    CompField lastComponentField = null;
    int nextIndex = 0;
    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()));
                final Location tempLocation = componentMap.get(templateName).getLocation();
                tempLocation.reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
                inSync = false;
            } else {
                componentMap.put(templateName, namedTemplate);
            }
            final CompField componentField = getComponentByName(identifier);
            if (inSync) {
                if (isModified) {
                    boolean found = false;
                    for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                        final CompField componentField2 = getComponentByIndex(j);
                        if (templateName.equals(componentField2.getIdentifier().getName())) {
                            lastComponentField = componentField2;
                            nextIndex = j + 1;
                            found = true;
                        }
                    }
                    if (!found && lastComponentField != null) {
                        namedTemplate.getLocation().reportSemanticError(MessageFormat.format(INCORRECTTEMPLATEFIELDORDER, identifier.getDisplayName(), lastComponentField.getIdentifier().getDisplayName(), getFullName()));
                        inSync = false;
                    }
                } else if (strictConstantCheckingSeverity) {
                    final CompField componentField2 = getComponentByIndex(i);
                    if (componentField2 != componentField) {
                        if (!componentField2.isOptional() || (componentField2.isOptional() && !implicitOmit)) {
                            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDTEMPLATEFIELD, identifier.getDisplayName(), componentField2.getIdentifier().getDisplayName()));
                            inSync = false;
                        }
                    }
                }
            }
            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()));
            inSync = false;
        }
    }
    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) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_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) Location(org.eclipse.titan.designer.AST.Location)

Example 30 with ITTCN3Template

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

the class ASN1_Choice_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;
    if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
        final Named_Template_List namedTemplateList = (Named_Template_List) template;
        final int nofTemplates = namedTemplateList.getNofTemplates();
        if (nofTemplates != 1) {
            template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
            template.setIsErroneous(true);
        }
        for (int i = 0; i < nofTemplates; i++) {
            final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
            final Identifier name = namedTemplate.getName();
            final CompField field = components.getCompByName(name);
            if (field == null) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
            } else {
                final Type fieldType = field.getType();
                if (fieldType != null && !fieldType.getIsErroneous(timestamp)) {
                    ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
                    namedTemplateTemplate.setMyGovernor(fieldType);
                    namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
                    final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
                    selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
                }
            }
        }
    } else {
        template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
        template.setIsErroneous(true);
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
        template.setIsErroneous(true);
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Completeness_type(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Completeness_type) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)

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