Search in sources :

Example 16 with Named_Template_List

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

the class Signature_Type method checkThisNamedTemplateList.

// see void Type::chk_this_template_Signature(Template *t, namedbool incomplete_allowed) in Type_chk.cc
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List template, final boolean isModified, final Assignment lhs) {
    final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
    boolean inSynch = true;
    // TODO:  alternatives:formalParList.getNofInParameters(); formalParList.getNofOutParameters()
    final int nofTypeParameters = getNofParameters();
    final int nofTemplateComponents = template.getNofTemplates();
    int tI = 0;
    boolean selfReference = false;
    for (int vI = 0; vI < nofTemplateComponents; vI++) {
        final NamedTemplate namedTemplate = template.getTemplateByIndex(vI);
        final Identifier identifier = namedTemplate.getName();
        final String name = identifier.getName();
        if (hasParameterWithName(name)) {
            if (componentMap.containsKey(name)) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, identifier.getDisplayName(), getTypename()));
                componentMap.get(name).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEPARAMETERFIRST, identifier.getDisplayName()));
                inSynch = false;
            } else {
                componentMap.put(name, namedTemplate);
            }
            final SignatureFormalParameter parameter = formalParList.getParameterByName(name);
            if (inSynch) {
                SignatureFormalParameter parameter2 = null;
                boolean found = false;
                for (; tI < nofTypeParameters && !found; tI++) {
                    parameter2 = formalParList.getParameterByIndex(tI);
                    if (parameter == parameter2) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    namedTemplate.getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDPARAMETER, identifier.getDisplayName()));
                    inSynch = false;
                }
            }
            final Type parameterType = parameter.getType();
            ITTCN3Template componentTemplate = namedTemplate.getTemplate();
            // FIXME: will be overwritten?
            componentTemplate.setMyGovernor(parameterType);
            componentTemplate = parameterType.checkThisTemplateRef(timestamp, componentTemplate);
            selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, parameterType, isModified, false, false, true, false, lhs);
        } else {
            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, identifier.getDisplayName(), getTypename()));
            inSynch = false;
        }
    }
    if (isModified) {
        SignatureFormalParameter firstUndefIn = null;
        SignatureFormalParameter firstUndefOut = null;
        for (int i = 0; i < nofTypeParameters; i++) {
            final SignatureFormalParameter parameter = formalParList.getParameterByIndex(i);
            final Identifier identifier = parameter.getIdentifier();
            if (!componentMap.containsKey(identifier.getName()) || Template_type.TEMPLATE_NOTUSED.equals(componentMap.get(identifier.getName()).getTemplate().getTemplatetype())) {
                switch(parameter.getDirection()) {
                    case PARAM_IN:
                        if (firstUndefIn == null) {
                            firstUndefIn = parameter;
                        }
                        break;
                    case PARAM_OUT:
                        if (firstUndefOut == null) {
                            firstUndefOut = parameter;
                        }
                        break;
                    default:
                        template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE1, identifier.getDisplayName()));
                        break;
                }
            }
        }
        if (firstUndefIn != null && firstUndefOut != null) {
            template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE2, firstUndefIn.getIdentifier().getDisplayName(), firstUndefOut.getIdentifier().getDisplayName()));
        }
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) SignatureReturnType(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType) 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)

Example 17 with Named_Template_List

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

the class TTCN3_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);
        }
        for (int i = 0; i < nofTemplates; i++) {
            final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
            final Identifier name = namedTemplate.getName();
            final CompField field = compFieldMap.getCompWithName(name);
            if (field == null) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
            } else {
                final Type fieldType = field.getType();
                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()));
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
    }
    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) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)

Example 18 with Named_Template_List

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

the class TTCN3_Sequence_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
 *                is the template modified or not ?
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the template, false otherwise
 */
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();
    final int nofTemplateComponents = templateList.getNofTemplates();
    boolean inSync = true;
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    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 (realComponents.containsKey(templateName)) {
            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.getName());
            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) {
                        final String message = MessageFormat.format(INCORRECTTEMPLATEFIELDORDER, identifier.getDisplayName(), lastComponentField.getIdentifier().getDisplayName(), getFullName());
                        namedTemplate.getLocation().reportSemanticError(message);
                        inSync = false;
                    }
                } else if (strictConstantCheckingSeverity) {
                    final CompField componentField2 = getComponentByIndex(i);
                    if (componentField2 != componentField) {
                        if (!componentField2.isOptional() || (componentField2.isOptional() && !implicitOmit)) {
                            final String message = MessageFormat.format(UNEXPECTEDTEMPLATEFIELD, identifier.getDisplayName(), componentField2.getIdentifier().getDisplayName());
                            namedTemplate.getLocation().reportSemanticError(message);
                            inSync = false;
                        }
                    }
                }
            }
            Type type = componentField.getType();
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            type = (Type) type.getTypeRefdLast(timestamp);
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            ITTCN3Template componentTemplate = namedTemplate.getTemplate();
            componentTemplate.setMyGovernor(type);
            componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
            final boolean isOptional = componentField.isOptional();
            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 (identifier == null) {
                continue;
            }
            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) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) 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) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Example 19 with Named_Template_List

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

the class TTCN3_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 is the template modified or not ?
 * @param implicitOmit indicates whether the template has the implicit omit attribute set or not.
 */
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();
    final int nofTemplateComponents = templateList.getNofTemplates();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    for (int i = 0; i < nofTemplateComponents; i++) {
        final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
        final Identifier identifier = namedTemplate.getName();
        final String templateName = identifier.getName();
        if (realComponents.containsKey(templateName)) {
            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.getName());
            final Type type = componentField.getType();
            ITTCN3Template componentTemplate = namedTemplate.getTemplate();
            componentTemplate.setMyGovernor(type);
            componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
            final boolean isOptional = componentField.isOptional();
            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) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) 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) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)16 Identifier (org.eclipse.titan.designer.AST.Identifier)11 IType (org.eclipse.titan.designer.AST.IType)10 Type (org.eclipse.titan.designer.AST.Type)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)9 HashMap (java.util.HashMap)5 IValue (org.eclipse.titan.designer.AST.IValue)5 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)4 Completeness_type (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Completeness_type)4 OmitValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)4 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Template_List)3 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2