Search in sources :

Example 6 with Expression_Value

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

the class ASN1_Integer_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (null == last || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            break;
        case NAMED_INTEGER_VALUE:
            if (null != namedNumbers) {
                // convert it into an integer value
                final Identifier name = ((Named_Integer_Value) last).getIdentifier();
                final NamedValue namedValue = namedNumbers.getNamedValueByName(name);
                IValue tempValue = namedValue.getValue();
                final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
                referenceChain.release();
                if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
                    final int temp = ((Integer_Value) tempValue).intValue();
                    final Integer_Value converted = new Integer_Value(temp);
                    converted.copyGeneralProperties(value);
                    ((Named_Integer_Value) last).setCalculatedValue(converted);
                } else {
                // FIXME Most probably we were not able
                // to build the semantic structure for
                // something, because it is not yet
                // supported, like referenced values in
                // sets
                }
            }
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)

Example 7 with Expression_Value

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

the class ASN1_Sequence_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            if (last.isAsn()) {
                selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (((SequenceOf_Value) last).isIndexed()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for SEQUENCE type `{0}''", getFullName()));
                value.setIsErroneous(true);
            } else {
                last = last.setValuetype(timestamp, Value_type.SEQUENCE_VALUE);
                if (last.isAsn()) {
                    selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
                } else {
                    selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
                }
            }
            break;
        case UNDEFINED_BLOCK:
            last = last.setValuetype(timestamp, Value_type.SEQUENCE_VALUE);
            selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(SEQUANCEEPECTED, getFullName()));
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)

Example 8 with Expression_Value

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

the class ASN1_BitString_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    if (last.isAsn()) {
        if (last instanceof IReferencingType) {
            final IType type = last.getMyGovernor().getTypeRefdLast(timestamp);
            switch(type.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    break;
                default:
                    value.getLocation().reportSemanticError("(reference to) BIT STRING value was expected");
                    value.setIsErroneous(true);
                    value.setLastTimeChecked(timestamp);
                    return selfReference;
            }
        }
        switch(last.getValuetype()) {
            case BITSTRING_VALUE:
                break;
            case HEXSTRING_VALUE:
                last.setValuetype(timestamp, Value_type.BITSTRING_VALUE);
                break;
            case UNDEFINED_BLOCK:
                {
                    last = last.setValuetype(timestamp, Value_type.NAMED_BITS);
                    if (namedValues == null) {
                        value.getLocation().reportSemanticError(MessageFormat.format("No named bits are defined in type `{0}''", getTypename()));
                        value.setIsErroneous(true);
                        value.setLastTimeChecked(timestamp);
                        return selfReference;
                    }
                    final Named_Bits namedBits = (Named_Bits) last;
                    final StringBuilder builder = new StringBuilder(namedBits.getNofIds());
                    for (int i = 0; i < namedBits.getNofIds(); i++) {
                        final Identifier id = namedBits.getIdByIndex(i);
                        if (!namedValues.hasNamedValueWithName(id)) {
                            id.getLocation().reportSemanticError(MessageFormat.format("No named bit with name `{0}'' is defined in type `{1}''", id.getDisplayName(), getTypename()));
                            value.setIsErroneous(true);
                            value.setLastTimeChecked(timestamp);
                            return selfReference;
                        }
                        IValue tempValue = namedValues.getNamedValueByName(id).getValue();
                        final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
                        referenceChain.release();
                        if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
                            final int bitIndex = ((Integer_Value) tempValue).intValue();
                            while (builder.length() <= bitIndex) {
                                builder.append('0');
                            }
                            builder.setCharAt(bitIndex, '1');
                        } else {
                        // FIXME Most probably we were
                        // not able to build the
                        // semantic structure for
                        // something, because it is not
                        // yet supported, like
                        // referenced values in sets
                        }
                    }
                    last = new Bitstring_Value(builder.toString());
                    last.copyGeneralProperties(value);
                    namedBits.setRealValue((Bitstring_Value) last);
                    break;
                }
            default:
                value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED1);
                value.setIsErroneous(true);
                value.setLastTimeChecked(timestamp);
                return selfReference;
        }
    } else {
        switch(last.getValuetype()) {
            case BITSTRING_VALUE:
                break;
            case EXPRESSION_VALUE:
            case MACRO_VALUE:
                // already checked
                break;
            default:
                value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED2);
                value.setIsErroneous(true);
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) Named_Bits(org.eclipse.titan.designer.AST.ASN1.values.Named_Bits) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with Expression_Value

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

