Search in sources :

Example 1 with FieldName

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

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

the class Referenced_ObjectSet method getRefdObjectClass.

/**
 * Returns the referenced ObjectClass. The evaluation depends on the type of the reference
 * @param timestamp
 * @return the referenced ObjectClass if found. Otherwise returns null.
 */
public ObjectClass getRefdObjectClass(final CompilationTimeStamp timestamp) {
    ObjectClass refdClass = null;
    if (reference instanceof InformationFromObj) {
        final ObjectClass tempGovernor = getRefdLast(timestamp, null).getMyGovernor();
        if (tempGovernor == null) {
            return null;
        }
        refdClass = tempGovernor.getRefdLast(timestamp, null);
        final FieldName fn = ((InformationFromObj) reference).getFieldName();
        if (fn.getNofFields() == 1) {
            final Identifier fieldId = fn.getFieldByIndex(0);
            final FieldSpecifications fss = refdClass.getFieldSpecifications();
            FieldSpecification fs = fss.getFieldSpecificationByIdentifier(fieldId);
            if (fs instanceof Undefined_FieldSpecification) {
                fs = ((Undefined_FieldSpecification) fs).getRealFieldSpecification();
            }
            switch(fs.getFieldSpecificationType()) {
                case FS_OS:
                    refdClass = ((ObjectSet_FieldSpecification) fs).getObjectClass().getRefdLast(timestamp, null);
                    break;
                case FS_T:
                    // TODO: implement the other cases
                    break;
                default:
                    // TODO: implement the other cases
                    break;
            }
        }
    } else if (reference instanceof Parameterised_Reference) {
        final Defined_Reference dref = ((Parameterised_Reference) reference).getRefDefdSimple();
        if (dref == null) {
            return null;
        }
        final Assignment ass = dref.getRefdAssignment(timestamp, false, null);
        if (ass instanceof ObjectSet_Assignment) {
            ass.check(timestamp);
            // experimental
            osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
            refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
        }
    } else if (reference instanceof Defined_Reference) {
        final Assignment ass = ((Defined_Reference) reference).getRefdAssignment(timestamp, false, null);
        if (ass instanceof ObjectSet_Assignment) {
            ass.check(timestamp);
            // experimental
            osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
            refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
        }
    } else {
        // to debug
        return refdClass;
    }
    return refdClass;
}
Also used : ObjectSet_Assignment(org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) ObjectClass(org.eclipse.titan.designer.AST.ASN1.ObjectClass) Identifier(org.eclipse.titan.designer.AST.Identifier) Parameterised_Reference(org.eclipse.titan.designer.AST.ASN1.Parameterised_Reference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) ObjectSet_Assignment(org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment) InformationFromObj(org.eclipse.titan.designer.AST.ASN1.InformationFromObj)

Example 3 with FieldName

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

the class CompFieldMap method checkUniqueness.

/**
 * Checks the uniqueness of the definitions, and also builds a hashmap of
 * them to speed up further searches.
 *
 * @param timestamp the timestamp of the actual semantic check cycle, or -1
 *            in silent check mode.
 */
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (lastUniquenessCheck != null && !lastUniquenessCheck.isLess(timestamp)) {
        return;
    }
    if (doubleComponents != null) {
        doubleComponents.clear();
    }
    componentFieldMap = new HashMap<String, CompField>(fields.size());
    if (fields.size() == 0) {
        // too early check
        return;
    }
    lastUniquenessCheck = timestamp;
    for (int i = 0, size = fields.size(); i < size; i++) {
        final CompField field = fields.get(i);
        final Identifier fieldIdentifier = field.getIdentifier();
        if (fieldIdentifier == null) {
            continue;
        }
        final String fieldName = fieldIdentifier.getName();
        if (componentFieldMap.containsKey(fieldName)) {
            if (doubleComponents == null) {
                doubleComponents = new ArrayList<CompField>();
            }
            doubleComponents.add(field);
        } else {
            componentFieldMap.put(fieldName, field);
        }
    }
    // FIXME: Perhaps this class should be copied under asn1 to handle this ASN1 problem
    if (doubleComponents != null) {
        final INamedNode p = getNameParent();
        if (p instanceof Open_Type) {
            return;
        }
        for (int i = 0, size = doubleComponents.size(); i < size; i++) {
            final CompField field = doubleComponents.get(i);
            // remove duplication from fields - not used anymore
            // fields.remove(field);
            // report duplication:
            final Identifier fieldIdentifier = field.getIdentifier();
            final String fieldName = fieldIdentifier.getName();
            componentFieldMap.get(fieldName).getIdentifier().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEFIRST, fieldIdentifier.getDisplayName()));
            fieldIdentifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEREPEATED, fieldIdentifier.getDisplayName()));
        }
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Identifier(org.eclipse.titan.designer.AST.Identifier) INamedNode(org.eclipse.titan.designer.AST.INamedNode)

