Search in sources :

Example 31 with Expected_Value_type

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

the class Xor4bExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    String str1;
    String str2;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            str1 = ((Bitstring_Value) last1).getValue();
            str2 = ((Bitstring_Value) last2).getValue();
            lastValue = new Bitstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            str1 = ((Hexstring_Value) last1).getValue();
            str2 = ((Hexstring_Value) last2).getValue();
            lastValue = new Hexstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            str1 = ((Octetstring_Value) last1).getValue();
            str2 = ((Octetstring_Value) last2).getValue();
            lastValue = new Octetstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 32 with Expected_Value_type

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

the class Type method checkStringIndex.

// FIXME comment
protected void checkStringIndex(final CompilationTimeStamp timestamp, final Value indexValue, final Expected_Value_type expectedIndex, final IReferenceChain refChain) {
    if (indexValue != null) {
        indexValue.setLoweridToReference(timestamp);
        final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
        switch(tempType) {
            case TYPE_INTEGER:
                final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
                if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
                    final Integer_Value lastInteger = (Integer_Value) last;
                    if (lastInteger.isNative()) {
                        final long temp = lastInteger.getValue();
                        if (temp < 0) {
                            indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.NONNEGATIVINDEXEXPECTED, temp));
                            indexValue.setIsErroneous(true);
                        }
                    } else {
                        indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
                        indexValue.setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                indexValue.setIsErroneous(true);
                break;
            default:
                indexValue.getLocation().reportSemanticError(SequenceOf_Type.INTEGERINDEXEXPECTED);
                indexValue.setIsErroneous(true);
                break;
        }
    }
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 33 with Expected_Value_type

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

the class Type method checkThisReferencedValue.

/**
 * Checks the provided referenced value.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the referenced value to be checked.
 * @param lhs
 *                the assignment to check against
 * @param expectedValue
 *                the expectations we have for the value.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param strElem
 *                true if the value to be checked is an element of a
 *                string
 * @return true if the value contains a reference to lhs
 */
private boolean checkThisReferencedValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final Expected_Value_type expectedValue, final IReferenceChain referenceChain, final boolean subCheck, final boolean strElem) {
    final Reference reference = ((Referenced_Value) value).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
    if (assignment == null) {
        value.setIsErroneous(true);
        return false;
    }
    final Assignment myAssignment = getDefiningAssignment();
    if (myAssignment != null && myAssignment instanceof Definition) {
        final String referingModuleName = value.getMyScope().getModuleScope().getName();
        if (!((Definition) myAssignment).referingHere.contains(referingModuleName)) {
            ((Definition) myAssignment).referingHere.add(referingModuleName);
        }
    }
    assignment.check(timestamp);
    final boolean selfReference = assignment == lhs;
    boolean isConst = false;
    boolean errorFlag = false;
    boolean checkRunsOn = false;
    IType governor = null;
    if (assignment.getIsErroneous()) {
        value.setIsErroneous(true);
    } else {
        switch(assignment.getAssignmentType()) {
            case A_CONST:
                isConst = true;
                break;
            case A_OBJECT:
            case A_OS:
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    value.setIsErroneous(true);
                    return selfReference;
                }
                if (!Setting_type.S_V.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format("This InformationFromObjects construct does not refer to a value: {0}", value.getFullName()));
                    value.setIsErroneous(true);
                    return selfReference;
                }
                governor = ((Value) setting).getMyGovernor();
                if (governor != null) {
                    isConst = true;
                }
                break;
            case A_EXT_CONST:
            case A_MODULEPAR:
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluatable) constant value was expected instead of {0}", assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_VAR:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    case EXPECTED_STATIC_VALUE:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    default:
                        break;
                }
                break;
            case A_TEMPLATE:
            case A_MODULEPAR_TEMPLATE:
            case A_VAR_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION_RVAL:
                checkRunsOn = true;
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_EXT_FUNCTION_RVAL:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_FUNCTION_RTEMP:
                checkRunsOn = true;
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_EXT_FUNCTION_RTEMP:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION:
            case A_EXT_FUNCTION:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of a call of {1}, which does not have a return type", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
            default:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
        }
    }
    if (checkRunsOn) {
        reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
    }
    if (governor == null) {
        final IType type = assignment.getType(timestamp);
        if (type != null) {
            governor = type.getFieldType(timestamp, reference, 1, expectedValue, referenceChain, false);
        }
    }
    if (governor == null) {
        value.setIsErroneous(true);
        return selfReference;
    }
    final TypeCompatibilityInfo info = new TypeCompatibilityInfo(this, governor, true);
    info.setStr1Elem(strElem);
    info.setStr2Elem(reference.refersToStringElement());
    final CompatibilityLevel compatibilityLevel = getCompatibility(timestamp, governor, info, null, null);
    if (compatibilityLevel != CompatibilityLevel.COMPATIBLE) {
        // Port or signature values do not exist at all. These
        // errors are already
        // reported at those definitions. Extra errors should
        // not be reported
        // here.
        final IType type = getTypeRefdLast(timestamp, null);
        switch(type.getTypetype()) {
            case TYPE_PORT:
                // neither port values nor templates exist
                break;
            case TYPE_SIGNATURE:
                if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    final String message = MessageFormat.format("Type mismatch: a signature template of type `{0}'' was expected instead of `{1}''", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_ARRAY:
            case TYPE_ASN1_SET:
            case TYPE_TTCN3_SET:
            case TYPE_SET_OF:
            case TYPE_ASN1_CHOICE:
            case TYPE_TTCN3_CHOICE:
            case TYPE_ANYTYPE:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    value.getLocation().reportSemanticError(info.toString());
                }
                break;
            default:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    final String message = MessageFormat.format("Type mismatch: a {0} of type `{1}'' was expected instead of `{2}''", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
        }
        errorFlag = true;
    } else {
        if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
            if (info.getNeedsConversion()) {
                value.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, this.getTypename(), governor.getTypename()));
            }
        }
    }
    if (errorFlag) {
        value.setIsErroneous(true);
        return selfReference;
    }
    // checking for circular references
    final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    if (isConst && !last.getIsErroneous(timestamp)) {
        if (subCheck && (subType != null)) {
            subType.checkThisValue(timestamp, value);
        }
    }
    return selfReference;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 34 with Expected_Value_type

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

the class RegexpExpression 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_CHARSTRING:
        case TYPE_UCHARSTRING:
            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 35 with Expected_Value_type

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

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)149 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)54 IType (org.eclipse.titan.designer.AST.IType)47 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)45 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)39 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)31 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)24 ISubReference (org.eclipse.titan.designer.AST.ISubReference)21 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)21 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)20 Identifier (org.eclipse.titan.designer.AST.Identifier)17 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)17 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)14 Type (org.eclipse.titan.designer.AST.Type)14 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Value (org.eclipse.titan.designer.AST.Value)11