Search in sources :

Example 21 with FormalParameter

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter 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 22 with FormalParameter

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter 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 23 with FormalParameter

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.

the class Def_Template method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TEMPLATE, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TEMPLATE, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp, refChain);
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, true);
        withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp, refChain).getTypetype());
    }
    if (body == null) {
        return;
    }
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    body.setMyGovernor(type);
    realBody = body;
    // Needed in case of universal charstring templates
    if (body.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
        realBody = body.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
    // FIXME implement setting the pattern type, once
    // universal charstring pattern are supported.
    }
    if (formalParList != null) {
        formalParList.reset();
        formalParList.check(timestamp, getAssignmentType());
        if (isLocal()) {
            location.reportSemanticError(MessageFormat.format(PARAMETRIZED_LOCAL_TEMPLATE, getIdentifier()));
        }
    }
    final ITTCN3Template tempBody = type.checkThisTemplateRef(timestamp, realBody);
    checkDefault(timestamp);
    checkModified(timestamp);
    checkRecursiveDerivation(timestamp);
    tempBody.checkThisTemplateGeneric(timestamp, type, derivedReference != null, true, true, true, hasImplicitOmitAttribute(timestamp), null);
    checkErroneousAttributes(timestamp);
    final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(CIRCULAREMBEDDEDRECURSION, true);
    tempReferenceChain.add(this);
    tempBody.checkRecursions(timestamp, tempReferenceChain);
    tempReferenceChain.release();
    if (templateRestriction != TemplateRestriction.Restriction_type.TR_NONE) {
        generateRestrictionCheck = TemplateRestriction.check(timestamp, this, tempBody, null);
        if (formalParList != null && templateRestriction != TemplateRestriction.Restriction_type.TR_PRESENT) {
            final int nofFps = formalParList.getNofParameters();
            for (int i = 0; i < nofFps; i++) {
                final FormalParameter fp = formalParList.getParameterByIndex(i);
                // parameters
                if (fp.getAssignmentType() != Assignment.Assignment_type.A_PAR_TEMP_IN) {
                    continue;
                }
                final TemplateRestriction.Restriction_type fpTemplateRestriction = fp.getTemplateRestriction();
                switch(templateRestriction) {
                    case TR_VALUE:
                    case TR_OMIT:
                        switch(fpTemplateRestriction) {
                            case TR_VALUE:
                            case TR_OMIT:
                                // allowed
                                break;
                            case TR_PRESENT:
                                fp.getLocation().reportSemanticError(MessageFormat.format(WITHTEMPRESTNOTALLOWED, fpTemplateRestriction.getDisplayName()));
                                break;
                            case TR_NONE:
                                fp.getLocation().reportSemanticError(WITHOUTTEMPRESTNOTALLOWED);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    if (formalParList != null) {
        formalParList.setGenName(getGenName());
    }
    // body.setGenNamePrefix("template_");//currently does not need the prefix
    body.setGenNameRecursive(getGenName());
    body.setCodeSection(CodeSectionType.CS_POST_INIT);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction) IType(org.eclipse.titan.designer.AST.IType)

Example 24 with FormalParameter

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

Example 25 with FormalParameter

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.

the class Assignment_Statement method checkTemplateRestriction.

/**
 * Checks the template restriction on the assignment referenced on the left hand side.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 */
private void checkTemplateRestriction(final CompilationTimeStamp timestamp) {
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        return;
    }
    switch(ass.getAssignmentType()) {
        case A_VAR_TEMPLATE:
            templateRestriction = ((Def_Var_Template) ass).getTemplateRestriction();
            break;
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            templateRestriction = ((FormalParameter) ass).getTemplateRestriction();
            break;
        default:
            templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
            break;
    }
    templateRestriction = TemplateRestriction.getSubRestriction(templateRestriction, timestamp, reference);
    generateRestrictionCheck = TemplateRestriction.check(timestamp, (Definition) ass, template, reference);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Aggregations

FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)18 IType (org.eclipse.titan.designer.AST.IType)12 Assignment (org.eclipse.titan.designer.AST.Assignment)9 Type (org.eclipse.titan.designer.AST.Type)8 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)4 IValue (org.eclipse.titan.designer.AST.IValue)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Reference (org.eclipse.titan.designer.AST.Reference)4 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)4 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)4 HashMap (java.util.HashMap)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 FunctionReferenceDefinition (org.eclipse.titan.designer.AST.TTCN3.types.FunctionReferenceGenerator.FunctionReferenceDefinition)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Location (org.eclipse.titan.designer.AST.Location)2 Module (org.eclipse.titan.designer.AST.Module)2