Search in sources :

Example 76 with ITTCN3Template

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

the class SuperfluousTemplate method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof TemplateInstance) {
        template = (TemplateInstance) node;
        final ITTCN3Template body = template.getTemplateBody();
        if (body instanceof Any_Value_Template || body instanceof AnyOrOmit_Template) {
            final Type type = template.getType();
            if (type == null) {
                // port.receive(?) or port.receive(*)
                receivesAny = true;
            } else if (receivableType != null && type.isIdentical(CompilationTimeStamp.getBaseTimestamp(), receivableType)) {
                // e.g. port.receive(integer:?)
                receivesAllOfType = true;
            }
        }
        // We don't want to investigate nested templates
        return V_SKIP;
    }
    return V_CONTINUE;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Any_Value_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Any_Value_Template) AnyOrOmit_Template(org.eclipse.titan.designer.AST.TTCN3.templates.AnyOrOmit_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 77 with ITTCN3Template

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

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

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