Search in sources :

Example 6 with ArrayDimensions

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions in project titan.EclipsePlug-ins by eclipse.

the class LogArgument method checkReference.

/**
 * Does the semantic checking of the log argument. Once it was
 * determined that it is a reference.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference contained in the log argument.
 */
private void checkReference(final CompilationTimeStamp timestamp, final Reference reference) {
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null || assignment.getIsErroneous()) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            {
                reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_CONST:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    if (assignment instanceof Def_Const) {
                        ((Def_Const) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
                    } else {
                        ((Value_Assignment) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
                    }
                    chain.release();
                }
                break;
            }
        case A_TEMPLATE:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    ((Def_Template) assignment).getTemplate(timestamp).getReferencedSubTemplate(timestamp, reference, chain);
                    chain.release();
                }
                break;
            }
        case A_MODULEPAR_TEMPLATE:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_VAR_TEMPLATE:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_PORT:
            {
                final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
                    isErroneous = true;
                }
                break;
            }
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
                    isErroneous = true;
                }
                break;
            }
        case A_PAR_TIMER:
        case A_PAR_PORT:
            if (reference.getSubreferences().size() > 1) {
                getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
                isErroneous = true;
            }
            break;
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was ecpected instead of a call of {0}, which does not have a return type", assignment.getDescription()));
            isErroneous = true;
            break;
        default:
            getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was expected instead of {0}", assignment.getDescription()));
            isErroneous = true;
            break;
    }
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with ArrayDimensions

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

Example 8 with ArrayDimensions

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions in project titan.EclipsePlug-ins by eclipse.

the class TimerReadExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
                }
                break;
            }
        case A_PAR_TIMER:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
            }
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR2, assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, true, false);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Example 9 with ArrayDimensions

use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions in project titan.EclipsePlug-ins by eclipse.

the class Port_Type method generateCodePort.

/**
 * Generate the classes to represent a port array.
 *
 * @param aData only used to update imports if needed
 * @param source where the source code should be generated
 * @param dimensions the dimensions of the array to use.
 */
public void generateCodePort(final JavaGenData aData, final StringBuilder source, final ArrayDimensions dimensions) {
    String className = getGenNameValue(aData, source, myScope);
    String elementName;
    for (int i = 0; i < dimensions.size(); i++) {
        final ArrayDimension dimension = dimensions.get(i);
        if (i == dimensions.size() - 1) {
            elementName = getGenNameOwn();
        } else {
            elementName = aData.getTemporaryVariableName();
        }
        source.append(MessageFormat.format("public static class {0} extends TitanPortArray<{1}> '{'\n", className, elementName));
        source.append(MessageFormat.format("public {0}() '{'\n", className));
        source.append(MessageFormat.format("super({0}.class, {1} , {2});\n", elementName, dimension.getSize(), dimension.getOffset()));
        source.append("}\n");
        source.append(MessageFormat.format("public {0}({0} otherValue) '{'\n", className));
        source.append("super(otherValue);\n");
        source.append("}\n");
        source.append("}\n\n");
        className = elementName;
    }
    aData.addBuiltinTypeImport("TitanPortArray");
}
Also used : ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)8 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 IType (org.eclipse.titan.designer.AST.IType)6 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 Reference (org.eclipse.titan.designer.AST.Reference)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Def_Port (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port)2 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)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 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)1 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)1