Search in sources :

Example 1 with Macro_Value

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

the class Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    value.setIsErroneous(false);
    final Assignment assignment = getDefiningAssignment();
    if (assignment != null && assignment instanceof Definition) {
        final Scope scope = value.getMyScope();
        if (scope != null) {
            final Module module = scope.getModuleScope();
            if (module != null) {
                final String referingModuleName = module.getName();
                if (!((Definition) assignment).referingHere.contains(referingModuleName)) {
                    ((Definition) assignment).referingHere.add(referingModuleName);
                }
            } else {
                ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a module");
                value.setIsErroneous(true);
            }
        } else {
            ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a scope");
            value.setIsErroneous(true);
        }
    }
    check(timestamp);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp) || getIsErroneous(timestamp)) {
        return false;
    }
    if (Value_type.OMIT_VALUE.equals(last.getValuetype()) && !valueCheckingOptions.omit_allowed) {
        value.getLocation().reportSemanticError("`omit' value is not allowed in this context");
        value.setIsErroneous(true);
        return false;
    }
    boolean selfReference = false;
    switch(value.getValuetype()) {
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                selfReference = checkThisReferencedValue(timestamp, last, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
                chain.release();
                return selfReference;
            }
            return false;
        case REFERENCED_VALUE:
            {
                final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                selfReference = checkThisReferencedValue(timestamp, value, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
                chain.release();
                return selfReference;
            }
        case EXPRESSION_VALUE:
            selfReference = value.checkExpressionSelfReference(timestamp, lhs);
            if (value.isUnfoldable(timestamp, null)) {
                final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
                if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
                    value.setIsErroneous(true);
                }
            }
            return selfReference;
        case MACRO_VALUE:
            selfReference = value.checkExpressionSelfReference(timestamp, lhs);
            if (value.isUnfoldable(timestamp, null)) {
                final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
                if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
                    value.setIsErroneous(true);
                }
                return selfReference;
            }
            break;
        default:
            break;
    }
    return selfReference;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 2 with Macro_Value

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

the class ASN1_Integer_Type method checkThisValueLimit.

// this method accepts REAL_VALUE
public void checkThisValueLimit(final CompilationTimeStamp timestamp, final IValue value, final ValueCheckingOptions valueCheckingOptions) {
    super.checkThisValue(timestamp, value, null, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (null == last || last.getIsErroneous(timestamp)) {
        return;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
        case REAL_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);
    }
}
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 3 with Macro_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Macro_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 4 with Macro_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Macro_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 5 with Macro_Value

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

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)19 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 IType (org.eclipse.titan.designer.AST.IType)4 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)4 Identifier (org.eclipse.titan.designer.AST.Identifier)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)3 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2 Scope (org.eclipse.titan.designer.AST.Scope)2 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)2 Choice_Value (org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value)2 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)2 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)2 Set_Value (org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)2 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)1 Named_Bits (org.eclipse.titan.designer.AST.ASN1.values.Named_Bits)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)1 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)1 Reference (org.eclipse.titan.designer.AST.Reference)1