Search in sources :

Example 36 with Identifier

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

the class ASN1_Enumerated_Type method addProposal.

@Override
public final /**
 * {@inheritDoc}
 */
void addProposal(final ProposalCollector propCollector, final int i) {
    final List<ISubReference> subreferences = propCollector.getReference().getSubreferences();
    if (subreferences.size() <= i || enumerations == null) {
        return;
    }
    final ISubReference subreference = subreferences.get(i);
    if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
        if (subreferences.size() <= i + 1) {
            final String referenceName = subreference.getId().getName();
            if (enumerations.enumItems1 != null) {
                final List<EnumItem> enumItems = enumerations.enumItems1.getItems();
                for (EnumItem item : enumItems) {
                    final Identifier itemID = item.getId();
                    if (itemID.getName().startsWith(referenceName)) {
                        propCollector.addProposal(itemID, " - " + "named integer", ImageCache.getImage(getOutlineIcon()), "named integer");
                    }
                }
            }
            if (enumerations.enumItems2 != null) {
                final List<EnumItem> enumItems = enumerations.enumItems2.getItems();
                for (EnumItem item : enumItems) {
                    final Identifier itemID = item.getId();
                    if (itemID.getName().startsWith(referenceName)) {
                        propCollector.addProposal(itemID, " - " + "named integer", ImageCache.getImage(getOutlineIcon()), "named integer");
                    }
                }
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)

Example 37 with Identifier

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

the class ASN1_Enumerated_Type method checkThisValueRef.

@Override
public final /**
 * {@inheritDoc}
 */
IValue checkThisValueRef(final CompilationTimeStamp timestamp, final IValue value) {
    IValue temp = value;
    if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
        // we are not able to parse lower identifier values as default values
        // so the parsed reference needs to be converted.
        final Reference reference = ((Referenced_Value) value).getReference();
        if (reference.getModuleIdentifier() == null && reference.getSubreferences().size() == 1) {
            final Identifier identifier = reference.getId();
            temp = new Enumerated_Value(identifier);
            temp.setMyGovernor(this);
            temp.setFullNameParent(this);
            temp.setMyScope(value.getMyScope());
            return temp;
        }
    }
    if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(temp.getValuetype())) {
        if (nameMap != null && nameMap.containsKey(((Undefined_LowerIdentifier_Value) temp).getIdentifier().getName())) {
            temp = temp.setValuetype(timestamp, Value_type.ENUMERATED_VALUE);
            temp.setMyGovernor(this);
            temp.setFullNameParent(this);
            temp.setMyScope(value.getMyScope());
            return temp;
        }
    }
    return super.checkThisValueRef(timestamp, value);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) 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) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)

Example 38 with Identifier

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

the class ASN1_Enumerated_Type method checkEnumItem.

/**
 * Helper function for checking a single enumeration item. Checks if the
 * name of the item is not a duplicate, and its value is in correct
 * order. Also for items after the ellipsis if the value is missing a
 * new one is assigned.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param item
 *                the enumeration item to work on.
 * @param afterEllipsis
 *                true if the enumeration item is after the ellipsis.
 * @param valueMap
 *                a value map so that the correctness of the item's
 *                value can be checked.
 */
