Search in sources :

Example 6 with BridgingNamedNode

use of org.eclipse.titan.designer.AST.BridgingNamedNode in project titan.EclipsePlug-ins by eclipse.

the class TableConstraint method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    parseBlocks();
    if (null == myType) {
        return;
    }
    objectSet.setMyScope(myType.getMyScope());
    BridgingNamedNode bridge = new BridgingNamedNode(this, FULLNAMEPART);
    objectSet.setFullNameParent(bridge);
    // search the constrained type (not the reference to it)
    constrainedType = myType;
    while (true) {
        if (constrainedType.getIsErroneous(timestamp)) {
            return;
        }
        if (Type_type.TYPE_OPENTYPE.equals(constrainedType.getTypetype()) || Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
            break;
        } else if (constrainedType instanceof IReferencingType) {
            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            constrainedType = ((IReferencingType) constrainedType).getTypeRefd(timestamp, chain);
            chain.release();
        } else {
            myType.getLocation().reportSemanticError(OCFTEXPECTED);
            return;
        }
    }
    if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
        ObjectClassField_Type ocfType = (ObjectClassField_Type) constrainedType;
        objectClassFieldname = ocfType.getObjectClassFieldName();
        objectSet.setMyGovernor(ocfType.getMyObjectClass());
        objectSet.check(timestamp);
        return;
    }
    // opentype
    final Open_Type openType = (Open_Type) constrainedType;
    openType.setMyTableConstraint(this);
    objectClassFieldname = openType.getObjectClassFieldName();
    objectSet.setMyGovernor(openType.getMyObjectClass());
    objectSet.check(timestamp);
    if (null == atNotationList) {
        return;
    }
    // componentrelationconstraint...
    // search the outermost textually enclosing seq, set or choice
    IType outermostParent = null;
    IType tempType = myType;
    do {
        switch(tempType.getTypetype()) {
            case TYPE_ASN1_CHOICE:
            case TYPE_TTCN3_CHOICE:
            case TYPE_OPENTYPE:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_ASN1_SET:
            case TYPE_TTCN3_SET:
                outermostParent = tempType;
                break;
            default:
                break;
        }
        tempType = tempType.getParentType();
    } while (null != tempType);
    if (null == outermostParent) {
        myType.getLocation().reportSemanticError(CANNOTDETERMINEPARENT);
        return;
    }
    // outermostparent->set_opentype_outermost();
    // TODO implement the setting of set_has_openType
    AtNotation atNotation;
    for (int i = 0; i < atNotationList.getNofAtNotations(); i++) {
        atNotation = atNotationList.getAtNotationByIndex(i);
        IType parent = null;
        if (0 == atNotation.getLevels()) {
            parent = outermostParent;
        } else {
            parent = myType;
            for (int level = atNotation.getLevels(); level > 0; level--) {
                parent = parent.getParentType();
                if (null == parent) {
                    myType.getLocation().reportSemanticError(MessageFormat.format(TOOMANYDOTS, atNotation.getLevels()));
                    return;
                }
            }
        }
        tempType = parent;
        atNotation.setFirstComponent(parent);
        // component identifiers... do they exist? yes, if the refd type is constrained
        FieldName componentIdentifiers = atNotation.getComponentIdentifiers();
        for (int j = 0; j < componentIdentifiers.getNofFields(); j++) {
            Identifier identifier = componentIdentifiers.getFieldByIndex(i);
            switch(tempType.getTypetype()) {
                case TYPE_ASN1_CHOICE:
                    {
                        final ASN1_Choice_Type temp2 = (ASN1_Choice_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_CHOICE:
                    {
                        final TTCN3_Choice_Type temp2 = (TTCN3_Choice_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_OPENTYPE:
                    {
                        final Open_Type temp2 = (Open_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_ASN1_SEQUENCE:
                    {
                        final ASN1_Sequence_Type temp2 = (ASN1_Sequence_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_SEQUENCE:
                    {
                        final TTCN3_Sequence_Type temp2 = (TTCN3_Sequence_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_ASN1_SET:
                    {
                        final ASN1_Set_Type temp2 = (ASN1_Set_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_SET:
                    {
                        final TTCN3_Set_Type temp2 = (TTCN3_Set_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                default:
                    myType.getLocation().reportSemanticError(MessageFormat.format(SECHOEXPECTED, tempType.getFullName()));
                    return;
            }
        }
        atNotation.setLastComponent(tempType);
        /*
			 * check if the referenced component is constrained by the same objectset...
			 */
        boolean ok = false;
        final Constraints constraints = tempType.getConstraints();
        if (constraints != null) {
            constraints.check(timestamp);
            final TableConstraint tableConstraint = constraints.getTableConstraint();
            if (tableConstraint != null) {
                IType ocft = tableConstraint.constrainedType;
                if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(ocft.getTypetype())) {
                    atNotation.setObjectClassFieldname(((ObjectClassField_Type) ocft).getObjectClassFieldName());
                    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    ObjectSet_definition osdef1 = tableConstraint.objectSet.getRefdLast(timestamp, chain);
                    chain.release();
                    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final ObjectSet_definition osdef2 = objectSet.getRefdLast(timestamp, chain);
                    chain.release();
                    if (osdef1 == osdef2) {
                        ok = true;
                    } else {
                        ok = false;
                    }
                }
            }
        }
        if (!ok) {
            myType.getLocation().reportSemanticError(SAMECONSTRAINTEXPECTED);
            return;
        }
    }
    if (objectSet instanceof Referenced_ObjectSet) {
        final Identifier objectSetId = ((Referenced_ObjectSet) objectSet).getId();
        collectTypesOfOpenType(timestamp, objectSet, openType, objectSetId);
    } else {
        // TODO: is it posssible? Perhaps log error!
        return;
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) AtNotation(org.eclipse.titan.designer.AST.AtNotation) ObjectSet_definition(org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition) ObjectClassField_Type(org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) Constraint(org.eclipse.titan.designer.AST.Constraint) IType(org.eclipse.titan.designer.AST.IType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Identifier(org.eclipse.titan.designer.AST.Identifier) Constraints(org.eclipse.titan.designer.AST.Constraints) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Referenced_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) FieldName(org.eclipse.titan.designer.AST.ASN1.Object.FieldName)

Example 7 with BridgingNamedNode

use of org.eclipse.titan.designer.AST.BridgingNamedNode in project titan.EclipsePlug-ins by eclipse.

the class SubType method addTtcnSingle.

/**
 * add TTCN-3 single value sub-type constraint to this sub-type
 */
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
    value.setMyScope(myOwner.getMyScope());
    value.setMyGovernor(myOwner);
    final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
    value.setFullNameParent(bridge);
    IValue last = myOwner.checkThisValueRef(timestamp, value);
    // check if this is type reference, if not then fall through
    final IValue refValue = value.setLoweridToReference(timestamp);
    // Value_type.REFERENCED_VALUE);
    if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
        final Reference ref = ((Referenced_Value) refValue).getReference();
        final Assignment ass = ref.getRefdAssignment(timestamp, false);
        if (ass == null) {
            // definition was not found, error was reported
            return false;
        }
        if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
            IType t = ass.getType(timestamp);
            t.check(timestamp);
            if (t.getIsErroneous(timestamp)) {
                return false;
            }
            final List<ISubReference> subrefs = ref.getSubreferences();
            if (subrefs.size() > 1) {
                // if there were sub-references then get the referenced field's type
                t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                if ((t == null) || t.getIsErroneous(timestamp)) {
                    return false;
                }
                t.check(timestamp);
                if (t.getIsErroneous(timestamp)) {
                    return false;
                }
            }
            if (!t.isIdentical(timestamp, myOwner)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
                return false;
            }
            // check subtype of referenced type
            final SubType tSt = t.getSubtype();
            if ((tSt == null) || (tSt.subtypeConstraint == null)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
                return false;
            }
            // check circular sub-type reference
            if (!addParentSubtype(tSt)) {
                return false;
            }
            if (tSt.getIsErroneous(timestamp)) {
                return false;
            }
            if (tSt.subtypeType != subtypeType) {
                ErrorReporter.INTERNAL_ERROR();
                return false;
            }
            // add the sub-type as union
            if (subtypeConstraint == null) {
                subtypeConstraint = tSt.subtypeConstraint;
            } else {
                subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
            }
            return true;
        }
    }
    myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    last = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
        return false;
    }
    // create a single value constraint
    SubtypeConstraint sc;
    switch(subtypeType) {
        case ST_INTEGER:
            sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case ST_FLOAT:
            sc = new RealRangeListConstraint(((Real_Value) last).getValue());
            break;
        case ST_BOOLEAN:
            sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
            break;
        case ST_VERDICTTYPE:
            sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
            break;
        case ST_BITSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
            break;
        case ST_HEXSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
            break;
        case ST_OCTETSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
            break;
        case ST_CHARSTRING:
            if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
                return false;
            }
            sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
            break;
        case ST_UNIVERSAL_CHARSTRING:
            switch(last.getValuetype()) {
                case CHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
                    break;
                case UNIVERSALCHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
                    break;
                default:
                    return false;
            }
            break;
        case ST_OBJID:
        case ST_ENUM:
        case ST_UNION:
        case ST_RECORD:
        case ST_SET:
        case ST_FUNCTION:
        case ST_ALTSTEP:
        case ST_TESTCASE:
            sc = new ValueListConstraint(last);
            break;
        case ST_RECORDOF:
        case ST_SETOF:
            sc = new ValueListAndSizeConstraint(last);
            break;
        default:
            ErrorReporter.INTERNAL_ERROR();
            return false;
    }
    // add next value using union operation
    if (subtypeConstraint == null) {
        subtypeConstraint = sc;
    } else {
        subtypeConstraint = subtypeConstraint.union(sc);
    }
    return true;
}
Also used : IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference)

Example 8 with BridgingNamedNode

use of org.eclipse.titan.designer.AST.BridgingNamedNode in project titan.EclipsePlug-ins by eclipse.

the class SubType method addTtcnRange.

private boolean addTtcnRange(final CompilationTimeStamp timestamp, final Value min, final boolean minExclusive, final Value max, final boolean maxExclusive, final int restrictionIndex) {
    switch(subtypeType) {
        case ST_INTEGER:
        case ST_FLOAT:
        case ST_CHARSTRING:
        case ST_UNIVERSAL_CHARSTRING:
            break;
        default:
            myOwner.getLocation().reportSemanticError(MessageFormat.format("Range subtyping is not allowed for type `{0}''", myOwner.getTypename()));
            return false;
    }
    if (min == null || max == null) {
        return false;
    }
    IValue vmin = null, vmax = null;
    min.setMyScope(myOwner.getMyScope());
    min.setMyGovernor(myOwner);
    BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<range_restriction_" + restrictionIndex + "_lower>");
    min.setFullNameParent(bridge);
    IValue last = myOwner.checkThisValueRef(timestamp, min);
    IType lastOwner = myOwner.getTypeRefdLast(timestamp);
    if (lastOwner instanceof Integer_Type) {
        ((Integer_Type) lastOwner).checkThisValueLimit(timestamp, last, Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false);
    } else {
        myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    }
    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    vmin = last.getValueRefdLast(timestamp, chain);
    chain.release();
    max.setMyScope(myOwner.getMyScope());
    max.setMyGovernor(myOwner);
    bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<range_restriction_" + restrictionIndex + "_upper>");
    max.setFullNameParent(bridge);
    last = myOwner.checkThisValueRef(timestamp, max);
    lastOwner = myOwner.getTypeRefdLast(timestamp);
    if (lastOwner instanceof Integer_Type) {
        ((Integer_Type) lastOwner).checkThisValueLimit(timestamp, last, Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false);
    } else {
        myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    }
    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    vmax = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (vmin.getIsErroneous(timestamp) || vmin.isUnfoldable(timestamp)) {
        // the error was already reported
        return false;
    }
    if (vmax.getIsErroneous(timestamp) || vmax.isUnfoldable(timestamp)) {
        // the error was already reported
        return false;
    }
    SubtypeConstraint rangeConstraint;
    switch(subtypeType) {
        case ST_INTEGER:
            {
                IntegerLimit minLimit;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype())) {
                    final Real_Value real = (Real_Value) vmin;
                    if (real.isNegativeInfinity()) {
                        minLimit = IntegerLimit.MINIMUM;
                    } else {
                        minLimit = IntegerLimit.MAXIMUM;
                    }
                } else {
                    minLimit = new IntegerLimit(((Integer_Value) vmin).getValueValue());
                }
                IntegerLimit maxLimit;
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype())) {
                    final Real_Value real = (Real_Value) vmax;
                    if (real.isPositiveInfinity()) {
                        maxLimit = IntegerLimit.MAXIMUM;
                    } else {
                        maxLimit = IntegerLimit.MINIMUM;
                    }
                } else {
                    maxLimit = new IntegerLimit(((Integer_Value) vmax).getValueValue());
                }
                if (minExclusive) {
                    if (minLimit.compareTo(IntegerLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("invalid lower boundary, -infinity cannot be excluded from an integer subtype range");
                        return false;
                    }
                    if (minLimit.compareTo(IntegerLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!infinity is not a valid lower boundary");
                        return false;
                    }
                    minLimit = (IntegerLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(IntegerLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("invalid upper boundary, infinity cannot be excluded from an integer subtype range");
                        return false;
                    }
                    if (maxLimit.compareTo(IntegerLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!-infinity is not a valid upper boundary");
                        return false;
                    }
                    maxLimit = (IntegerLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in integer subtype range");
                    return false;
                }
                rangeConstraint = new RangeListConstraint(minLimit, maxLimit);
                break;
            }
        case ST_FLOAT:
            {
                if (Double.isNaN(((Real_Value) vmin).getValue())) {
                    min.getLocation().reportSemanticError("lower boundary cannot be not_a_number in float subtype range");
                    return false;
                }
                if (Double.isNaN(((Real_Value) vmax).getValue())) {
                    max.getLocation().reportSemanticError("upper boundary cannot be not_a_number in float subtype range");
                    return false;
                }
                RealLimit minLimit = new RealLimit(((Real_Value) vmin).getValue());
                RealLimit maxLimit = new RealLimit(((Real_Value) vmax).getValue());
                if (minExclusive) {
                    if (minLimit.compareTo(RealLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!infinity is not a valid lower boundary");
                        return false;
                    }
                    minLimit = (RealLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(RealLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!-infinity is not a valid upper boundary");
                        return false;
                    }
                    maxLimit = (RealLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in float subtype range");
                    return false;
                }
                rangeConstraint = new RealRangeListConstraint(minLimit, maxLimit);
                break;
            }
        case ST_CHARSTRING:
            {
                boolean erroneous = false;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype()) && ((Real_Value) vmin).isNegativeInfinity()) {
                    getParsedLocation().reportSemanticError("lower boundary of a charstring subtype range cannot be -infinity");
                    erroneous = true;
                }
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype()) && ((Real_Value) vmax).isPositiveInfinity()) {
                    getParsedLocation().reportSemanticError("upper boundary of a charstring subtype range cannot be infinity");
                    erroneous = true;
                }
                if (erroneous) {
                    return false;
                }
                String minString;
                switch(vmin.getValuetype()) {
                    case CHARSTRING_VALUE:
                        minString = ((Charstring_Value) vmin).getValue();
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        {
                            final UniversalCharstring ustr = ((UniversalCharstring_Value) vmin).getValue();
                            if ((ustr.length() < 1) || !ustr.get(0).isValidChar()) {
                                min.getLocation().reportSemanticError("lower boundary of charstring subtype range is not a valid char");
                                return false;
                            }
                            minString = String.valueOf((char) ustr.get(0).cell());
                            break;
                        }
                    default:
                        return false;
                }
                String maxString;
                switch(vmax.getValuetype()) {
                    case CHARSTRING_VALUE:
                        maxString = ((Charstring_Value) vmax).getValue();
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        {
                            final UniversalCharstring ustr = ((UniversalCharstring_Value) vmax).getValue();
                            if ((ustr.length() < 1) || !ustr.get(0).isValidChar()) {
                                max.getLocation().reportSemanticError("upper boundary of charstring subtype range is not a valid char");
                                return false;
                            }
                            maxString = String.valueOf((char) ustr.get(0).cell());
                            break;
                        }
                    default:
                        return false;
                }
                if (minString.length() != 1) {
                    min.getLocation().reportSemanticError("lower boundary of charstring subtype range must be a single element string");
                    return false;
                }
                if (maxString.length() != 1) {
                    max.getLocation().reportSemanticError("upper boundary of charstring subtype range must be a single element string");
                    return false;
                }
                CharLimit minLimit = new CharLimit(minString.charAt(0));
                CharLimit maxLimit = new CharLimit(maxString.charAt(0));
                if (minExclusive) {
                    if (minLimit.compareTo(CharLimit.MAXIMUM) == 0) {
                        min.getLocation().reportSemanticError("exclusive lower boundary is not a legal charstring character");
                        return false;
                    }
                    minLimit = (CharLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(CharLimit.MINIMUM) == 0) {
                        max.getLocation().reportSemanticError("exclusive upper boundary is not a legal charstring character");
                        return false;
                    }
                    maxLimit = (CharLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in charstring subtype range");
                    return false;
                }
                rangeConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.ALPHABET_CONSTRAINT, new RangeListConstraint(minLimit, maxLimit));
                break;
            }
        case ST_UNIVERSAL_CHARSTRING:
            {
                boolean erroneous = false;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype()) && ((Real_Value) vmin).isNegativeInfinity()) {
                    min.getLocation().reportSemanticError("lower boundary of a universal charstring subtype range cannot be -infinity");
                    erroneous = true;
                }
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype()) && ((Real_Value) vmax).isPositiveInfinity()) {
                    max.getLocation().reportSemanticError("upper boundary of a universal charstring subtype range cannot be infinity");
                    erroneous = true;
                }
                if (erroneous) {
                    return false;
                }
                UniversalCharstring minString;
                switch(vmin.getValuetype()) {
                    case CHARSTRING_VALUE:
                        minString = new UniversalCharstring(((Charstring_Value) vmin).getValue());
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        minString = ((UniversalCharstring_Value) vmin).getValue();
                        break;
                    default:
                        return false;
                }
                UniversalCharstring maxString;
                switch(vmax.getValuetype()) {
                    case CHARSTRING_VALUE:
                        maxString = new UniversalCharstring(((Charstring_Value) vmax).getValue());
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        maxString = ((UniversalCharstring_Value) vmax).getValue();
                        break;
                    default:
                        return false;
                }
                if (minString.length() != 1) {
                    min.getLocation().reportSemanticError("lower boundary of universal charstring subtype range must be a single element string");
                    return false;
                }
                if (maxString.length() != 1) {
                    max.getLocation().reportSemanticError("upper boundary of universal charstring subtype range must be a single element string");
                    return false;
                }
                UCharLimit minLimit = new UCharLimit(minString.get(0));
                UCharLimit maxLimit = new UCharLimit(maxString.get(0));
                if (minExclusive) {
                    if (minLimit.compareTo(UCharLimit.MAXIMUM) == 0) {
                        min.getLocation().reportSemanticError("exclusive lower boundary is not a legal universal charstring character");
                        return false;
                    }
                    minLimit = (UCharLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(UCharLimit.MINIMUM) == 0) {
                        max.getLocation().reportSemanticError("exclusive upper boundary is not a legal universal charstring character");
                        return false;
                    }
                    maxLimit = (UCharLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in universal charstring subtype range");
                    return false;
                }
                rangeConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.ALPHABET_CONSTRAINT, new RangeListConstraint(minLimit, maxLimit));
                break;
            }
        default:
            ErrorReporter.INTERNAL_ERROR();
            return false;
    }
    subtypeConstraint = (subtypeConstraint == null) ? rangeConstraint : subtypeConstraint.union(rangeConstraint);
    return true;
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) PatternString(org.eclipse.titan.designer.AST.TTCN3.templates.PatternString) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 9 with BridgingNamedNode

use of org.eclipse.titan.designer.AST.BridgingNamedNode 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 10 with BridgingNamedNode

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

Aggregations

BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)15 IType (org.eclipse.titan.designer.AST.IType)13 IValue (org.eclipse.titan.designer.AST.IValue)10 ISubReference (org.eclipse.titan.designer.AST.ISubReference)8 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)8 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)7 Identifier (org.eclipse.titan.designer.AST.Identifier)7 Value (org.eclipse.titan.designer.AST.Value)6 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)4 Assignment (org.eclipse.titan.designer.AST.Assignment)4 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)2 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)2