Search in sources :

Example 1 with Referenced_ObjectSet

use of org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet 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 2 with Referenced_ObjectSet

use of org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet in project titan.EclipsePlug-ins by eclipse.

the class ObjectSetElementVisitor_objectCollector method visitObjectSet.

public void visitObjectSet(final ObjectSet p, final boolean force) {
    if (governor == null || p == null) {
        return;
    }
    final ObjectClass myClass = governor.getRefdLast(timestamp, null);
    ObjectClass refdClass = null;
    if (p instanceof Referenced_ObjectSet) {
        refdClass = ((Referenced_ObjectSet) p).getRefdObjectClass(timestamp);
    }
    if (myClass != refdClass && myClass != null && refdClass != null) {
        p.getLocation().reportSemanticError(MessageFormat.format(OBJECTOFCLASSEXPECTED, myClass.getFullName(), p.getFullName(), refdClass.getFullName()));
        return;
    }
    final ObjectSet_definition os = p.getRefdLast(timestamp, null);
    if (visitedElements.contains(os)) {
        if (!force) {
            return;
        }
    } else {
        visitedElements.add(os);
    }
    // ^Par ref ^^^^^^ObjectSet
    if (((Referenced_ObjectSet) p).isReferencedParameterisedReference()) {
        return;
    }
    // TODO: check this!
    if (((Referenced_ObjectSet) p).isReferencedDefinedReference()) {
        return;
    }
    final ASN1Objects otherObjects = os.getObjs();
    otherObjects.trimToSize();
    for (int i = 0; i < otherObjects.getNofObjects(); i++) {
        visitObject(otherObjects.getObjectByIndex(i));
    }
}
Also used : ObjectClass(org.eclipse.titan.designer.AST.ASN1.ObjectClass)

Example 3 with Referenced_ObjectSet

use of org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet in project titan.EclipsePlug-ins by eclipse.

the class ObjectSet_definition method getRefdLast.

@Override
public final /**
 * {@inheritDoc}
 */
ObjectSet_definition getRefdLast(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (1 != objectSetElements.size()) {
        return this;
    }
    final IObjectSet_Element element = objectSetElements.get(0);
    if (!(element instanceof Referenced_ObjectSet)) {
        return this;
    }
    final boolean newChain = null == referenceChain;
    IReferenceChain temporalReferenceChain;
    if (newChain) {
        temporalReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        temporalReferenceChain = referenceChain;
    }
    temporalReferenceChain.add(this);
    final ObjectSet_definition result = ((Referenced_ObjectSet) element).getRefdLast(timestamp, temporalReferenceChain);
    if (newChain) {
        temporalReferenceChain.release();
    }
    return result;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IObjectSet_Element(org.eclipse.titan.designer.AST.ASN1.IObjectSet_Element)

Example 4 with Referenced_ObjectSet

use of org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet in project titan.EclipsePlug-ins by eclipse.

the class TableConstraint method collectTypesOfOpenType.

private void collectTypesOfOpenType(final CompilationTimeStamp aTimestamp, ObjectSet aObjectSet, final Open_Type aOpenType, final Identifier aObjectSetId) {
    if (aObjectSet instanceof Referenced_ObjectSet) {
        if (((Referenced_ObjectSet) aObjectSet).isReferencedDefinedReference()) {
            aObjectSet = aObjectSet.getRefdLast(aTimestamp, null);
        } else if (((Referenced_ObjectSet) aObjectSet).isReferencedInformationFromObj()) {
            // TODO: How to handle this?
            return;
        } else {
            // impossible, try it
            return;
        }
    }
    // now aObjectSet is instanceof ObjectSet_definition:
    List<IObjectSet_Element> oses = ((ObjectSet_definition) aObjectSet).getObjectSetElements();
    for (IObjectSet_Element ose : oses) {
        if (ose instanceof ReferencedObject) {
            // fspec
            ose = ((ReferencedObject) ose).getRefdLast(aTimestamp);
        }
        if (ose instanceof Object_Definition) {
            final Object_Definition od = (Object_Definition) ose;
            FieldSetting fs = od.getFieldSettingWithNameDefault(objectClassFieldname, false);
            if (fs != null) {
                // TODO: handle FieldSetting options: FieldSetting_Type, FieldSetting_ObjectSet, FieldSetting_Value
                if (fs instanceof FieldSetting_Type) {
                    final FieldSetting_Type fst = (FieldSetting_Type) fs;
                    final IASN1Type type = fst.getSetting();
                    final AtomicBoolean isStrange = new AtomicBoolean();
                    Identifier id = getOpenTypeAlternativeName(aTimestamp, (Type) type, isStrange);
                    if (!aOpenType.hasComponentWithName(id)) {
                        aOpenType.addComponent(new CompField(id, (Type) type, false, null));
                        if (isStrange.get()) {
                            aOpenType.getLocation().reportSemanticWarning(MessageFormat.format("Strange alternative name (`{0}') was added to open type `{1}'", id.getDisplayName(), aOpenType.getFullName()));
                        }
                    }
                } else {
                    // TODO: is it possible FieldSetting_ObjectSet, FieldSetting_Value ??
                    continue;
                }
            } else {
                fs = od.getFieldSettingWithNameDefault(aObjectSetId, false);
                if (fs == null) {
                    continue;
                }
                if (fs instanceof FieldSetting_ObjectSet) {
                    final ISetting objectSet1 = fs.getSetting();
                    ObjectSet objectSet2;
                    if (objectSet1 instanceof ObjectSet) {
                        objectSet2 = (ObjectSet) objectSet1;
                    } else {
                        // unexpected case
                        continue;
                    }
                    if (objectSet2 == aObjectSet) {
                        // to prevent infinite loop
                        continue;
                    }
                    collectTypesOfOpenType(aTimestamp, objectSet2, aOpenType, aObjectSetId);
                } else {
                    // TODO: is it possible??
                    continue;
                }
            }
        }
    }
    // for
    aOpenType.check(aTimestamp);
}
Also used : FieldSetting_Type(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_Type) ObjectSet_definition(org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition) FieldSetting_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_ObjectSet) ISetting(org.eclipse.titan.designer.AST.ISetting) Referenced_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet) FieldSetting_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_ObjectSet) FieldSetting(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) FieldSetting_Type(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) ObjectClassField_Type(org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Object_Definition(org.eclipse.titan.designer.AST.ASN1.Object.Object_Definition) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) ReferencedObject(org.eclipse.titan.designer.AST.ASN1.Object.ReferencedObject) Referenced_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet)

Aggregations

ObjectSet_definition (org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition)2 Referenced_ObjectSet (org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet)2 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)2 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)2 ObjectClassField_Type (org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 IType (org.eclipse.titan.designer.AST.IType)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)2 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)2 TTCN3_Set_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IObjectSet_Element (org.eclipse.titan.designer.AST.ASN1.IObjectSet_Element)1 FieldName (org.eclipse.titan.designer.AST.ASN1.Object.FieldName)1 FieldSetting (org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting)1 FieldSetting_ObjectSet (org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_ObjectSet)1