Search in sources :

Example 1 with SignatureFormalParameterList

use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList in project titan.EclipsePlug-ins by eclipse.

the class VariableList_Parameter_Redirect method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Signature_Type signature, final boolean isOut) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    this.checkErroneous(timestamp);
    if (signature == null) {
        return;
    }
    final SignatureFormalParameterList parameterList = signature.getParameterList();
    if (parameterList.getNofParameters() == 0) {
        getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTPARAMETERS, signature.getTypename()));
        checkErroneous(timestamp);
        return;
    }
    final int nofVariableEntries = entries.getNofEntries();
    final int nofParameters = isOut ? parameterList.getNofOutParameters() : parameterList.getNofInParameters();
    if (nofVariableEntries != nofParameters) {
        getLocation().reportSemanticError(MessageFormat.format("Too {0} variable entries compared to the number of {1}/inout parameters in signature `{2}'': {3} was expected instead of {4}", (nofVariableEntries > nofParameters) ? "many" : "few", isOut ? "out" : "in", signature.getTypename(), nofParameters, nofVariableEntries));
    }
    for (int i = 0; i < nofVariableEntries; i++) {
        final Variable_Entry entry = entries.getEntryByIndex(i);
        if (i < nofParameters) {
            final SignatureFormalParameter parameter = isOut ? parameterList.getOutParameterByIndex(i) : parameterList.getInParameterByIndex(i);
            checkVariableReference(timestamp, entry.getReference(), parameter.getType());
        } else {
            checkVariableReference(timestamp, entry.getReference(), null);
        }
    }
    lastTimeChecked = timestamp;
}
Also used : SignatureFormalParameterList(org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList) SignatureFormalParameter(org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter)

Example 2 with SignatureFormalParameterList

use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList in project titan.EclipsePlug-ins by eclipse.

the class AssignmentList_Parameter_Redirect method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Signature_Type signature, final boolean isOut) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    final SignatureFormalParameterList parameterList = signature.getParameterList();
    if (parameterList.getNofParameters() == 0) {
        getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTPARAMETERS, signature.getTypename()));
        checkErroneous(timestamp);
        return;
    }
    boolean errorFlag = false;
    final HashMap<String, Parameter_Assignment> parameterMap = new HashMap<String, Parameter_Assignment>();
    for (int i = 0, size = assignments.getNofParameterAssignments(); i < size; i++) {
        final Parameter_Assignment assignment = assignments.getParameterAssignmentByIndex(i);
        final String name = assignment.getIdentifier().getName();
        if (parameterMap.containsKey(name)) {
            assignment.getLocation().reportSemanticError(MessageFormat.format("Duplicate redirect for parameter `{0}''", assignment.getIdentifier().getDisplayName()));
            final Location otherLocation = parameterMap.get(name).getLocation();
            otherLocation.reportSemanticWarning(MessageFormat.format("A variable entry for parameter `{0}'' is already given here", assignment.getIdentifier().getDisplayName()));
            errorFlag = true;
        } else {
            parameterMap.put(name, assignment);
        }
        if (parameterList.hasParameterWithName(name)) {
            final SignatureFormalParameter parameterTemplate = parameterList.getParameterByName(name);
            if (isOut) {
                if (SignatureFormalParameter.ParamaterDirection.PARAM_IN == parameterTemplate.getDirection()) {
                    final String message = MessageFormat.format("Parameter `{0}'' of signature `{1}'' has `in'' direction", assignment.getIdentifier().getDisplayName(), signature.getTypename());
                    assignment.getLocation().reportSemanticError(message);
                    errorFlag = true;
                }
            } else {
                if (SignatureFormalParameter.ParamaterDirection.PARAM_OUT == parameterTemplate.getDirection()) {
                    final String message = MessageFormat.format("Parameter `{0}'' of signature `{1}'' has `out'' direction", assignment.getIdentifier().getDisplayName(), signature.getTypename());
                    assignment.getLocation().reportSemanticError(message);
                    errorFlag = true;
                }
            }
            checkVariableReference(timestamp, assignment.getReference(), parameterTemplate.getType());
        } else {
            assignment.getLocation().reportSemanticError(MessageFormat.format("Signature `{0}'' does not have parameter named `{1}''", signature.getTypename(), assignment.getIdentifier().getDisplayName()));
            errorFlag = true;
            checkVariableReference(timestamp, assignment.getReference(), null);
        }
    }
    if (!errorFlag) {
        // converting the AssignmentList to VariableList
        final Variable_Entries variableEntries = new Variable_Entries();
        final int upperLimit = isOut ? parameterList.getNofOutParameters() : parameterList.getNofInParameters();
        for (int i = 0; i < upperLimit; i++) {
            final SignatureFormalParameter parameter = isOut ? parameterList.getOutParameterByIndex(i) : parameterList.getInParameterByIndex(i);
            final String name = parameter.getIdentifier().getName();
            if (parameterMap.containsKey(name)) {
                variableEntries.add(new Variable_Entry(parameterMap.get(name).getReference()));
            } else {
                variableEntries.add(new Variable_Entry());
            }
        }
    }
    lastTimeChecked = timestamp;
}
Also used : HashMap(java.util.HashMap) SignatureFormalParameterList(org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList) SignatureFormalParameter(org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

SignatureFormalParameter (org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter)2 SignatureFormalParameterList (org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList)2 HashMap (java.util.HashMap)1 Location (org.eclipse.titan.designer.AST.Location)1