private final void checkEnumItem(final CompilationTimeStamp timestamp, final EnumItem item, final boolean afterEllipsis, final Map<Integer, EnumItem> valueMap) {
    final Identifier itemID = item.getId();
    if (nameMap.containsKey(itemID.getName())) {
        nameMap.get(itemID.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, itemID.getDisplayName()));
        itemID.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATEDREPEATED, itemID.getDisplayName()));
    } else {
        nameMap.put(itemID.getName(), item);
    }
    if (!itemID.getHasValid(Identifier_type.ID_TTCN)) {
        itemID.getLocation().reportSemanticWarning(MessageFormat.format(ASN1Assignment.UNREACHABLE, itemID.getDisplayName()));
    }
    final Value value = item.getValue();
    if (!item.isOriginal()) {
        if (afterEllipsis) {
            while (valueMap.containsKey(firstUnused)) {
                firstUnused++;
            }
            valueMap.put(firstUnused, item);
            // again.
            if (null == value || ((Integer_Value) value).getValue() != firstUnused) {
                final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
                tempValue.setLocation(item.getLocation());
                item.setValue(tempValue);
            }
        }
        return;
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", itemID.getDisplayName()));
        value.setIsErroneous(true);
        return;
    }
    final Integer_Value temp = (Integer_Value) last;
    if (!temp.isNative()) {
        value.getLocation().reportSemanticError(MessageFormat.format("The numeric value of enumeration `{0}'' ({1}) is too large for being represented in memory", itemID.getDisplayName(), temp.getValueValue()));
        value.setIsErroneous(true);
        return;
    }
    final Integer enumValue = Integer.valueOf(temp.intValue());
    if (afterEllipsis) {
        if (enumValue >= firstUnused) {
            valueMap.put(enumValue, item);
            while (valueMap.containsKey(firstUnused)) {
                firstUnused++;
            }
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format("ENUMERATED values shall be monotonically growing after the ellipsis: the value of `{0}'' must be at least {1} instead of {2}", itemID.getDisplayName(), firstUnused, enumValue));
            value.setIsErroneous(true);
        }
    } else {
        if (valueMap.containsKey(enumValue)) {
            final Location tempLocation = valueMap.get(enumValue).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumValue, valueMap.get(enumValue).getId().getDisplayName()));
            value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumValue, itemID.getDisplayName()));
            setIsErroneous(true);
        } else {
            valueMap.put(enumValue, item);
        }
    }
}
Also used : 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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Location(org.eclipse.titan.designer.AST.Location)

Example 39 with Identifier

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

the class ASN1_Enumerated_Type method addDeclaration.

@Override
public final /**
 * {@inheritDoc}
 */
void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
    final List<ISubReference> subreferences = declarationCollector.getReference().getSubreferences();
    if (subreferences.size() <= i) {
        return;
    }
    final ISubReference subreference = subreferences.get(i);
    if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
        if (subreferences.size() <= i + 1) {
            final String referenceName = subreference.getId().getName();
            if (enumerations.enumItems1 != null) {
                final List<EnumItem> enumItems = enumerations.enumItems1.getItems();
                for (EnumItem item : enumItems) {
                    final Identifier itemID = item.getId();
                    if (itemID.getName().startsWith(referenceName)) {
                        declarationCollector.addDeclaration(itemID.getDisplayName(), itemID.getLocation(), this);
                    }
                }
            }
            if (enumerations.enumItems2 != null) {
                final List<EnumItem> enumItems = enumerations.enumItems2.getItems();
                for (EnumItem item : enumItems) {
                    final Identifier itemID = item.getId();
                    if (itemID.getName().startsWith(referenceName)) {
                        declarationCollector.addDeclaration(itemID.getDisplayName(), itemID.getLocation(), this);
                    }
                }
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)

Example 40 with Identifier

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

Aggregations

Identifier (org.eclipse.titan.designer.AST.Identifier)176 IType (org.eclipse.titan.designer.AST.IType)75 ISubReference (org.eclipse.titan.designer.AST.ISubReference)57 IValue (org.eclipse.titan.designer.AST.IValue)39 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)38 Type (org.eclipse.titan.designer.AST.Type)35 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 Assignment (org.eclipse.titan.designer.AST.Assignment)25 ArrayList (java.util.ArrayList)24 Location (org.eclipse.titan.designer.AST.Location)24 Reference (org.eclipse.titan.designer.AST.Reference)22 Module (org.eclipse.titan.designer.AST.Module)21 HashMap (java.util.HashMap)16 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)15 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)12 Value (org.eclipse.titan.designer.AST.Value)12 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10