Search in sources :

Example 16 with Type_type

use of org.eclipse.titan.designer.AST.IType.Type_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 17 with Type_type

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

Example 18 with Type_type

use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.

the class ReplaceExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    if (lastValue != null && lastValue != this) {
        lastValue.generateCodeExpression(aData, expression, true);
        return;
    }
    final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    // TODO handle the needs conversion case
    final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    switch(expressionType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            aData.addCommonLibraryImport("AdditionalFunctions");
            expression.expression.append("AdditionalFunctions.replace( ");
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(", ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(')');
            break;
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            // TODO: need to test
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(".replace( ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(')');
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
            break;
    }
}
Also used : 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)

Example 19 with Type_type

use of org.eclipse.titan.designer.AST.IType.Type_type 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 20 with Type_type

use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.

the class RotateLeftExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value1 == null || value2 == null || getIsErroneous(timestamp)) {
        return true;
    }
    if (value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain)) {
        return true;
    }
    value1.setLoweridToReference(timestamp);
    final Type_type tempType = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            return false;
        default:
            return true;
    }
}
Also used : Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Aggregations

Type_type (org.eclipse.titan.designer.AST.IType.Type_type)130 IValue (org.eclipse.titan.designer.AST.IValue)79 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)19 IType (org.eclipse.titan.designer.AST.IType)13 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)9 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)9 Assignment (org.eclipse.titan.designer.AST.Assignment)7 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)7 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)3 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)3 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)3 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3 Module (org.eclipse.titan.designer.AST.Module)2