Search in sources :

Example 1 with IndexedValue

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

Example 2 with IndexedValue

use of org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue in project titan.EclipsePlug-ins by eclipse.

the class Indexed_Template_List method getValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValue() {
    if (asValue != null) {
        return asValue;
    }
    final Values values = new Values(true);
    for (int i = 0, size = getNofTemplates(); i < size; i++) {
        final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
        final IndexedValue indexedValue = new IndexedValue(indexedTemplate.getIndex(), indexedTemplate.getTemplate().getValue());
        indexedValue.setLocation(indexedTemplate.getLocation());
        values.addIndexedValue(indexedValue);
    }
    asValue = new SequenceOf_Value(values);
    asValue.setLocation(getLocation());
    asValue.setMyScope(getMyScope());
    asValue.setFullNameParent(getNameParent());
    asValue.setMyGovernor(getMyGovernor());
    return asValue;
}
Also used : Values(org.eclipse.titan.designer.AST.TTCN3.values.Values) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) IndexedValue(org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue)

Example 3 with IndexedValue

use of org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue in project titan.EclipsePlug-ins by eclipse.

the class Values method updateSyntax.

/**
 * Handles the incremental parsing of this value list.
 *
 * @param reparser the parser doing the incremental parsing.
 * @param isDamaged true if the location contains the damaged area, false if only its' location needs to be updated.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (isIndexed) {
        for (int i = 0, size = indexedValues.size(); i < size; i++) {
            final IndexedValue indexedValue = indexedValues.get(i);
            indexedValue.updateSyntax(reparser, false);
            reparser.updateLocation(indexedValue.getLocation());
        }
    } else {
        for (int i = 0, size = values.size(); i < size; i++) {
            final IValue value = values.get(i);
            if (value instanceof IIncrementallyUpdateable) {
                ((IIncrementallyUpdateable) value).updateSyntax(reparser, false);
                reparser.updateLocation(value.getLocation());
            } else {
                throw new ReParseException();
            }
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 IIncrementallyUpdateable (org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable)1 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)1 IndexedValue (org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue)1 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)1 Values (org.eclipse.titan.designer.AST.TTCN3.values.Values)1 Value (org.eclipse.titan.designer.AST.Value)1 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)1