Search in sources :

Example 1 with NamedValues

use of org.eclipse.titan.designer.AST.TTCN3.values.NamedValues 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 2 with NamedValues

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

the class ASN1_BitString_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == namedValues) {
        parseBlockBitstring();
    }
    if (isErroneous || null == namedValues) {
        return;
    }
    /* check named bits */
    final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
    for (int i = 0, size = namedValues.getSize(); i < size; i++) {
        final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
        final Identifier identifier = namedValue.getName();
        if (nameMap.containsKey(identifier.getName())) {
            final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            nameMap.put(identifier.getName(), identifier);
        }
    }
    final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
    for (int i = 0, size = namedValues.getSize(); i < size; i++) {
        final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
        final IValue value = namedValue.getValue();
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = value.getValueRefdLast(timestamp, referenceChain);
        referenceChain.release();
        if (last.getIsErroneous(timestamp)) {
            continue;
        }
        switch(last.getValuetype()) {
            case INTEGER_VALUE:
                {
                    final Integer_Value integerValue = (Integer_Value) last;
                    if (integerValue.isNative()) {
                        final int intValue = integerValue.intValue();
                        final Integer intValueObject = Integer.valueOf(intValue);
                        if (intValue < 0) {
                            value.getLocation().reportSemanticError(MessageFormat.format("A non-negative INTEGER value was expected for named bit `{0}'' instead of {1}", namedValue.getName().getDisplayName(), intValueObject));
                            value.setIsErroneous(true);
                            continue;
                        }
                        if (valueMap.containsKey(intValueObject)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Duplicate value {0} for named bit `{1}''", intValueObject, namedValue.getName().getDisplayName()));
                            value.setIsErroneous(true);
                            final NamedValue temp = valueMap.get(intValueObject);
                            temp.getLocation().reportSemanticError(MessageFormat.format("Bit {0} is already assigned to name `{1}''", intValueObject, temp.getName().getDisplayName()));
                        } else {
                            valueMap.put(intValueObject, namedValue);
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value `{0}'' is too big to be used as a named bit", integerValue.getValueValue()));
                        value.setIsErroneous(true);
                    }
                    break;
                }
            default:
                namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named bit `{0}''", namedValue.getName().getDisplayName()));
                break;
        }
    }
    nameMap.clear();
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Example 3 with NamedValues

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

the class Named_Template_List method getValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValue() {
    if (asValue != null) {
        return asValue;
    }
    final NamedValues values = new NamedValues();
    for (int i = 0, size = getNofTemplates(); i < size; i++) {
        final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
        final NamedValue namedValue = new NamedValue(namedTemplate.getName(), namedTemplate.getTemplate().getValue());
        namedValue.setLocation(namedTemplate.getLocation());
        values.addNamedValue(namedValue);
    }
    asValue = new Sequence_Value(values);
    asValue.setLocation(getLocation());
    asValue.setMyScope(getMyScope());
    asValue.setFullNameParent(getNameParent());
    asValue.setMyGovernor(getMyGovernor());
    return asValue;
}
Also used : Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) NamedValues(org.eclipse.titan.designer.AST.TTCN3.values.NamedValues)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)2 HashMap (java.util.HashMap)1 Named_Bits (org.eclipse.titan.designer.AST.ASN1.values.Named_Bits)1 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)1 IType (org.eclipse.titan.designer.AST.IType)1 Location (org.eclipse.titan.designer.AST.Location)1 Module (org.eclipse.titan.designer.AST.Module)1 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)1 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)1 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)1 NamedValues (org.eclipse.titan.designer.AST.TTCN3.values.NamedValues)1 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)1