Search in sources :

Example 1 with NotUsed_Template

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

the class FormalParameterList method collateLazyAndNonLazyActualParameters.

/**
 * Read the parsed actual parameters, and collate the lazy and non-lazy actual parameters
 * according to their associated formal parameters.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parsedParameters
 *                the parsed actual parameters (may contain named, and unnamed parts too).
 * @param actualLazyParameters
 *                the list of actual lazy parameters returned for later usage.
 * @param actualNonLazyParameters
 *                the list of actual non lazy parameters returned for later usage.
 */
public final void collateLazyAndNonLazyActualParameters(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualLazyParameters, final ActualParameterList actualNonLazyParameters) {
    final TemplateInstances unnamed = parsedParameters.getInstances();
    final NamedParameters named = parsedParameters.getNamedParameters();
    int nofLocated = unnamed.getNofTis();
    final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
    }
    final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
    for (int i = 0, size = named.getNofParams(); i < size; i++) {
        final NamedParameter namedParameter = named.getParamByIndex(i);
        final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
        final int isAt = formalParameterMap.get(formalParameter);
        for (; nofLocated < isAt; nofLocated++) {
            final NotUsed_Template temp = new NotUsed_Template();
            if (!parameters.get(nofLocated).hasDefaultValue()) {
                temp.setIsErroneous(true);
            }
            final TemplateInstance instance = new TemplateInstance(null, null, temp);
            instance.setLocation(parsedParameters.getLocation());
            finalUnnamed.addTemplateInstance(instance);
        }
        finalUnnamed.addTemplateInstance(namedParameter.getInstance());
        nofLocated++;
    }
    finalUnnamed.setLocation(parsedParameters.getLocation());
    final int upperLimit = (finalUnnamed.getNofTis() < parameters.size()) ? finalUnnamed.getNofTis() : parameters.size();
    for (int i = 0; i < upperLimit; i++) {
        final TemplateInstance instance = finalUnnamed.getInstanceByIndex(i);
        final FormalParameter formalParameter = parameters.get(i);
        if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
            final ActualParameter defaultValue = formalParameter.getDefaultValue();
            final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
            if (defaultValue != null && !defaultValue.getIsErroneous()) {
                temp.setLocation(defaultValue.getLocation());
            }
            if (formalParameter.getIsLazy()) {
                actualLazyParameters.addParameter(temp);
            } else {
                actualNonLazyParameters.addParameter(temp);
            }
        } else {
            final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            actualParameter.setLocation(instance.getLocation());
            if (formalParameter.getIsLazy()) {
                actualLazyParameters.addParameter(actualParameter);
            } else {
                actualNonLazyParameters.addParameter(actualParameter);
            }
        }
    }
    for (int i = upperLimit; i < parameters.size(); i++) {
        final FormalParameter formalParameter = parameters.get(i);
        final ActualParameter defaultValue = formalParameter.getDefaultValue();
        final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
        if (defaultValue != null && !defaultValue.getIsErroneous()) {
            temp.setLocation(defaultValue.getLocation());
        }
        if (formalParameter.getIsLazy()) {
            actualLazyParameters.addParameter(temp);
        } else {
            actualNonLazyParameters.addParameter(temp);
        }
    }
}
Also used : NamedParameters(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters) HashMap(java.util.HashMap) NamedParameter(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter) TemplateInstances(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances) NotUsed_Template(org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 2 with NotUsed_Template

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

the class FormalParameterList method checkActualParameterList.

/**
 * Check if a list of parsed actual parameters is semantically correct
 * according to a list of formal parameters (the called entity).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parsedParameters
 *                the parsed actual parameters (may contain named, and
 *                unnamed parts too).
 * @param actualParameters
 *                the list of actual parameters returned for later
 *                usage.
 *
 * @return true if a semantic error was found, false otherwise
 */
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
    parsedParameters.setFormalParList(this);
    checkUniqueness(timestamp);
    boolean isErroneous = false;
    final TemplateInstances unnamed = parsedParameters.getInstances();
    final NamedParameters named = parsedParameters.getNamedParameters();
    int nofLocated = unnamed.getNofTis();
    final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
    }
    final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
    for (int i = 0, size = named.getNofParams(); i < size; i++) {
        final NamedParameter namedParameter = named.getParamByIndex(i);
        if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
            final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
            final int isAt = formalParameterMap.get(formalParameter);
            if (isAt >= nofLocated) {
                for (; nofLocated < isAt; nofLocated++) {
                    final NotUsed_Template temp = new NotUsed_Template();
                    if (!parameters.get(nofLocated).hasDefaultValue()) {
                        temp.setIsErroneous(true);
                    }
                    final TemplateInstance instance = new TemplateInstance(null, null, temp);
                    instance.setLocation(parsedParameters.getLocation());
                    finalUnnamed.addTemplateInstance(instance);
                }
                finalUnnamed.addTemplateInstance(namedParameter.getInstance());
                nofLocated++;
            } else {
                isErroneous = true;
                if (isAt >= unnamed.getNofTis()) {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
                } else {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
                }
            }
        } else {
            String name;
            switch(myDefinition.getAssignmentType()) {
                case A_TYPE:
                    switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
                        case TYPE_FUNCTION:
                            name = "Function reference";
                            break;
                        case TYPE_ALTSTEP:
                            name = "Altstep reference";
                            break;
                        case TYPE_TESTCASE:
                            name = "Testcase reference";
                            break;
                        default:
                            name = "";
                            break;
                    }
                    break;
                default:
                    name = myDefinition.getAssignmentName();
                    break;
            }
            isErroneous = true;
            namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
        }
    }
    if (isErroneous) {
        return false;
    }
    finalUnnamed.setLocation(parsedParameters.getLocation());
    return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
Also used : NamedParameters(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters) HashMap(java.util.HashMap) NamedParameter(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter) TemplateInstances(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances) NotUsed_Template(org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Aggregations

HashMap (java.util.HashMap)2 NamedParameter (org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter)2 NamedParameters (org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters)2 NotUsed_Template (org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template)2 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)2 TemplateInstances (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances)2