Search in sources :

Example 1 with ActualParameterList

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

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

Example 3 with ActualParameterList

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

the class Activate_Referenced_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    if (dereferredValue == null) {
        setIsErroneous();
        return;
    }
    dereferredValue.setLoweridToReference(timestamp);
    IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null || type.getIsErroneous(timestamp)) {
        setIsErroneous();
        return;
    }
    if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
        dereferredValue.getLocation().reportSemanticError(MessageFormat.format(ALTSTEPEXPECTED, type.getTypename()));
        setIsErroneous();
        return;
    }
    if (((Altstep_Type) type).isRunsOnSelf()) {
        dereferredValue.getLocation().reportSemanticError(RUNONSELFERROR);
        setIsErroneous();
        return;
    }
    if (myStatementBlock != null) {
        myStatementBlock.checkRunsOnScope(timestamp, type, this, STATEMENT_NAME);
    }
    actualParameterList2 = new ActualParameterList();
    final FormalParameterList formalParameterList = ((Altstep_Type) type).getFormalParameters();
    if (formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameterList2)) {
        setIsErroneous();
        return;
    }
    actualParameterList2.setFullNameParent(this);
    actualParameterList2.setMyScope(getMyScope());
    if (!formalParameterList.checkActivateArgument(timestamp, actualParameterList2, getFullName())) {
        setIsErroneous();
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with ActualParameterList

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

the class Invoke_Template method checkInvoke.

public void checkInvoke(final CompilationTimeStamp timestamp) {
    if (getIsErroneous(timestamp) || actualParameterList == null || value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null) {
        if (!value.getIsErroneous(timestamp)) {
            value.getLocation().reportSemanticError("A value of type function was expected in the argument");
        }
        setIsErroneous(true);
        return;
    }
    if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument instead of `{0}''", type.getTypename()));
        setIsErroneous(true);
        return;
    }
    if (myScope == null) {
        return;
    }
    myScope.checkRunsOnScope(timestamp, type, this, "call");
    final FormalParameterList formalParameterList = ((Function_Type) type).getFormalParameters();
    actualParameter_list = new ActualParameterList();
    if (!formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameter_list)) {
        actualParameter_list.setFullNameParent(this);
        actualParameter_list.setMyScope(getMyScope());
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with ActualParameterList

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

the class Invoke_Template method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (lengthRestriction != null) {
        lengthRestriction.updateSyntax(reparser, false);
        reparser.updateLocation(lengthRestriction.getLocation());
    }
    if (baseTemplate instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
        reparser.updateLocation(baseTemplate.getLocation());
    } else if (baseTemplate != null) {
        throw new ReParseException();
    }
    if (value != null) {
        value.updateSyntax(reparser, false);
        reparser.updateLocation(value.getLocation());
    }
    if (actualParameterList != null) {
        actualParameterList.updateSyntax(reparser, false);
        reparser.updateLocation(actualParameterList.getLocation());
    }
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Aggregations

ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)18 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)13 IType (org.eclipse.titan.designer.AST.IType)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 IValue (org.eclipse.titan.designer.AST.IValue)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)3 Altstep_Type (org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type)3 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)3 HashMap (java.util.HashMap)2 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)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 TemplateInstances (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1