Search in sources :

Example 26 with Omit_Value

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

the class Open_Type method checkThisValue.

// FIXME add tests
@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 (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;
    }
    this.check(timestamp);
    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;
        default:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
            }
            value.setIsErroneous(true);
    }
    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 27 with Omit_Value

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

the class Sequence_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    if (convertedValue != null && convertedValue != this) {
        final IValue temp = convertedValue.getReferencedSubValue(timestamp, reference, actualSubReference, refChain);
        if (temp != null && temp.getIsErroneous(timestamp)) {
            setIsErroneous(true);
        }
        return temp;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            CompField compField;
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SEQUENCE:
                    if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((TTCN3_Sequence_Type) type).getComponentByName(fieldId.getDisplayName());
                    if (compField.isOptional()) {
                        // create an explicit omit value
                        final Value result = new Omit_Value();
                        final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                        result.setFullNameParent(bridge);
                        result.setMyScope(getMyScope());
                        return result;
                    }
                    if (!reference.getUsedInIsbound()) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound record field `{0}''", fieldId.getDisplayName()));
                    }
                    return null;
                case TYPE_ASN1_SEQUENCE:
                    if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
                    if (compField.isOptional()) {
                        // create an explicit omit value
                        final Value result = new Omit_Value();
                        final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                        result.setFullNameParent(bridge);
                        result.setMyScope(getMyScope());
                        return result;
                    } else if (compField.hasDefault()) {
                        return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    return null;
                default:
                    return null;
            }
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 28 with Omit_Value

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

the class Set_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    break;
                default:
                    return null;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                if (!reference.getUsedInIsbound()) {
                    subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound set field `{0}''", fieldId.getDisplayName()));
                }
                // this is an error, that was already reported
                return null;
            }
            final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            } else if (compField.hasDefault()) {
                return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            }
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 29 with Omit_Value

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

the class ASN1_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);
                }
            }
            break;
        case CHOICE_VALUE:
            selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
                value.setIsErroneous(true);
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
                value.setIsErroneous(true);
            }
            value.setIsErroneous(true);
    }
    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 30 with Omit_Value

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

the class EqualsExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    // TODO actually a bit more complicated
    // TODO maybe this can be optimized later
    boolean isOptional1 = false;
    boolean isOptional2 = false;
    final IValue temp = value1.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
    if (temp instanceof Omit_Value) {
        isOptional1 = true;
    } else if (temp instanceof Referenced_Value) {
        final Reference reference = ((Referenced_Value) temp).getReference();
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
            isOptional1 = true;
        }
    }
    final IValue temp2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
    if (temp2 instanceof Omit_Value) {
        isOptional2 = true;
    } else if (temp2 instanceof Referenced_Value) {
        final Reference reference = ((Referenced_Value) temp2).getReference();
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
            isOptional2 = true;
        }
    }
    if (isOptional1) {
        value1.generateCodeExpression(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value2.generateCodeExpression(aData, expression, true);
        expression.expression.append(" )");
    } else if (isOptional2) {
        value2.generateCodeExpression(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value1.generateCodeExpression(aData, expression, true);
        expression.expression.append(" )");
    } else {
        value1.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value2.generateCodeExpressionMandatory(aData, expression, false);
        expression.expression.append(" )");
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 IType (org.eclipse.titan.designer.AST.IType)15 Identifier (org.eclipse.titan.designer.AST.Identifier)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)8 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)7 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6 Value (org.eclipse.titan.designer.AST.Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 HashMap (java.util.HashMap)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)4 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)4 Type (org.eclipse.titan.designer.AST.Type)4 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)3 Assignment (org.eclipse.titan.designer.AST.Assignment)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)3 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)2