Search in sources :

Example 1 with NamedValue

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

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

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

the class ASN1_Sequence_Type method checkThisValueSeq.

/**
 * Checks the Sequence_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for
 * sure that the value is of sequence type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 * @param expectedValue
 *                the expected kind of the value.
 * @param incompleteAllowed
 *                wheather incomplete value is allowed or not.
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the value, false otherwise
 */
private boolean checkThisValueSeq(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
    if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
        value.removeGeneratedValues();
    }
    final boolean isAsn = value.isAsn();
    boolean inSnyc = true;
    final int nofTypeComponents = getNofComponents(timestamp);
    final int nofValueComponents = value.getNofComponents();
    int nextIndex = 0;
    CompField lastCompField = null;
    int sequenceIndex = 0;
    for (int i = 0; i < nofValueComponents; i++, sequenceIndex++) {
        final NamedValue namedValue = value.getSeqValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!hasComponentWithName(valueId)) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
            inSnyc = false;
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUBLICATEDFIELDAGAINASN1 : DUBLICATEDFIELDAGAINTTCN3, valueId.getDisplayName()));
                final Location tempLocation = componentMap.get(valueId.getName()).getLocation();
                tempLocation.reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName()));
                inSnyc = false;
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = getComponentByName(valueId);
            if (inSnyc) {
                if (incompleteAllowed) {
                    boolean found = false;
                    for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                        final CompField field2 = getComponentByIndex(j);
                        if (valueId.getName().equals(field2.getIdentifier().getName())) {
                            lastCompField = field2;
                            nextIndex = j + 1;
                            found = true;
                        }
                    }
                    if (lastCompField != null && !found) {
                        namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? WRONGFIELDORDERASN1 : WRONGFIELDORDERTTCN3, valueId.getDisplayName(), lastCompField.getIdentifier().getDisplayName()));
                    }
                } else {
                    CompField field2 = getComponentByIndex(sequenceIndex);
                    final CompField field2Original = field2;
                    boolean isOptional = field2.isOptional();
                    if (!isOptional && field2.hasDefault() && defaultAsOptional) {
                        isOptional = true;
                    }
                    while (implicitOmit && sequenceIndex < getNofComponents(timestamp) && componentField != field2 && isOptional) {
                        ++sequenceIndex;
                        field2 = getComponentByIndex(sequenceIndex);
                    }
                    if (sequenceIndex >= getNofComponents(timestamp) || componentField != field2) {
                        namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? UNEXPECTEDFIELDASN1 : UNEXPECTEDFIELDTTCN3, valueId.getDisplayName(), field2Original.getIdentifier().getDisplayName()));
                    }
                }
            }
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                final IValue temporalValue = type.checkThisValueRef(timestamp, componentValue);
                boolean isOptional = componentField.isOptional();
                if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
                    isOptional = true;
                }
                selfReference |= type.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, isOptional, true, implicitOmit, strElem));
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier id = getComponentByIndex(i).getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (getComponentByIndex(i).isOptional() && implicitOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value) Location(org.eclipse.titan.designer.AST.Location)

Example 4 with NamedValue

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

the class ASN1_Set_Type method checkThisValueSet.

/**
 * Checks the Set_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for
 * sure that the value is of set type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 * @param expectedValue
 *                the kind of value expected here.
 * @param incompleteAllowed
 *                wheather incomplete value is allowed or not.
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the value, false otherwise
 */
