Search in sources :

Example 16 with ITTCN3Template

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

the class RegexpExpression 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) {
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    setIsErroneous(false);
    if (templateInstance1 != null) {
        IType governor1 = templateInstance1.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template template = templateInstance1.getTemplateBody();
        if (governor1 == null) {
            template = template.setLoweridToReference(timestamp);
            governor1 = template.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor1 == null) {
            if (!template.getIsErroneous(timestamp)) {
                templateInstance1.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance1, governor1, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        final ITTCN3Template temp = template.setLoweridToReference(timestamp);
        temp.checkSpecificValue(timestamp, false);
        switch(governor1.getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (templateInstance2 != null) {
        IType governor2 = templateInstance2.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template temp = templateInstance2.getTemplateBody();
        if (governor2 == null) {
            temp = temp.setLoweridToReference(timestamp);
            governor2 = temp.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor2 == null) {
            if (!temp.getIsErroneous(timestamp)) {
                templateInstance2.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance2, governor2, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        switch(governor2.getTypeRefdLast(timestamp).getTypetype()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        final IValue temp = value3.setLoweridToReference(timestamp);
        final Type_type tempType3 = temp.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = temp.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
                    if (((Integer_Value) last3).isNative()) {
                        final long i = ((Integer_Value) last3).getValue();
                        if (i < 0) {
                            value3.getLocation().reportSemanticError(OPERANDERROR4);
                            setIsErroneous(true);
                        }
                    } else {
                        value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR5, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR3);
                setIsErroneous(true);
                break;
        }
    }
// TODO add regexp specific checks once patterns become
// supported
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 17 with ITTCN3Template

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

the class ReplaceExpression method getExpressionReturntype.

@Override
public /**
 * {@inheritDoc}
 */
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IValue last = getValueRefdLast(timestamp, expectedValue, null);
    if (last == null || templateInstance1 == null) {
        return Type_type.TYPE_UNDEFINED;
    }
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return Type_type.TYPE_UNDEFINED;
    }
    final ITTCN3Template template = templateInstance1.getTemplateBody().setLoweridToReference(timestamp);
    final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
        case TYPE_SET_OF:
        case TYPE_SEQUENCE_OF:
            return tempType;
        case TYPE_UNDEFINED:
            return tempType;
        default:
            setIsErroneous(true);
            return Type_type.TYPE_UNDEFINED;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 18 with ITTCN3Template

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

the class IsValueExpression 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 referenceChain
 *                the referencechain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (governor == null) {
        template = template.setLoweridToReference(timestamp);
        governor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (governor == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance.getLocation().reportSemanticError(OPERANDERROR);
        }
        setIsErroneous(true);
    } else {
        templateInstance.getExpressionReturntype(timestamp, internalExpectation);
        checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 19 with ITTCN3Template

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

the class IsValueExpression method checkExpressionTemplateInstance.

/**
 * Checks if the templateinstance parameter (which is a parameter of the
 * expression parameter) is actually a constant or static value or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expression
 *                the expression to report the possible errors to.
 * @param instance
 *                the template instance parameter of the expression to
 *                be checked.
 * @param type
 *                the type against which the template instance shall be
 *                checked.
 * @param referenceChain
 *                the referencechain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
public static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
    Expected_Value_type internalExpectation;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectation = expectedValue;
    }
    instance.check(timestamp, type);
    if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
        if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
            instance.getLocation().reportSemanticError(CONSTEXPECTED1);
        } else {
            instance.getLocation().reportSemanticError(STATICEXPECTED1);
        }
        expression.setIsErroneous(true);
    }
    ITTCN3Template template = instance.getTemplateBody();
    if (template.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    switch(template.getTemplatetype()) {
        case TEMPLATE_REFD:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
                template = template.getTemplateReferencedLast(timestamp, referenceChain);
                if (template.getIsErroneous(timestamp)) {
                    expression.setIsErroneous(true);
                }
            } else {
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
                    instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                } else {
                    instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                }
                expression.setIsErroneous(true);
            }
            break;
        case SPECIFIC_VALUE:
            final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
            switch(tempValue.getValuetype()) {
                case REFERENCED_VALUE:
                    type.checkThisValueRef(timestamp, tempValue);
                    break;
                case EXPRESSION_VALUE:
                    tempValue.getValueRefdLast(timestamp, referenceChain);
                    break;
                default:
                    break;
            }
            if (tempValue.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 20 with ITTCN3Template

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

the class DecvalueUnicharExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * inout universal charstring
 * @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference1 == null) {
        setIsErroneous(true);
        return;
    }
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
    if (type_type != Type_type.TYPE_UCHARSTRING) {
        if (!isErroneous) {
            location.reportSemanticError(OPERAND1_ERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

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