Search in sources :

Example 1 with EnumItem

use of org.eclipse.titan.designer.AST.TTCN3.types.EnumItem in project titan.EclipsePlug-ins by eclipse.

the class LessThanExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with EnumItem

use of org.eclipse.titan.designer.AST.TTCN3.types.EnumItem in project titan.EclipsePlug-ins by eclipse.

the class Enum2IntExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last == null || last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    IType type = last.getExpressionGovernor(timestamp, expectedValue);
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_ASN1_ENUMERATED:
            {
                final EnumItem item = ((ASN1_Enumerated_Type) type).getEnumItemWithName(((Enumerated_Value) last).getValue());
                lastValue = new Integer_Value(((Integer_Value) item.getValue()).getValue());
                lastValue.copyGeneralProperties(this);
                break;
            }
        case TYPE_TTCN3_ENUMERATED:
            {
                final EnumItem item = ((TTCN3_Enumerated_Type) type).getEnumItemWithName(((Enumerated_Value) last).getValue());
                lastValue = new Integer_Value(((Integer_Value) item.getValue()).getValue());
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with EnumItem

use of org.eclipse.titan.designer.AST.TTCN3.types.EnumItem in project titan.EclipsePlug-ins by eclipse.

the class GreaterThanOrEqualExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) >= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) >= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() >= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() >= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with EnumItem

use of org.eclipse.titan.designer.AST.TTCN3.types.EnumItem in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Enumerated_Type method getEnclosingField.

@Override
public final /**
 * {@inheritDoc}
 */
void getEnclosingField(final int offset, final ReferenceFinder rf) {
    if (enumerations == null) {
        return;
    }
    if (enumerations.enumItems1 != null) {
        for (EnumItem enumItem : enumerations.enumItems1.getItems()) {
            if (enumItem.getLocation().containsOffset(offset)) {
                rf.type = this;
                rf.fieldId = enumItem.getId();
                return;
            }
        }
    }
    if (enumerations.enumItems2 != null) {
        for (EnumItem enumItem : enumerations.enumItems2.getItems()) {
            if (enumItem.getLocation().containsOffset(offset)) {
                rf.type = this;
                rf.fieldId = enumItem.getId();
                return;
            }
        }
    }
}
Also used : EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)

Example 5 with EnumItem

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

Aggregations

EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)10 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)10 IValue (org.eclipse.titan.designer.AST.IValue)7 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)4 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 Enum_Defs (org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_Defs)2 Enum_field (org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_field)2 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)2 Value (org.eclipse.titan.designer.AST.Value)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 Location (org.eclipse.titan.designer.AST.Location)1 Module (org.eclipse.titan.designer.AST.Module)1 EnumeratedGenerator (org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator)1 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)1