Search in sources :

Example 1 with ValueList_Template

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

the class Assignment_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isErroneous = false;
    selfReference = false;
    templateRestriction = Restriction_type.TR_NONE;
    generateRestrictionCheck = false;
    if (reference == null) {
        return;
    }
    reference.setUsedOnLeftHandSide();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null || assignment.getIsErroneous()) {
        isErroneous = true;
        return;
    }
    if (template == null) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_PAR_VAL_IN:
            ((FormalParameter) assignment).useAsLValue(reference);
            if (template.isValue(timestamp)) {
                // TODO: isValue should be checked within the previous line! This is double check!
                final IValue temporalValue = template.getValue();
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                // TODO: convert (x) to x to compilation!
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_VAL:
            ((FormalParameter) assignment).setWritten();
            if (template.isValue(timestamp)) {
                // TODO: isValue should be checked within the previous line! This is double check!
                final IValue temporalValue = template.getValue();
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                // TODO: convert (x) to x to compilation!
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        // break
        case A_VAR:
            ((Def_Var) assignment).setWritten();
            if (template.getIsErroneous(timestamp)) {
                return;
            }
            final IValue temporalValue = template.getValue();
            if (temporalValue != null) {
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        case A_PAR_TEMP_IN:
            ((FormalParameter) assignment).useAsLValue(reference);
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            ((FormalParameter) assignment).setWritten();
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        case A_VAR_TEMPLATE:
            ((Def_Var_Template) assignment).setWritten();
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(VARIABLEREFERENCEEXPECTED, assignment.getAssignmentName()));
            reference.setIsErroneous(true);
            isErroneous = true;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) IValue(org.eclipse.titan.designer.AST.IValue) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 2 with ValueList_Template

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

the class Integer_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    switch(template.getTemplatetype()) {
        case VALUE_RANGE:
            final ValueRange range = ((Value_Range_Template) template).getValueRange();
            final IValue lower = checkBoundary(timestamp, range.getMin(), BOUNDARY_TYPE.LOWER);
            final IValue upper = checkBoundary(timestamp, range.getMax(), BOUNDARY_TYPE.UPPER);
            range.setTypeType(getTypetypeTtcn3());
            // Template references are not checked.
            if (lower != null && Value.Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && upper != null && Value.Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
                if (!getIsErroneous(timestamp) && ((Integer_Value) lower).getValue() > ((Integer_Value) upper).getValue()) {
                    template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
                    template.setIsErroneous(true);
                }
            }
            // TODO some checks are still missing
            break;
        case VALUE_LIST:
            final ValueList_Template temp = (ValueList_Template) template;
            for (int i = 0; i < temp.getNofTemplates(); i++) {
                final TTCN3Template tmp = temp.getTemplateByIndex(i);
                selfReference |= checkThisTemplate(timestamp, tmp, isModified, implicitOmit, lhs);
            }
            break;
        case ANY_OR_OMIT:
        case ANY_VALUE:
            // Allowed
            break;
        default:
            template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
            template.setIsErroneous(true);
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
        template.setIsErroneous(true);
    }
    return selfReference;
}
Also used : ValueRange(org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Value_Range_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Value_Range_Template) ValueList_Template(org.eclipse.titan.designer.AST.TTCN3.templates.ValueList_Template)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)2 Assignment (org.eclipse.titan.designer.AST.Assignment)1 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)1 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)1 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)1 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)1 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)1 ValueList_Template (org.eclipse.titan.designer.AST.TTCN3.templates.ValueList_Template)1 ValueRange (org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange)1 Value_Range_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Value_Range_Template)1 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)1