Search in sources :

Example 6 with Def_Var

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

the class TypenameInDef method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
        return;
    }
    final Definition s = (Definition) node;
    check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Also used : Def_ExternalConst(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 7 with Def_Var

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

the class Parameter_Redirect method checkVariableReference.

/**
 * Check whether the reference points to a variable of the provided
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference to check
 * @param type
 *                the type the parameter is expected to have.
 */
public final void checkVariableReference(final CompilationTimeStamp timestamp, final Reference reference, final IType type) {
    if (reference == null) {
        return;
    }
    final IType variableType = reference.checkVariableReference(timestamp);
    if (type != null && variableType != null && !type.isIdentical(timestamp, variableType)) {
        final String message = MessageFormat.format("Type mismatch in parameter redirect: A variable of type `{0}'' was expected instead of `{1}''", type.getTypename(), variableType.getTypename());
        reference.getLocation().reportSemanticError(message);
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) IType(org.eclipse.titan.designer.AST.IType)

Example 8 with Def_Var

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

the class Port_Utility method checkValueRedirect.

/**
 * Calculates the type of a variable when it was to be used as a value
 * redirect target.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param redirectValue
 *                the reference to which the redirection is targeted
 * @param type
 *                the expected type of the value redirection.
 *
 * @return the the type of a variable referenced when it was to be used
 *         as a value redirection target.
 */
public static IType checkValueRedirect(final CompilationTimeStamp timestamp, final Reference redirectValue, final IType type) {
    if (redirectValue == null) {
        return null;
    }
    final IType variableType = redirectValue.checkVariableReference(timestamp);
    if (type != null && variableType != null && !type.isCompatible(timestamp, variableType, null, null, null)) {
        redirectValue.getLocation().reportSemanticError(MessageFormat.format(VALUEREDIRECTTYPEMISSMATCH, type.getTypename(), variableType.getTypename()));
    }
    final Assignment assignment = redirectValue.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                break;
            default:
                break;
        }
    }
    return variableType;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with Def_Var

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

the class FormalParameter method checkActualParameterByReference.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a reference parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param isTemplate
 *                true if the formal parameter is template, false
 *                otherwise
 * @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 checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
    final Type parameterType = parameter.getType();
    if (parameterType != null) {
        parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
        parameter.checkType(timestamp, type);
    }
    final Reference derivedReference = parameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
        parameter.checkDerivedReference(timestamp, type);
    }
    String expectedString;
    if (isTemplate) {
        expectedString = "template variable or template parameter";
    } else {
        expectedString = "variable or value parameter";
    }
    final ITTCN3Template template = parameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        reference.setUsedOnLeftHandSide();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        boolean assignmentTypeIsCorrect;
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL_IN:
                ((FormalParameter) assignment).useAsLValue(reference);
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_TEMP_IN:
                assignmentTypeIsCorrect = isTemplate;
                ((FormalParameter) assignment).useAsLValue(reference);
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            default:
                assignmentTypeIsCorrect = false;
                break;
        }
        if (assignmentTypeIsCorrect) {
            final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
            if (fieldType != null) {
                if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
                } else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
                }
                if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
                }
            }
        } else {
            reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
        }
        final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
        if (isTemplate && assignmentTypeIsCorrect) {
            TemplateRestriction.Restriction_type refdRestriction;
            switch(assignment.getAssignmentType()) {
                case A_VAR_TEMPLATE:
                    {
                        final Def_Var_Template temp = (Def_Var_Template) assignment;
                        refdRestriction = temp.getTemplateRestriction();
                        break;
                    }
                case A_PAR_TEMP_IN:
                case A_PAR_TEMP_OUT:
                case A_PAR_TEMP_INOUT:
                    {
                        final FormalParameter par = (FormalParameter) assignment;
                        refdRestriction = par.getTemplateRestriction();
                        break;
                    }
                default:
                    return returnActualParameter;
            }
            TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
            if (templateRestriction != refdRestriction) {
                final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
                final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
                if (preCallCheck || postCallCheck) {
                    final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
                    reference.getLocation().reportSemanticWarning(message);
                }
            }
            // written C++ code
            if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
                switch(myParameterList.getMyDefinition().getAssignmentType()) {
                    case A_EXT_FUNCTION:
                    case A_EXT_FUNCTION_RVAL:
                    case A_EXT_FUNCTION_RTEMP:
                        // here
                        break;
                    default:
                        break;
                }
            }
        }
        return returnActualParameter;
    }
    parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IType(org.eclipse.titan.designer.AST.IType) 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) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)

Aggregations

Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 IType (org.eclipse.titan.designer.AST.IType)5 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)4 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)4 Reference (org.eclipse.titan.designer.AST.Reference)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Scope (org.eclipse.titan.designer.AST.Scope)1 TemplateRestriction (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)1 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)1 Def_ExternalConst (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst)1