private boolean checkThisValueSet(final CompilationTimeStamp timestamp, final Set_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    value.removeGeneratedValues();
    final boolean isAsn = value.isAsn();
    final int nofValueComponents = value.getNofComponents();
    for (int i = 0; i < nofValueComponents; i++) {
        final NamedValue namedValue = value.getSequenceValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!hasComponentWithName(valueId)) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDASN1 : NONEXISTENTFIELDTTCN3, namedValue.getName().getDisplayName(), getTypename()));
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDAGAINASN1 : DUPLICATEFIELDAGAINTTCN3, valueId.getDisplayName()));
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDFIRSTASN1 : DUPLICATEFIELDFIRSTTTCN3, valueId.getDisplayName()));
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = getComponentByName(valueId);
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                final IValue temporalValue = type.checkThisValueRef(timestamp, componentValue);
                boolean isOptional = componentField.isOptional();
                if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
                    isOptional = true;
                }
                selfReference |= type.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, isOptional, true, implicitOmit, strElem));
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        final int nofTypeComponents = getNofComponents(timestamp);
        CompField field;
        for (int i = 0; i < nofTypeComponents; i++) {
            field = getComponentByIndex(i);
            final Identifier id = field.getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (field.isOptional() && implicitOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

Example 5 with NamedValue

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

the class Signature_Type method checkThisValueSequence.

/**
 * Checks the Sequence_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for sure
 * that the value is of sequence type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value expected here.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param implicitOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
private boolean checkThisValueSequence(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    boolean inSnyc = true;
    final int nofTypeComponents = getNofParameters();
    final int nofvalueComponents = value.getNofComponents();
    int nextIndex = 0;
    SignatureFormalParameter lastParameter = null;
    for (int i = 0; i < nofvalueComponents; i++) {
        final NamedValue namedValue = value.getSeqValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!formalParList.hasParameterWithName(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, valueId.getDisplayName(), getTypename()));
            inSnyc = false;
            continue;
        } else if (componentMap.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, valueId.getDisplayName(), getTypename()));
            componentMap.get(valueId.getName()).getLocation().reportSemanticError(MessageFormat.format("Parameter `{0}'' is already given here", valueId.getDisplayName()));
            inSnyc = false;
        } else {
            componentMap.put(valueId.getName(), namedValue);
        }
        final SignatureFormalParameter formalParameter = formalParList.getParameterByName(valueId.getName());
        if (inSnyc) {
            if (incompleteAllowed) {
                boolean found = false;
                for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                    final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(j);
                    if (valueId.getName().equals(formalParameter2.getIdentifier().getName())) {
                        lastParameter = formalParameter2;
                        nextIndex = j + 1;
                        found = true;
                    }
                }
                if (lastParameter != null && !found) {
                    namedValue.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' cannot appear after parameter `{1}'' in signature value", valueId.getDisplayName(), lastParameter.getIdentifier().getDisplayName()));
                    inSnyc = false;
                }
            } else {
                final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(i);
                if (formalParameter != formalParameter2) {
                    namedValue.getLocation().reportSemanticError(MessageFormat.format("Unexpected field `{0}'' in signature value, expecting `{1}''", valueId.getDisplayName(), formalParameter2.getIdentifier().getDisplayName()));
                    inSnyc = false;
                }
            }
        }
        final Type type = formalParameter.getType();
        final IValue componentValue = namedValue.getValue();
        if (componentValue != null) {
            componentValue.setMyGovernor(type);
            final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
            selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, false, false, true, implicitOmit, strElem));
        }
    }
    if (!incompleteAllowed) {
        for (int i = 0; i < formalParList.getNofInParameters(); i++) {
            final SignatureFormalParameter formalParameter = formalParList.getInParameterByIndex(i);
            final Identifier identifier = formalParameter.getIdentifier();
            if (!componentMap.containsKey(identifier.getName()) && SignatureFormalParameter.ParamaterDirection.PARAM_OUT != formalParameter.getDirection()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is missing from signature value", identifier.getDisplayName()));
            }
        }
    }
    return selfReference;
}
Also used : SignatureReturnType(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)

Aggregations

NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)10 IValue (org.eclipse.titan.designer.AST.IValue)9 Identifier (org.eclipse.titan.designer.AST.Identifier)9 HashMap (java.util.HashMap)7 IType (org.eclipse.titan.designer.AST.IType)5 Type (org.eclipse.titan.designer.AST.Type)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)4 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)3 Location (org.eclipse.titan.designer.AST.Location)3 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)2 Module (org.eclipse.titan.designer.AST.Module)2 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)2 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)2 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)1 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)1 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)1