the class Start_Referenced_Component_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    Component_Type compType = null;
    if (componentReference != null) {
        compType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
    }
    if (dereferredValue == null) {
        return;
    }
    switch(dereferredValue.getValuetype()) {
        case EXPRESSION_VALUE:
            if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
                dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `refers' operation," + " which does not specify any function type.");
                return;
            }
            break;
        case TTCN3_NULL_VALUE:
        case FAT_NULL_VALUE:
            dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `null' value, which does not specify any function type.");
            return;
        default:
            break;
    }
    dereferredValue.setLoweridToReference(timestamp);
    IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null || type.getIsErroneous(timestamp)) {
        return;
    }
    if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
        dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument of `{0}''", type.getTypename()));
        return;
    }
    final Function_Type functionType = (Function_Type) type;
    if (functionType.isRunsOnSelf()) {
        dereferredValue.getLocation().reportSemanticError("The argument cannot be a function reference with 'runs on self' clause");
        return;
    }
    if (!functionType.checkStartable(timestamp, getLocation())) {
        return;
    }
    final IType runsOnType = functionType.getRunsOnType(timestamp);
    if (compType != null && runsOnType != null && !runsOnType.isCompatible(timestamp, compType, null, null, null)) {
        final String message = MessageFormat.format("Component type mismatch: the component reference os of type `{0}'', but functions of type `{1}'' run on `{2}''", compType.getTypename(), functionType.getTypename(), runsOnType.getTypename());
        componentReference.getLocation().reportSemanticError(message);
    }
    final IType returnType = functionType.getReturnType();
    if (returnType != null) {
        if (functionType.returnsTemplate()) {
            dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Function of type `{0}'' return a template of type `{1}''," + " which cannot be retrieved when the test component terminates", functionType.getTypename(), returnType.getTypename()));
        } else {
            IType lastType = returnType;
            boolean returnTypeCorrect = false;
            while (!returnTypeCorrect) {
                if (lastType.hasDoneAttribute()) {
                    returnTypeCorrect = true;
                    break;
                }
                if (lastType instanceof IReferencingType) {
                    final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IType refd = ((IReferencingType) lastType).getTypeRefd(timestamp, refChain);
                    refChain.release();
                    if (lastType != refd) {
                        lastType = refd;
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
            if (!returnTypeCorrect) {
                dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Return type of function type `{0}'' is `{1}'', which does not have the `done'' extension attibute." + " When the test component terminates the returnes value cannot be retrived with a `done'' operation", functionType.getTypename(), returnType.getTypename()));
            }
        }
    }
    actualParameterList2 = new ActualParameterList();
    final FormalParameterList formalParameters = functionType.getFormalParameters();
    if (!formalParameters.checkActualParameterList(timestamp, parameters, actualParameterList2)) {
        actualParameterList2.setFullNameParent(this);
        actualParameterList2.setMyScope(getMyScope());
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with Expression_Value

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

the class Stop_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    final ExpressionStruct expression = new ExpressionStruct();
    if (componentReference == null) {
        aData.addBuiltinTypeImport("TitanComponent");
        expression.expression.append("TTCN_Runtime.stop_component(TitanComponent.ALL_COMPREF)");
    } else {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = componentReference.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (last.getValuetype() == Value_type.REFERENCED_VALUE) {
            // the argument is a simple component reference
            last.generateCodeExpressionMandatory(aData, expression, true);
            expression.expression.append(".stop()");
        } else {
            boolean refers_to_self = false;
            if (last.getValuetype() == Value_type.EXPRESSION_VALUE) {
                // the argument is a special component reference (mtc, self, etc.)
                switch(((Expression_Value) last).getOperationType()) {
                    case MTC_COMPONENT_OPERATION:
                        {
                            Definition myDefinition = myStatementBlock.getMyDefinition();
                            if (myDefinition != null && myDefinition.getAssignmentType() == Assignment_type.A_TESTCASE) {
                                refers_to_self = true;
                            }
                            break;
                        }
                    case SELF_COMPONENT_OPERATION:
                        refers_to_self = true;
                    default:
                        break;
                }
            }
            if (refers_to_self) {
                expression.expression.append("TTCN_Runtime.stop_execution()");
            } else {
                expression.expression.append("TTCN_Runtime.stop_component(");
                last.generateCodeExpression(aData, expression, false);
                expression.expression.append(')');
            }
        }
    }
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)30 IType (org.eclipse.titan.designer.AST.IType)13 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)11 Identifier (org.eclipse.titan.designer.AST.Identifier)5 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)5 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)5 Scope (org.eclipse.titan.designer.AST.Scope)4 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)4 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)3 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)3 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)3 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)3 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)2 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2