Search in sources :

Example 41 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class FormalParameter method checkActualParameterByReference.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a reference parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param isTemplate
 *                true if the formal parameter is template, false
 *                otherwise
 * @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 checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
    final Type parameterType = parameter.getType();
    if (parameterType != null) {
        parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
        parameter.checkType(timestamp, type);
    }
    final Reference derivedReference = parameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
        parameter.checkDerivedReference(timestamp, type);
    }
    String expectedString;
    if (isTemplate) {
        expectedString = "template variable or template parameter";
    } else {
        expectedString = "variable or value parameter";
    }
    final ITTCN3Template template = parameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        reference.setUsedOnLeftHandSide();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        boolean assignmentTypeIsCorrect;
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL_IN:
                ((FormalParameter) assignment).useAsLValue(reference);
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_TEMP_IN:
                assignmentTypeIsCorrect = isTemplate;
                ((FormalParameter) assignment).useAsLValue(reference);
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            default:
                assignmentTypeIsCorrect = false;
                break;
        }
        if (assignmentTypeIsCorrect) {
            final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
            if (fieldType != null) {
                if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
                } else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
                }
                if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
                }
            }
        } else {
            reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
        }
        final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
        if (isTemplate && assignmentTypeIsCorrect) {
            TemplateRestriction.Restriction_type refdRestriction;
            switch(assignment.getAssignmentType()) {
                case A_VAR_TEMPLATE:
                    {
                        final Def_Var_Template temp = (Def_Var_Template) assignment;
                        refdRestriction = temp.getTemplateRestriction();
                        break;
                    }
                case A_PAR_TEMP_IN:
                case A_PAR_TEMP_OUT:
                case A_PAR_TEMP_INOUT:
                    {
                        final FormalParameter par = (FormalParameter) assignment;
                        refdRestriction = par.getTemplateRestriction();
                        break;
                    }
                default:
                    return returnActualParameter;
            }
            TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
            if (templateRestriction != refdRestriction) {
                final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
                final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
                if (preCallCheck || postCallCheck) {
                    final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
                    reference.getLocation().reportSemanticWarning(message);
                }
            }
            // written C++ code
            if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
                switch(myParameterList.getMyDefinition().getAssignmentType()) {
                    case A_EXT_FUNCTION:
                    case A_EXT_FUNCTION_RVAL:
                    case A_EXT_FUNCTION_RTEMP:
                        // here
                        break;
                    default:
                        break;
                }
            }
        }
        return returnActualParameter;
    }
    parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)

Example 42 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class FormalParameterList method checkCompatibility.

/**
 * Checks the compatibility of two formal parameter lists.
 * They are compatible if every parameter is compatible,
 *   has the same attribute, type, restriction and name.
 *
 * Please note that all errors will be reported to the location provided as the last parameter.
 * In themselves both formal parameter lists might be OK,
 *   so the error needs to be reported to the location where they are compared.
 *
 * @param timestamp the compilation timestamp
 * @param fpList the formal parameter list to be compared to the actual one.
 * @param callSite the location where errors should be reported to.
 */
