Search in sources :

Example 56 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class All_From_Template method getNofTemplatesNotAnyornone.

/**
 * Calculates the number of list members which are not the any or none
 * symbol.
 *
 * @return the number calculated.
 */
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
    int result = 0;
    if (allFrom == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    if (!((SpecificValue_Template) allFrom).isReference()) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    // isReference branch:
    final Reference reference = ((SpecificValue_Template) allFrom).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        allFrom.getLocation().reportSemanticError("Assignment not found");
        allFrom.setIsErroneous(true);
        return result;
    }
    ITTCN3Template body = null;
    switch(assignment.getAssignmentType()) {
        case A_TEMPLATE:
            body = ((Def_Template) assignment).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            body = ((Def_Var_Template) assignment).getInitialValue();
            break;
        case A_CONST:
            final IValue value = ((Def_Const) assignment).getValue();
            return getNofValues(value, timestamp);
        case A_MODULEPAR:
            final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
            return getNofValues(mvalue, timestamp);
        case A_MODULEPAR_TEMPLATE:
            body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
            break;
        default:
            return result;
    }
    if (body == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
        allFrom.setIsErroneous(true);
        return result;
    }
    result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)

Example 57 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class LogArgument method check.

/**
 * Does the semantic checking of the log argument. This is the main
 * entry point.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
public void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (templateInstance == null) {
        return;
    }
    lastTimeChecked = timestamp;
    isErroneous = false;
    ITTCN3Template template = templateInstance.getTemplateBody();
    template = template.setLoweridToReference(timestamp);
    if (template.getIsErroneous(timestamp)) {
        isErroneous = true;
        return;
    }
    if (templateInstance.getType() == null && templateInstance.getDerivedReference() == null && template.isValue(timestamp)) {
        final IValue value = template.getValue();
        final IType gov = template.getMyGovernor();
        if (gov != null) {
            value.setMyGovernor(gov);
        }
        checkValue(timestamp, value);
    } else {
        IType governor = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
        if (governor == null) {
            governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
        }
        if (governor == null) {
            if (!template.getIsErroneous(timestamp)) {
                getLocation().reportSemanticError("Cannot determine the type of the argument");
            }
            isErroneous = true;
        } else {
            internalLogArgument = new TemplateInstance_InternalLogArgument(templateInstance);
            templateInstance.check(timestamp, governor);
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) IType(org.eclipse.titan.designer.AST.IType)

Example 58 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template 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 59 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class FormalParameter method checkActualParameterValue.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a value 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 made from the provided parameter.
 */
private ActualParameter checkActualParameterValue(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    actualParameter.checkType(timestamp, type);
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        actualParameter.checkDerivedReference(timestamp, type);
    }
    final ITTCN3Template template = actualParameter.getTemplateBody();
    if (type != null) {
        final IValue value = template.getValue();
        if (value != null) {
            value.setMyGovernor(type);
            final IValue temp = type.checkThisValueRef(timestamp, value);
            if (!Value_type.NOTUSED_VALUE.equals(temp.getValuetype())) {
                type.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(expectedValue, false, false, true, false, false));
            }
            return new Value_ActualParameter(temp);
        }
    }
    actualParameter.getLocation().reportSemanticError(MessageFormat.format(SPECIFICVALUEXPECTED, getAssignmentName()));
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 60 with ITTCN3Template

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

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)67 IType (org.eclipse.titan.designer.AST.IType)42 IValue (org.eclipse.titan.designer.AST.IValue)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)19 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)19 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Type (org.eclipse.titan.designer.AST.Type)13 ISubReference (org.eclipse.titan.designer.AST.ISubReference)12 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)12 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)12 Reference (org.eclipse.titan.designer.AST.Reference)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)6 HashMap (java.util.HashMap)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)5