Search in sources :

Example 11 with ISubReference

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

the class Notused_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with ISubReference

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

the class ObjectIdentifierComponent method checkNameForm.

/**
 * Checks that the identifier in name is a valid name form in the actual state.
 * Also checks the named form in an OID component.
 *
 * @param timestamp the timestamp of the actual compilation cycle.
 * @param parent the parent value.
 * @param refChain the reference chain used to detect cyclic references.
 * @param state the state of checking.
 *
 * @param the new state after this check was done.
 */
private oidState_type checkNameForm(final CompilationTimeStamp timestamp, final Value parent, final IReferenceChain refChain, final oidState_type state, final AtomicInteger result) {
    final String nameString = name.getName();
    oidState_type actualState = state;
    int value = -1;
    switch(state) {
        case START:
            if ("itu__t".equals(nameString) || "ccitt".equals(nameString)) {
                actualState = oidState_type.ITU;
                value = 0;
            } else if ("itu__r".equals(nameString)) {
                location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NameForm", name.getDisplayName()));
                actualState = oidState_type.ITU;
                value = 0;
            } else if ("iso".equals(nameString)) {
                actualState = oidState_type.ISO;
                value = 1;
            } else if ("joint__iso__itu__t".equals(nameString) || "joint__iso__ccitt".equals(nameString)) {
                actualState = oidState_type.JOINT;
                value = 2;
            }
            break;
        case ITU:
            for (int i = 0; i < NAMES_ITU.length; i++) {
                if (nameString.equals(NAMES_ITU[i].name)) {
                    value = NAMES_ITU[i].value;
                    switch(value) {
                        case 0:
                            actualState = oidState_type.ITU_REC;
                            break;
                        case 5:
                            location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NumberForm", name.getDisplayName()));
                            actualState = oidState_type.LATER;
                            break;
                        default:
                            actualState = oidState_type.LATER;
                            break;
                    }
                }
            }
            break;
        case ISO:
            for (int i = 0; i < NAMES_ISO.length; i++) {
                if (nameString.equals(NAMES_ISO[i].name)) {
                    value = NAMES_ISO[i].value;
                    actualState = oidState_type.LATER;
                }
            }
            break;
        case JOINT:
            for (int i = 0; i < NAMES_JOINT.length; i++) {
                if (nameString.equals(NAMES_JOINT[i].name)) {
                    value = NAMES_JOINT[i].value;
                    actualState = oidState_type.LATER;
                    location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NumberForm", name.getDisplayName()));
                }
            }
            break;
        case ITU_REC:
            if (nameString.length() == 1) {
                final char c = nameString.charAt(0);
                if (c >= 'a' && c <= 'z') {
                    value = c - 'a' + 1;
                    actualState = oidState_type.LATER;
                }
            }
            break;
        default:
            break;
    }
    // now we have detected the name form
    if (value < 0) {
        final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
        newSubreferences.add(new FieldSubReference(name));
        Reference reference;
        if (parent.isAsn()) {
            reference = new Defined_Reference(null, newSubreferences);
        } else {
            reference = new Reference(null, newSubreferences);
        }
        final IValue newDefinedValue = new Referenced_Value(reference);
        newDefinedValue.setLocation(this.getLocation());
        final ObjectIdentifierComponent component = new ObjectIdentifierComponent(newDefinedValue);
        component.setFullNameParent(this);
        component.setMyScope(parent.getMyScope());
        actualState = component.checkDefdValueOID(timestamp, refChain, actualState);
    }
    result.set(value);
    // the other case is not handled as it would only change a parsed value
    return actualState;
}
Also used : Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) ArrayList(java.util.ArrayList) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue)

Example 13 with ISubReference

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

the class ObjectIdentifier_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 14 with ISubReference

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

the class Array_Value method evaluateIsbound.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp) || !Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value arrayIndex = ((ArraySubReference) subreference).getValue();
            IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (valueIndex.isUnfoldable(timestamp)) {
                return false;
            }
            if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
                final int index = ((Integer_Value) valueIndex).intValue();
                if (isIndexed()) {
                    for (int i = 0; i < values.getNofIndexedValues(); i++) {
                        IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
                        referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        indexedValue = indexedValue.getValueRefdLast(timestamp, referenceChain);
                        referenceChain.release();
                        if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
                            return values.getIndexedValueByIndex(i).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
                        }
                    }
                    arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
                } else if (index < 0 || index >= values.getNofValues()) {
                // the error was already reported
                } else {
                    return values.getValueByIndex(index).evaluateIsbound(timestamp, reference, actualSubReference + 1);
                }
                return false;
            }
            return false;
        case fieldSubReference:
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) 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) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 15 with ISubReference

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

the class Array_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp) || !Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value arrayIndex = ((ArraySubReference) subreference).getValue();
            final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, refChain);
            if (valueIndex.isUnfoldable(timestamp)) {
                return null;
            }
            if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
                final ArrayDimension dimension = ((Array_Type) type).getDimension();
                dimension.checkIndex(timestamp, valueIndex, Expected_Value_type.EXPECTED_CONSTANT);
                if (dimension.getIsErroneous(timestamp)) {
                    return null;
                }
                final int index = ((Integer_Value) valueIndex).intValue() - (int) dimension.getOffset();
                if (isIndexed()) {
                    for (int i = 0; i < values.getNofIndexedValues(); i++) {
                        IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
                        indexedValue = indexedValue.getValueRefdLast(timestamp, refChain);
                        if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
                            return values.getIndexedValueByIndex(i).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                        }
                    }
                    arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
                } else if (index < 0 || index >= values.getNofValues()) {
                // the error was already reported
                } else {
                    return values.getValueByIndex(index).getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                }
                return null;
            }
            arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Aggregations

ISubReference (org.eclipse.titan.designer.AST.ISubReference)205 IType (org.eclipse.titan.designer.AST.IType)80 IValue (org.eclipse.titan.designer.AST.IValue)63 Identifier (org.eclipse.titan.designer.AST.Identifier)53 Value (org.eclipse.titan.designer.AST.Value)47 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)46 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)40 Assignment (org.eclipse.titan.designer.AST.Assignment)28 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)25 Reference (org.eclipse.titan.designer.AST.Reference)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)15 ArrayList (java.util.ArrayList)14 Template (org.eclipse.jface.text.templates.Template)11 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)11 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)11 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)10 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)8 Module (org.eclipse.titan.designer.AST.Module)8 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)7 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)6