Search in sources :

Example 6 with Def_Port

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

the class FormalParameter method checkActualParameterPort.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a port parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @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 checkActualParameterPort(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    final Type parameterType = actualParameter.getType();
    if (parameterType != null) {
        parameterType.getLocation().reportSemanticWarning("Explicit type specification is useless for a port parameter");
        actualParameter.checkType(timestamp, type);
    }
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError("An in-line modified temlate cannot be used as port parameter");
        actualParameter.checkDerivedReference(timestamp, type);
    }
    final ITTCN3Template parameterTemplate = actualParameter.getTemplateBody();
    if (!(parameterTemplate instanceof SpecificValue_Template) || !((SpecificValue_Template) parameterTemplate).isReference()) {
        actualParameter.getLocation().reportSemanticError("Reference to a port or port parameter was expected for a port parameter");
        final ActualParameter temp = new Value_ActualParameter(null);
        temp.setIsErroneous();
        return temp;
    }
    final Reference reference = ((SpecificValue_Template) parameterTemplate).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        final ActualParameter temp = new Value_ActualParameter(null);
        temp.setIsErroneous();
        return temp;
    }
    Type referredType;
    switch(assignment.getAssignmentType()) {
        case A_PORT:
            final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
            if (dimensions != null) {
                dimensions.checkIndices(timestamp, reference, "port", false, expectedValue);
            } else if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
            }
            referredType = ((Def_Port) assignment).getType(timestamp);
            break;
        case A_PAR_PORT:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR3, assignment.getDescription()));
            }
            referredType = ((FormalParameter) assignment).getType(timestamp);
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(PORTEXPECTED, assignment.getDescription()));
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
    }
    if (referredType != null && type != null && !type.isIdentical(timestamp, referredType)) {
        reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename(), referredType.getTypename()));
    }
    return new Referenced_ActualParameter(reference);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) 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) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)5 IType (org.eclipse.titan.designer.AST.IType)5 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)5 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Reference (org.eclipse.titan.designer.AST.Reference)3 Def_Port (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IValue (org.eclipse.titan.designer.AST.IValue)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)2 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)2 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)2 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)2 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 Assignment_type (org.eclipse.titan.designer.AST.Assignment.Assignment_type)1 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)1 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)1