Search in sources :

Example 56 with IType

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

the class Any2UnistrExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * in template (value) any_type
 * @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 (templateInstance1 == null) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType type = templateInstance1.getExpressionGovernor(timestamp, internalExpectation);
    ITTCN3Template template = templateInstance1.getTemplateBody();
    if (type == null) {
        template = template.setLoweridToReference(timestamp);
        type = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (type == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance1.getLocation().reportSemanticError(OPERAND1_ERROR1);
        }
        setIsErroneous(true);
        return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance1, type, referenceChain, expectedValue);
    if (getIsErroneous(timestamp)) {
        return;
    }
    template.checkSpecificValue(timestamp, false);
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_UNDEFINED:
        case TYPE_NULL:
        case TYPE_REFERENCED:
        case TYPE_VERDICT:
        case TYPE_PORT:
        case TYPE_COMPONENT:
        case TYPE_DEFAULT:
        case TYPE_SIGNATURE:
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (!isErroneous) {
                location.reportSemanticError(OPERAND1_ERROR2);
                setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
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 57 with IType

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

the class GreaterThanOrEqualExpression 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);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) >= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) >= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() >= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() >= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 58 with IType

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

the class ApplyExpression method getExpressionGovernor.

@Override
public /**
 * {@inheritDoc}
 */
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (myGovernor != null) {
        return myGovernor;
    }
    if (value == null) {
        return null;
    }
    IType type = value.getExpressionGovernor(timestamp, expectedValue);
    if (type == null) {
        if (!value.getIsErroneous(timestamp)) {
            value.getLocation().reportSemanticError(VALUEXPECTED1);
        }
        setIsErroneous(true);
        return null;
    }
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_FUNCTION:
            final Type result = ((Function_Type) type).getReturnType();
            if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && ((Function_Type) type).returnsTemplate()) {
                location.reportSemanticError(MessageFormat.format(VALUEXPECTED2, type.getTypename(), result.getTypename()));
            }
            return result;
        default:
            setIsErroneous(true);
            return null;
    }
}
Also used : Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 59 with IType

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

the class Def_Extfunction method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    isUsed = false;
    prototype = EncodingPrototype_type.NONE;
    functionEncodingType = ExternalFunctionEncodingType_type.MANUAL;
    encodingType = MessageEncoding_type.UNDEFINED;
    encodingOptions = null;
    errorBehaviorList = null;
    printingType = null;
    lastTimeChecked = timestamp;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_EXTERNALFUNCTION, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (returnType != null) {
        returnType.check(timestamp);
        final IType returnedType = returnType.getTypeRefdLast(timestamp);
        if (returnedType != null && Type_type.TYPE_PORT.equals(returnedType.getTypetype()) && returnType.getLocation() != null) {
            returnType.getLocation().reportSemanticError(PORTRETURNNOTALLOWED);
        }
    }
    formalParList.reset();
    formalParList.check(timestamp, getAssignmentType());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
        analyzeExtensionAttributes(timestamp);
        checkPrototype(timestamp);
        checkFunctionType(timestamp);
    }
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 60 with IType

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

the class Def_Extfunction method checkPrototype.

/**
 * Checks the prototype attribute set for this external function
 * definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
private void checkPrototype(final CompilationTimeStamp timestamp) {
    if (EncodingPrototype_type.NONE.equals(prototype)) {
        return;
    }
    // checking formal parameter list
    if (EncodingPrototype_type.CONVERT.equals(prototype)) {
        if (formalParList.getNofParameters() == 1) {
            final FormalParameter parameter = formalParList.getParameterByIndex(0);
            switch(parameter.getRealAssignmentType()) {
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                    inputType = parameter.getType(timestamp);
                    break;
                default:
                    {
                        final String message = MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName());
                        parameter.getLocation().reportSemanticError(message);
                        break;
                    }
            }
        } else {
            final String message = MessageFormat.format("The external function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName());
            formalParList.getLocation().reportSemanticError(message);
        }
    } else if (formalParList.getNofParameters() == 2) {
        final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
        if (EncodingPrototype_type.SLIDING.equals(prototype)) {
            if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                final Type firstParameterType = firstParameter.getType(timestamp);
                final IType last = firstParameterType.getTypeRefdLast(timestamp);
                if (last.getIsErroneous(timestamp)) {
                    inputType = firstParameterType;
                } else {
                    switch(last.getTypetypeTtcn3()) {
                        case TYPE_OCTETSTRING:
                        case TYPE_CHARSTRING:
                        case TYPE_BITSTRING:
                            inputType = firstParameterType;
                            break;
                        default:
                            {
                                final String message = MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName());
                                firstParameter.getLocation().reportSemanticError(message);
                                break;
                            }
                    }
                }
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        } else {
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                inputType = firstParameter.getType(timestamp);
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        }
        final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
        if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
            outputType = secondParameter.getType(timestamp);
        } else {
            secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
        }
    } else {
        formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
    }
    // checking the return type
    if (EncodingPrototype_type.FAST.equals(prototype)) {
        if (returnType != null) {
            returnType.getLocation().reportSemanticError(MessageFormat.format("The external function cannot have return type fo attribute `prototype({0})''", prototype.getName()));
        }
    } else {
        if (returnType == null) {
            location.reportSemanticError(MessageFormat.format("The external function must have a return type for attribute `prototype({0})''", prototype.getName()));
        } else {
            if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
                returnType.getLocation().reportSemanticError(MessageFormat.format("The external function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
            }
            if (EncodingPrototype_type.CONVERT.equals(prototype)) {
                outputType = returnType;
            } else {
                final IType last = returnType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
                    returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
                }
            }
        }
    }
}
Also used : IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) PrintingType(org.eclipse.titan.designer.AST.TTCN3.attributes.PrintingType) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)414 IValue (org.eclipse.titan.designer.AST.IValue)94 ISubReference (org.eclipse.titan.designer.AST.ISubReference)82 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)65 Identifier (org.eclipse.titan.designer.AST.Identifier)49 Assignment (org.eclipse.titan.designer.AST.Assignment)40 Value (org.eclipse.titan.designer.AST.Value)34 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)21 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)21 Reference (org.eclipse.titan.designer.AST.Reference)21 Type (org.eclipse.titan.designer.AST.Type)20 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)18 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)17 ArrayList (java.util.ArrayList)16 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)15 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)13