Search in sources :

Example 41 with TemplateInstance

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

the class LengthofExpression 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;
    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);
        return;
    }
    final Type_type typetype = templateInstance.getExpressionReturntype(timestamp, internalExpectation);
    switch(typetype) {
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
        case TYPE_ARRAY:
            break;
        case TYPE_UNDEFINED:
            break;
        default:
            templateInstance.getLocation().reportSemanticError(UNEXPECTEDOPERAND);
            setIsErroneous(true);
            return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 42 with TemplateInstance

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

the class LengthofExpression 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 (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody();
    final IValue value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
    int length;
    switch(value.getValuetype()) {
        case CHARSTRING_VALUE:
            length = ((Charstring_Value) value).getValueLength();
            break;
        case UNIVERSALCHARSTRING_VALUE:
            length = ((UniversalCharstring_Value) value).getValueLength();
            break;
        case BITSTRING_VALUE:
            length = ((Bitstring_Value) value).getValueLength();
            break;
        case HEXSTRING_VALUE:
            length = ((Hexstring_Value) value).getValueLength();
            break;
        case OCTETSTRING_VALUE:
            length = ((Octetstring_Value) value).getValueLength();
            break;
        case SEQUENCEOF_VALUE:
            length = ((SequenceOf_Value) value).getNofComponents();
            break;
        case SETOF_VALUE:
            length = ((SetOf_Value) value).getNofComponents();
            break;
        case ARRAY_VALUE:
            length = ((Array_Value) value).getNofComponents();
            break;
        default:
            setIsErroneous(true);
            return lastValue;
    }
    lastValue = new Integer_Value(length);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 43 with TemplateInstance

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

the class MatchExpression 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) {
    if (value == null || templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    if (value.getIsErroneous(timestamp) || templateInstance.getTemplateBody().getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    // Start
    IType localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    if (localGovernor == null) {
        localGovernor = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (localGovernor == null) {
        template = template.setLoweridToReference(timestamp);
        localGovernor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (localGovernor == null) {
        // Start again:
        value.setLoweridToReference(timestamp);
        localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    }
    if (localGovernor == null) {
        if (!template.getIsErroneous(timestamp)) {
            getLocation().reportSemanticError("Cannot determine the type of arguments in `match()' operation");
        }
        setIsErroneous(true);
        return;
    }
    value.setMyGovernor(localGovernor);
    final IValue temporalValue = localGovernor.checkThisValueRef(timestamp, value);
    localGovernor.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
    // FIXME check value against governor
    template.checkThisTemplateGeneric(timestamp, localGovernor, templateInstance.getDerivedReference() != null, false, false, true, false, null);
    try {
        ExpressionUtilities.checkExpressionOperatorCompatibility(timestamp, this, referenceChain, Expected_Value_type.EXPECTED_TEMPLATE, value, templateInstance);
    } catch (StackOverflowError e) {
        ErrorReporter.logExceptionStackTrace("Stack overflow was detected while analysing `" + getFullName() + "'", e.getCause());
        getLocation().reportSemanticError("Titan was unable to analyse this statement");
        setIsErroneous(true);
    }
    if (getIsErroneous(timestamp)) {
        return;
    }
    value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    templateInstance.getTemplateBody().getTemplateReferencedLast(timestamp, referenceChain);
    templateInstance.check(timestamp, localGovernor);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 44 with TemplateInstance

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

the class SizeOfExpression 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 (templateInstance == null) {
        return lastValue;
    }
    final long i = checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (i != -1) {
        lastValue = new Integer_Value(i);
        lastValue.copyGeneralProperties(this);
    }
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    return lastValue;
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 45 with TemplateInstance

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

the class Ttcn2StringExpression 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;
    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);
        IsValueExpression.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)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)29 IType (org.eclipse.titan.designer.AST.IType)26 IValue (org.eclipse.titan.designer.AST.IValue)16 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)13 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)13 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)10 Reference (org.eclipse.titan.designer.AST.Reference)9 Assignment (org.eclipse.titan.designer.AST.Assignment)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)8 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 Template (org.eclipse.jface.text.templates.Template)6 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)5 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)5 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)5 Type (org.eclipse.titan.designer.AST.Type)5 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)4 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)4 TypeSet (org.eclipse.titan.designer.AST.TTCN3.types.TypeSet)4 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3