Example 4 with FieldName

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

the class TTCN3_Set_Seq_Choice_BaseType method checkSetSeqRawCodingAttributes.

/**
 * Check the raw coding attributes of TTCN3 record and set types.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 */
protected void checkSetSeqRawCodingAttributes(final CompilationTimeStamp timestamp) {
    // check raw attributes
    if (rawAttribute != null) {
        if (rawAttribute.taglist != null) {
            for (int c = 0; c < rawAttribute.taglist.size(); c++) {
                final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
                final Identifier fieldname = singleTag.fieldName;
                if (!hasComponentWithName(fieldname.getName())) {
                    fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
                    continue;
                }
                if (singleTag.keyList != null) {
                    for (int a = 0; a < singleTag.keyList.size(); a++) {
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(fieldname));
                        for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
                            reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
                        }
                        final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                        if (t != null) {
                            final Value v = singleTag.keyList.get(a).v_value;
                            if (v != null) {
                                v.setMyScope(getMyScope());
                                v.setMyGovernor(t);
                                final IValue tempValue = t.checkThisValueRef(timestamp, v);
                                t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                            }
                        }
                    }
                }
            }
        }
        if (rawAttribute.ext_bit_groups != null) {
            for (int a = 0; a < rawAttribute.ext_bit_groups.size(); a++) {
                final rawAST_ext_bit_group tempExtBitGroup = rawAttribute.ext_bit_groups.get(a);
                final Identifier fromIdentifier = tempExtBitGroup.from;
                final Identifier toIdentifier = tempExtBitGroup.to;
                boolean foundError = false;
                if (!hasComponentWithName(fromIdentifier.getName())) {
                    fromIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", fromIdentifier.getDisplayName(), getTypename()));
                    foundError = true;
                }
                if (!hasComponentWithName(toIdentifier.getName())) {
                    toIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", toIdentifier.getDisplayName(), getTypename()));
                    foundError = true;
                }
                if (!foundError) {
                    boolean foundStart = false;
                    for (int i = 0; i < getNofComponents(); i++) {
                        final Identifier tempId = getComponentByIndex(i).getIdentifier();
                        if (tempId.equals(fromIdentifier)) {
                            foundStart = true;
                        } else if (tempId.equals(toIdentifier)) {
                            if (!foundStart) {
                                getLocation().reportSemanticError(MessageFormat.format("Invalid field order in RAW parameter EXTENSION_BIT_GROUP for type `{0}'': `{1}'', `{2}''", getTypename(), fromIdentifier.getDisplayName(), toIdentifier.getDisplayName()));
                            }
                            break;
                        }
                    }
                }
            }
        }
        if (rawAttribute.paddall != RawAST.XDEFDEFAULT) {
            for (int i = 0; i < getNofComponents(); i++) {
                final CompField cField = getComponentByIndex(i);
                final Type fieldType = cField.getType();
                RawAST fieldRawAttribute = fieldType.rawAttribute;
                if (fieldRawAttribute == null) {
                    IType t = fieldType;
                    if (t instanceof Referenced_Type) {
                        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
                        referenceChain.release();
                    }
                    while (t.getRawAttribute() == null && t instanceof Referenced_Type) {
                        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
                        referenceChain.release();
                    }
                    fieldRawAttribute = new RawAST(t.getRawAttribute(), fieldType.getDefaultRawFieldLength());
                    fieldType.setRawAttributes(fieldRawAttribute);
                }
                if (fieldRawAttribute.padding == 0) {
                    fieldRawAttribute.padding = rawAttribute.padding;
                }
                if (fieldRawAttribute.prepadding == 0) {
                    fieldRawAttribute.prepadding = rawAttribute.prepadding;
                }
                if (fieldRawAttribute.padding_pattern_length == 0 && rawAttribute.padding_pattern_length > 0) {
                    fieldRawAttribute.padding_pattern = rawAttribute.padding_pattern;
                    fieldRawAttribute.padding_pattern_length = rawAttribute.padding_pattern_length;
                }
            }
        }
        if (rawAttribute.fieldorder != RawAST.XDEFDEFAULT) {
            for (int i = 0; i < getNofComponents(); i++) {
                final CompField cField = getComponentByIndex(i);
                final Type fieldType = cField.getType();
                RawAST fieldRawAttribute = fieldType.rawAttribute;
                if (fieldRawAttribute == null) {
                    fieldRawAttribute = new RawAST(fieldType.getDefaultRawFieldLength());
                    fieldType.setRawAttributes(fieldRawAttribute);
                }
                if (fieldRawAttribute.fieldorder == RawAST.XDEFDEFAULT) {
                    fieldRawAttribute.fieldorder = rawAttribute.fieldorder;
                }
            }
        }
    }
    if (rawAttribute != null && rawAttribute.presence != null) {
        if (rawAttribute.presence.keyList != null) {
            for (int a = 0; a < rawAttribute.presence.keyList.size(); a++) {
                final rawAST_tag_field_value tempTagFieldValue = rawAttribute.presence.keyList.get(a);
                final Reference reference = new Reference(null);
                reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
                for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
                    reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
                }
                final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                if (t != null) {
                    final Value v = tempTagFieldValue.v_value;
                    if (v != null) {
                        v.setMyScope(getMyScope());
                        v.setMyGovernor(t);
                        final IValue tempValue = t.checkThisValueRef(timestamp, v);
                        t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                    }
                }
            }
        }
    }
    // number of bits used to store all previous fields
    int usedBits = 0;
    for (int i = 0; i < getNofComponents(); i++) {
        final CompField cField = getComponentByIndex(i);
        final Type fieldType = cField.getType();
        fieldType.forceRaw(timestamp);
        final RawAST rawPar = fieldType.rawAttribute;
        if (rawPar != null) {
            final Identifier fieldId = cField.getIdentifier();
            final IType fieldTypeLast = fieldType.getTypeRefdLast(timestamp);
            if (rawPar.prepadding != 0) {
                usedBits = (usedBits + rawPar.prepadding - 1) / rawPar.prepadding * rawPar.prepadding;
            }
            if (rawPar.intX && fieldTypeLast.getTypetype() == Type_type.TYPE_INTEGER) {
                if (usedBits % 8 != 0 && (rawAttribute == null || rawAttribute.fieldorder != RawAST.XDEFMSB)) {
                    getLocation().reportSemanticError(MessageFormat.format("Using RAW parameter IntX in a record/set with FIELDORDER set to 'lsb' is only supported if the IntX field starts at the beginning of a new octet. There are {0} unused bits in the last octet before field {1}.", 8 - (usedBits % 8), fieldId.getDisplayName()));
                }
            } else if (rawPar.fieldlength > 0) {
                usedBits += rawPar.fieldlength;
            }
            if (rawPar.padding != 0) {
                usedBits = (usedBits + rawPar.padding - 1) / rawPar.padding * rawPar.padding;
            }
            if (rawPar.lengthto != null) {
                for (int j = 0; j < rawPar.lengthto.size(); j++) {
                    final Identifier id = rawPar.lengthto.get(j);
                    if (!hasComponentWithName(id.getName())) {
                        id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                    }
                }
            }
            if (rawPar.lengthto != null) {
                switch(fieldTypeLast.getTypetype()) {
                    case TYPE_INTEGER:
                    case TYPE_INTEGER_A:
                        break;
                    case TYPE_TTCN3_CHOICE:
                        for (int fi = 0; fi < ((TTCN3_Choice_Type) fieldTypeLast).getNofComponents(); fi++) {
                            final Type_type tt = ((TTCN3_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
                            if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
                                getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
                            }
                        }
                        break;
                    case TYPE_ASN1_CHOICE:
                        for (int fi = 0; fi < ((ASN1_Choice_Type) fieldTypeLast).getNofComponents(timestamp); fi++) {
                            final Type_type tt = ((ASN1_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
                            if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
                                getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
                            }
                        }
                        break;
                    case TYPE_ANYTYPE:
                    case TYPE_OPENTYPE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_ASN1_SEQUENCE:
                    case TYPE_TTCN3_SET:
                    case TYPE_ASN1_SET:
                        if (rawPar.lengthindex != null) {
                            // will be checked in the next step
                            break;
                        }
                    default:
                        getLocation().reportSemanticError(MessageFormat.format("The LENGTHTO field must be an integer or union type instead of `{0}''", fieldTypeLast.getTypename()));
                        break;
                }
            }
            if (rawPar.lengthto != null && rawPar.lengthindex != null) {
                final Identifier id = rawPar.lengthindex.names.get(0);
                switch(fieldTypeLast.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id.getName())) {
                            id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                        }
                        break;
                    case TYPE_ASN1_CHOICE:
                    case TYPE_ASN1_SEQUENCE:
                    case TYPE_ASN1_SET:
                        if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id)) {
                            id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                        }
                        break;
                    default:
                        fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter LENGTHINDEX for field {0}.", fieldId.getDisplayName()));
                        break;
                }
            }
            if (rawPar.pointerto != null) {
                final Identifier id = rawPar.pointerto;
                boolean errorFound = false;
                int pointed = 0;
                if (!hasComponentWithName(id.getName())) {
                    id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter POINTERTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                    errorFound = true;
                }
                if (!errorFound) {
                    pointed = getComponentIndexByName(id);
                    if (pointed <= i) {
                        id.getLocation().reportSemanticError(MessageFormat.format("Pointer must precede the pointed field. Incorrect field name `{0}'' in RAW parameter POINTERTO for field `{1}''", id.getDisplayName(), fieldId.getDisplayName()));
                        errorFound = true;
                    }
                }
                if (!errorFound && rawPar.ptrbase != null) {
                    final Identifier idf2 = rawPar.ptrbase;
                    if (!hasComponentWithName(idf2.getName())) {
                        idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
                        errorFound = true;
                    }
                    if (!errorFound && getComponentIndexByName(idf2) > pointed) {
                        idf2.getLocation().reportSemanticError(MessageFormat.format("Pointer base must precede the pointed field. Incorrect field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
                    }
                }
            }
            if (rawPar.presence != null && rawPar.presence.keyList != null) {
                for (int a = 0; a < rawPar.presence.keyList.size(); a++) {
                    final rawAST_tag_field_value tempTagFieldValue = rawPar.presence.keyList.get(a);
                    final Reference reference = new Reference(null);
                    reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
                    for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
                        reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
                    }
                    final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                    if (t != null) {
                        final Value v = tempTagFieldValue.v_value;
                        if (v != null) {
                            v.setMyScope(getMyScope());
                            v.setMyGovernor(t);
                            final IValue tempValue = t.checkThisValueRef(timestamp, v);
                            t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                        }
                    }
                }
            }
            if (rawPar.crosstaglist != null) {
                for (int c = 0; c < rawPar.crosstaglist.size(); c++) {
                    final rawAST_single_tag singleTag = rawPar.crosstaglist.get(c);
                    final Identifier idf = singleTag.fieldName;
                    switch(fieldTypeLast.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf.getName())) {
                                idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
                            }
                            break;
                        case TYPE_ASN1_CHOICE:
                        case TYPE_ASN1_SEQUENCE:
                        case TYPE_ASN1_SET:
                            if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf)) {
                                idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
                            }
                            break;
                        default:
                            fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
                            break;
                    }
                    if (singleTag.keyList != null) {
                        for (int a = 0; a < singleTag.keyList.size(); a++) {
                            IType t2 = this;
                            boolean errorFound = false;
                            boolean allow_omit = false;
                            final rawAST_tag_field_value tagField = singleTag.keyList.get(a);
                            for (int b = 0; b < tagField.keyField.names.size() && !errorFound; b++) {
                                final Identifier idf2 = tagField.keyField.names.get(b);
                                CompField cf2 = null;
                                switch(t2.getTypetype()) {
                                    case TYPE_TTCN3_CHOICE:
                                    case TYPE_TTCN3_SEQUENCE:
                                    case TYPE_TTCN3_SET:
                                        if (!((TTCN3_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2.getName())) {
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
                                            errorFound = true;
                                        } else {
                                            cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2.getName());
                                        }
                                        break;
                                    case TYPE_ASN1_CHOICE:
                                    case TYPE_ASN1_SEQUENCE:
                                    case TYPE_ASN1_SET:
                                        if (!((ASN1_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2)) {
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
                                            errorFound = true;
                                        } else {
                                            cf2 = ((ASN1_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2);
                                        }
                                        break;
                                    default:
                                        fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
                                        errorFound = true;
                                        break;
                                }
                                if (b == 0) {
                                    final int fieldIndex = getComponentIndexByName(idf2);
                                    if (fieldIndex == i) {
                                        idf2.getLocation().reportSemanticError(MessageFormat.format("RAW parameter CROSSTAG for field `{0}'' cannot refer to the field itself", idf2.getDisplayName()));
                                        errorFound = true;
                                    } else if (fieldIndex > i) {
                                        if (cField.isOptional()) {
                                            // TODO || fieldType.getRawLength() < 0
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' that CROSSTAG refers to must precede field `{1}'' or field `{1}'' must be mandatory with fixed length", idf2.getDisplayName(), fieldId.getDisplayName()));
                                            errorFound = true;
                                        }
                                    }
                                }
                                if (!errorFound) {
                                    t2 = cf2.getType().getTypeRefdLast(timestamp);
                                    if (b == tagField.keyField.names.size() - 1 && cf2.isOptional()) {
                                        allow_omit = true;
                                    }
                                }
                            }
                            if (!errorFound) {
                                final Value v = singleTag.keyList.get(a).v_value;
                                if (v != null) {
                                    v.setMyScope(getMyScope());
                                    v.setMyGovernor(t2);
                                    final IValue tempValue = t2.checkThisValueRef(timestamp, v);
                                    t2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, allow_omit, false, false, false));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Reference(org.eclipse.titan.designer.AST.Reference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) RawAST.rawAST_ext_bit_group(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_ext_bit_group) IType(org.eclipse.titan.designer.AST.IType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ASN1_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType) 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) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) RawAST.rawAST_tag_field_value(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_tag_field_value) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag)

Example 5 with FieldName

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

the class Named_Template_List method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    if (asValue != null) {
        asValue.generateCodeInit(aData, source, name);
        return;
    }
    if (myGovernor == null) {
        return;
    }
    // FIXME actually a bit more complex
    final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (type == null) {
        return;
    }
    if (namedTemplates.getNofTemplates() == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
    }
    // else is not needed as the loop will not run
    for (int i = 0; i < namedTemplates.getNofTemplates(); i++) {
        final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
        final String fieldName = namedTemplate.getName().getName();
        // FIXME handle needs_temp_ref case
        final String generatedFieldName = FieldSubReference.getJavaGetterName(fieldName);
        final TTCN3Template template = namedTemplate.getTemplate();
        if (template.needsTemporaryReference()) {
            Type fieldType;
            switch(type.getTypetype()) {
                case TYPE_SIGNATURE:
                    fieldType = ((Signature_Type) type).getParameterByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SEQUENCE:
                    fieldType = ((TTCN3_Sequence_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SET:
                    fieldType = ((TTCN3_Set_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_ASN1_SEQUENCE:
                    fieldType = ((ASN1_Sequence_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_SET:
                    fieldType = ((ASN1_Set_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_CHOICE:
                    fieldType = ((ASN1_Choice_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_TTCN3_CHOICE:
                    fieldType = ((TTCN3_Choice_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_OPENTYPE:
                    fieldType = ((Open_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ANYTYPE:
                    fieldType = ((Anytype_Type) type).getComponentByName(fieldName).getType();
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing named template list `" + getFullName() + "''");
                    return;
            }
            final String tempId = aData.getTemporaryVariableName();
            source.append("{\n");
            source.append(MessageFormat.format("{0} {1} = {2}.get{3}();\n", fieldType.getGenNameTemplate(aData, source, myScope), tempId, name, generatedFieldName));
            template.generateCodeInit(aData, source, tempId);
            source.append("}\n");
        } else {
            final String embeddedName = MessageFormat.format("{0}.get{1}()", name, generatedFieldName);
            template.generateCodeInit(aData, source, embeddedName);
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) 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) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) 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) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_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) 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)

Aggregations

Identifier (org.eclipse.titan.designer.AST.Identifier)5 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)3 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)3 IType (org.eclipse.titan.designer.AST.IType)3 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 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)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 Type (org.eclipse.titan.designer.AST.Type)2 Defined_Reference (org.eclipse.titan.designer.AST.ASN1.Defined_Reference)1 InformationFromObj (org.eclipse.titan.designer.AST.ASN1.InformationFromObj)1 FieldName (org.eclipse.titan.designer.AST.ASN1.Object.FieldName)1 ObjectSet_definition (org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition)1 Referenced_ObjectSet (org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet)1 ObjectClass (org.eclipse.titan.designer.AST.ASN1.ObjectClass)1 ObjectSet_Assignment (org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment)1 Parameterised_Reference (org.eclipse.titan.designer.AST.ASN1.Parameterised_Reference)1 ASN1_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType)1