Search in sources :

Example 6 with Sequence_Value

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

the class Anytype_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:
            last = last.setValuetype(timestamp, Value_type.ANYTYPE_VALUE);
            if (!last.getIsErroneous(timestamp)) {
                selfReference = checkThisValueAnytype(timestamp, (Anytype_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
            }
            break;
        case ANYTYPE_VALUE:
            selfReference = checkThisValueAnytype(timestamp, (Anytype_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(ANYTYPEEXPECTED, getFullName()));
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Anytype_Value(org.eclipse.titan.designer.AST.TTCN3.values.Anytype_Value)

Example 7 with Sequence_Value

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

Example 8 with Sequence_Value

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

the class Signature_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:
            selfReference = checkThisValueSequence(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case SEQUENCEOF_VALUE:
            last = last.setValuetype(timestamp, Value_type.SEQUENCE_VALUE);
            selfReference = checkThisValueSequence(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED, getTypename()));
            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)

Example 9 with Sequence_Value

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

the class TTCN3_Choice_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 (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
                value.setIsErroneous(true);
            } else {
                last = last.setValuetype(timestamp, Value_type.CHOICE_VALUE);
                if (!last.getIsErroneous(timestamp)) {
                    selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
                }
            }
            break;
        case CHOICE_VALUE:
            selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
            }
            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 : IValue(org.eclipse.titan.designer.AST.IValue) Choice_Value(org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value)

Example 10 with Sequence_Value

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

the class TTCN3_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 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 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;
    check(timestamp);
    final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
    if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
        value.removeGeneratedValues();
    }
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    final boolean isAsn = value.isAsn();
    boolean inSnyc = true;
    final int nofTypeComponents = realComponents.size();
    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 (!realComponents.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
            inSnyc = false;
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                final String duplicateAgain = MessageFormat.format(isAsn ? DUPLICATEDFIELDAGAINASN1 : DUPLICATEDFIELDAGAINTTCN3, valueId.getDisplayName());
                namedValue.getLocation().reportSemanticError(duplicateAgain);
                final String duplicateFirst = MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName());
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(duplicateFirst);
                inSnyc = false;
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = realComponents.get(valueId.getName());
            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()));
                        inSnyc = false;
                    }
                } else {
                    CompField field2 = getComponentByIndex(sequenceIndex);
                    final CompField field2Original = field2;
                    while (implicitOmit && sequenceIndex < getNofComponents() && componentField != field2 && field2.isOptional()) {
                        field2 = getComponentByIndex(sequenceIndex);
                    }
                    if (sequenceIndex >= getNofComponents() || 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);
                if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
                    if (!incompleteAllowed) {
                        componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                    }
                } else {
                    final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
                    selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, implicitOmit, strElem));
                }
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier id = compFieldMap.fields.get(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) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)16 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)4 Type (org.eclipse.titan.designer.AST.Type)4 HashMap (java.util.HashMap)3 Choice_Value (org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value)3 Location (org.eclipse.titan.designer.AST.Location)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)2 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)2 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)2 Set_Value (org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)2 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1