public void checkCompatibility(final CompilationTimeStamp timestamp, final FormalParameterList fpList, final Location callSite) {
    if (parameters.size() != fpList.parameters.size()) {
        callSite.reportSemanticError(MessageFormat.format("{0} formal parameters was expected instead of {1}", parameters.size(), fpList.parameters.size()));
    }
    final int upperLimit = Math.min(parameters.size(), fpList.parameters.size());
    for (int i = 0; i < upperLimit; i++) {
        final FormalParameter typeParameter = parameters.get(i);
        final FormalParameter functionParameter = fpList.getParameterByIndex(i);
        if (typeParameter.getIsErroneous() || functionParameter.getIsErroneous()) {
            continue;
        }
        if (!typeParameter.getAssignmentType().semanticallyEquals(functionParameter.getAssignmentType())) {
            callSite.reportSemanticError(MessageFormat.format("The kind of the {0}th parameter is not the same: {1} was expected instead of {2}", i, typeParameter.getAssignmentName(), functionParameter.getAssignmentName()));
        }
        if (typeParameter.getAssignmentType() != Assignment_type.A_TIMER && functionParameter.getAssignmentType() != Assignment_type.A_TIMER) {
            final Type typeParameterType = typeParameter.getType(timestamp);
            final Type functionParameterType = functionParameter.getType(timestamp);
            if (!typeParameterType.isIdentical(timestamp, functionParameterType)) {
                callSite.reportSemanticError(MessageFormat.format("The type of the {0}th parameter is not the same: `{1}'' was expected instead of `{2}''", i, typeParameterType.getTypename(), functionParameterType.getTypename()));
            }
        }
        if (typeParameter.getTemplateRestriction() != functionParameter.getTemplateRestriction()) {
            callSite.reportSemanticError(MessageFormat.format("The template restriction of the {0}th parameter is not the same: `{1}'' was expected instead of `{2}''", i, typeParameter.getTemplateRestriction().getDisplayName(), functionParameter.getTemplateRestriction().getDisplayName()));
        }
        if (typeParameter.getIsLazy() != functionParameter.getIsLazy()) {
            callSite.reportSemanticError(MessageFormat.format("{0}th parameter @lazy-ness mismatch", i));
        }
        if (!typeParameter.getIdentifier().equals(functionParameter.getIdentifier())) {
            callSite.reportSemanticWarning(MessageFormat.format("The name of the {0}th parameter is not the same: `{1}'' was expected instead of `{2}''", i, typeParameter.getIdentifier().getDisplayName(), functionParameter.getIdentifier().getDisplayName()));
        }
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType)

Example 43 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class FormalParameterList method setGenName.

public void setGenName(final String prefix) {
    for (final FormalParameter parameter : parameters) {
        final String parameterName = parameter.getIdentifier().getName();
        if (!Assignment_type.A_TIMER.equals(parameter.getAssignmentType())) {
            final Type parameterType = parameter.getType(CompilationTimeStamp.getBaseTimestamp());
            if (parameterType != null) {
                parameterType.setGenName(prefix, parameterName);
            }
        }
        if (parameter.hasDefaultValue()) {
            final StringBuilder embeddedName = new StringBuilder(prefix);
            embeddedName.append('_');
            embeddedName.append(parameterName);
            embeddedName.append("_defval");
            final ActualParameter defaultValue = parameter.getDefaultValue();
            if (defaultValue instanceof Value_ActualParameter) {
                final IValue value = ((Value_ActualParameter) defaultValue).getValue();
                // value.setGenNamePrefix("const_");//currently does not need the prefix
                value.setGenNameRecursive(embeddedName.toString());
            } else if (defaultValue instanceof Template_ActualParameter) {
                final TemplateInstance instance = ((Template_ActualParameter) defaultValue).getTemplateInstance();
                final TTCN3Template template = instance.getTemplateBody();
                // template.setGenNamePrefix("template_");//currently does not need the prefix
                template.setGenNameRecursive(embeddedName.toString());
            }
        }
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 44 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Function method checkPrototype.

/**
 * Checks the prototype attribute set for this function definition.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
public void checkPrototype(final CompilationTimeStamp timestamp) {
    if (EncodingPrototype_type.NONE.equals(prototype)) {
        return;
    }
    // checking formal parameter list
    if (EncodingPrototype_type.CONVERT.equals(prototype)) {
        if (formalParList.getNofParameters() == 1) {
            final FormalParameter parameter = formalParList.getParameterByIndex(0);
            final Assignment_type assignmentType = parameter.getRealAssignmentType();
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(assignmentType)) {
                inputType = parameter.getType(timestamp);
            } else {
                parameter.getLocation().reportSemanticError(MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName()));
            }
        } else {
            formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName()));
        }
    } else if (formalParList.getNofParameters() == 2) {
        final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
        if (EncodingPrototype_type.SLIDING.equals(prototype)) {
            if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                final Type firstParameterType = firstParameter.getType(timestamp);
                final IType last = firstParameterType.getTypeRefdLast(timestamp);
                if (last.getIsErroneous(timestamp)) {
                    inputType = firstParameterType;
                } else {
                    switch(last.getTypetypeTtcn3()) {
                        case TYPE_OCTETSTRING:
                        case TYPE_CHARSTRING:
                            inputType = firstParameterType;
                            break;
                        default:
                            firstParameter.getLocation().reportSemanticError(MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName()));
                            break;
                    }
                }
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        } else {
            final Assignment_type assignmentType = firstParameter.getRealAssignmentType();
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(assignmentType) || Assignment_type.A_PAR_VAL.semanticallyEquals(assignmentType)) {
                inputType = firstParameter.getType(timestamp);
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        }
        final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
        if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
            outputType = secondParameter.getType(timestamp);
        } else {
            secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
        }
    } else {
        formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
    }
    // checking the return type
    if (EncodingPrototype_type.FAST.equals(prototype)) {
        if (returnType != null) {
            returnType.getLocation().reportSemanticError(MessageFormat.format("The function cannot have return type for attribute `prototype({0})''", prototype.getName()));
        }
    } else {
        if (returnType == null) {
            location.reportSemanticError(MessageFormat.format("The function must have a return type for attribute `prototype({0})''", prototype.getName()));
        } else {
            if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
                returnType.getLocation().reportSemanticError(MessageFormat.format("The function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
            }
            if (EncodingPrototype_type.CONVERT.equals(prototype)) {
                outputType = returnType;
            } else {
                final IType last = returnType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
                    returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
                }
            }
        }
    }
    // checking the runs on clause
    if (runsOnType != null && runsOnRef != null) {
        runsOnRef.getLocation().reportSemanticError(MessageFormat.format("The function cannot have `runs on'' clause for attribute `prototype({0})''", prototype.getName()));
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Example 45 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Template method checkModified.

/**
 * Checks the correctness of the modification of this template done to
 * the modified one if it has any.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle
 */
private void checkModified(final CompilationTimeStamp timestamp) {
    if (baseTemplate == null) {
        return;
    }
    final IType baseType = baseTemplate.getType(timestamp);
    if (!type.isCompatible(timestamp, baseType, null, null, null)) {
        type.getLocation().reportSemanticError(MessageFormat.format(IMCOMPATIBLEBASETYPE, baseTemplate.getFullName(), baseType.getFullName(), type.getFullName()));
    }
    final FormalParameterList baseParameters = baseTemplate.getFormalParameterList(timestamp);
    final int nofBaseFps = (baseParameters == null) ? 0 : baseParameters.getNofParameters();
    final int nofLocalFps = (formalParList == null) ? 0 : formalParList.getNofParameters();
    int minFps;
    if (nofLocalFps < nofBaseFps) {
        location.reportSemanticError(MessageFormat.format(FEWERFORMALPARAMETERS, baseTemplate.getFullName(), nofBaseFps, nofLocalFps));
        minFps = nofLocalFps;
    } else {
        minFps = nofBaseFps;
    }
    for (int i = 0; i < minFps; i++) {
        final FormalParameter baseFormalpar = baseParameters.getParameterByIndex(i);
        final FormalParameter localFormalpar = formalParList.getParameterByIndex(i);
        if (baseFormalpar.getAssignmentType() != localFormalpar.getAssignmentType()) {
            localFormalpar.getLocation().reportSemanticError(MessageFormat.format(DIFFERENTPARAMETERKINDS, baseTemplate.getFullName(), baseFormalpar.getAssignmentName(), localFormalpar.getAssignmentName()));
        }
        final Type baseFpType = baseFormalpar.getType(timestamp);
        final Type localFpType = localFormalpar.getType(timestamp);
        if (!baseFpType.isCompatible(timestamp, localFpType, null, null, null)) {
            if (!localFpType.getIsErroneous(timestamp) && !baseFpType.getIsErroneous(timestamp)) {
                localFpType.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEBASEPARAMETERTYPE, baseTemplate.getFullName(), baseFpType.getTypename(), localFpType.getTypename()));
            }
        }
        final Identifier baseFormalparId = baseFormalpar.getIdentifier();
        final Identifier localFormalparId = localFormalpar.getIdentifier();
        if (!baseFormalparId.equals(localFormalparId)) {
            localFormalpar.getLocation().reportSemanticError(MessageFormat.format(DIFFERENTPARAMETERNAMES, baseTemplate.getFullName(), baseFormalparId.getDisplayName(), localFormalparId.getDisplayName()));
        }
    }
    body.setBaseTemplate(baseTemplate.getTemplate(timestamp));
}
Also used : CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Type (org.eclipse.titan.designer.AST.Type)69 IType (org.eclipse.titan.designer.AST.IType)56 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IValue (org.eclipse.titan.designer.AST.IValue)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)12 HashMap (java.util.HashMap)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)9 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 Reference (org.eclipse.titan.designer.AST.Reference)8 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)8 Attribute_Type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type)7 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)6 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)6 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6