Search in sources :

Example 31 with IReferenceChain

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

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

the class TableConstraint method getOpenTypeAlternativeName.

// Original titan.core version: t_type->get_otaltname(is_strange);
private Identifier getOpenTypeAlternativeName(final CompilationTimeStamp timestamp, final Type type, final AtomicBoolean isStrange) {
    StringBuffer sb = new StringBuffer();
    // TODO:  if (is_tagged() || is_constrained() || hasRawAttrs()) {
    if (!type.getIsErroneous(timestamp) && type.isConstrained()) {
        sb.append(type.getGenNameOwn());
        isStrange.set(true);
    } else if (!type.getIsErroneous(timestamp) && type instanceof Referenced_Type) {
        Reference t_ref = ((Referenced_Type) type).getReference();
        if (t_ref != null) {
            final Identifier id = t_ref.getId();
            final String dn = id.getDisplayName();
            int i = dn.indexOf('.');
            if (i >= 0 && i < dn.length()) {
                // id is not regular because t_ref is a parameterized reference
                sb.append(id.getName());
                isStrange.set(true);
            } else {
                Assignment as = t_ref.getRefdAssignment(timestamp, true);
                if (as == null) {
                    return null;
                }
                Scope assScope = as.getMyScope();
                if (assScope.getParentScope() == assScope.getModuleScope()) {
                    sb.append(id.getName());
                    isStrange.set(false);
                } else {
                    // t_ref is a dummy reference in a parameterized assignment
                    // (i.e. it points to a parameter assignment of an instantiation)
                    // perform the same examination recursively on the referenced type
                    // (which is the actual parameter)
                    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
                    chain.release();
                    return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
                }
            }
        } else {
            // the type comes from an information object [class]
            // examine the referenced type recursively
            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
            chain.release();
            return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
        }
    } else {
        Identifier tmpId1 = new Identifier(Identifier_type.ID_NAME, type.getFullName());
        String s = tmpId1.getDisplayName();
        // module name will be cut off:
        if (s.startsWith("@") && s.indexOf('.') > 0) {
            s = s.substring(s.indexOf('.') + 1);
        }
        Identifier tmpId2 = new Identifier(Identifier_type.ID_ASN, s);
        sb.append(tmpId2.getTtcnName());
    }
    // conversion to lower case initial:
    sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
    // trick:
    Identifier tmpId = new Identifier(Identifier_type.ID_NAME, sb.toString());
    return new Identifier(Identifier_type.ID_ASN, tmpId.getAsnName());
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) 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) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 33 with IReferenceChain

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

the class Type_Assignment method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != assPard) {
        assPard.check(timestamp);
        return;
    }
    checkTTCNIdentifier();
    if (null != type) {
        type.setGenName(getGenName());
        type.check(timestamp);
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        type.checkRecursions(timestamp, referenceChain);
        referenceChain.release();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 34 with IReferenceChain

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

the class Undefined_Assignment_OS_or_VS method classifyAssignment.

@Override
protected void classifyAssignment(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain temporalReferenceChain;
    if (newChain) {
        temporalReferenceChain = ReferenceChain.getInstance(CIRCULARASSIGNMENTCHAIN, true);
    } else {
        temporalReferenceChain = referenceChain;
        temporalReferenceChain.markState();
    }
    realAssignment = null;
    if (temporalReferenceChain.add(this)) {
        if (null != reference) {
            reference.setMyScope(getMyScope());
            if (!reference.refersToSettingType(timestamp, Setting_type.S_ERROR, temporalReferenceChain)) {
                if (identifier.isvalidAsnObjectSetReference() && reference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
                    final ObjectClass_refd oc = new ObjectClass_refd(reference);
                    oc.setLocation(reference.getLocation());
                    realAssignment = new ObjectSet_Assignment(identifier, assPard, oc, newObjectSetDefinitionInstance());
                // assPard = null;
                // left = null;
                // right = null;
                // asstype = A_OS;
                } else if (identifier.isvalidAsnValueSetReference() && (reference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || reference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
                    final Referenced_Type type = new Referenced_Type(reference);
                    type.setLocation(reference.getLocation());
                    realAssignment = newValueSetAssignmentInstance(type);
                // left = null;
                // right = null;
                // asstype = A_VS;
                }
            }
        }
    }
    if (null == realAssignment) {
        location.reportSemanticError(UNRECOGNISABLEASSIGNMENT);
        isErroneous = true;
    } else {
        realAssignment.setLocation(location);
        realAssignment.setMyScope(myScope);
        realAssignment.setRightScope(rightScope);
        realAssignment.setFullNameParent(this);
    }
    if (newChain) {
        temporalReferenceChain.release();
    } else {
        temporalReferenceChain.previousState();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ObjectClass_refd(org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_refd) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 35 with IReferenceChain

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

the class Undefined_Assignment_T_or_OC method classifyAssignment.

@Override
protected void classifyAssignment(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain temporalReferenceChain;
    if (newChain) {
        temporalReferenceChain = ReferenceChain.getInstance(CIRCULARASSIGNMENTCHAIN, true);
    } else {
        temporalReferenceChain = referenceChain;
        temporalReferenceChain.markState();
    }
    realAssignment = null;
    if (temporalReferenceChain.add(this)) {
        reference.setMyScope(rightScope);
        if (identifier.isvalidAsnObjectClassReference() && reference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
            final ObjectClass_refd oc = new ObjectClass_refd(reference);
            oc.setLocation(reference.getLocation());
            realAssignment = new ObjectClass_Assignment(identifier, assPard, oc);
        // assPard = null;
        // asstype = Assignment.A_OC;
        } else if (identifier.isvalidAsnTyperef() && (reference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || reference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
            final Referenced_Type type = new Referenced_Type(reference);
            type.setLocation(reference.getLocation());
            realAssignment = new Type_Assignment(identifier, assPard, type);
        // assPard = null;
        // asstype = A_TYPE;
        }
    }
    if (null == realAssignment) {
        location.reportSemanticError(UNRECOGNISABLEASSIGNMENT);
        isErroneous = true;
    } else {
        realAssignment.setLocation(location);
        realAssignment.setMyScope(myScope);
        realAssignment.setRightScope(rightScope);
        realAssignment.setFullNameParent(this);
    }
    if (newChain) {
        temporalReferenceChain.release();
    } else {
        temporalReferenceChain.previousState();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ObjectClass_refd(org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_refd) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)154 IValue (org.eclipse.titan.designer.AST.IValue)102 IType (org.eclipse.titan.designer.AST.IType)55 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)18 Value (org.eclipse.titan.designer.AST.Value)18 Assignment (org.eclipse.titan.designer.AST.Assignment)16 BigInteger (java.math.BigInteger)15 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)14 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)13 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Reference (org.eclipse.titan.designer.AST.Reference)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)7 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)7 HashMap (java.util.HashMap)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)5