use of org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value 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;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value 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;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value 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;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value 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);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value in project titan.EclipsePlug-ins by eclipse.
the class SubType method checkThisValue.
/**
* Checks if a given value is valid according to this sub-type.
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param value
* the value to be checked
*/
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
return;
}
if (value.getIsErroneous(timestamp)) {
return;
}
final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (last.getIsErroneous(timestamp)) {
return;
}
boolean isValid = true;
switch(last.getValuetype()) {
case INTEGER_VALUE:
if (subtypeType != SubType_type.ST_INTEGER) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
break;
case REAL_VALUE:
if (subtypeType == SubType_type.ST_FLOAT) {
isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
break;
} else if (subtypeType == SubType_type.ST_INTEGER) {
final Real_Value real = (Real_Value) last;
if (real.isNegativeInfinity()) {
isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
break;
} else if (real.isPositiveInfinity()) {
isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
break;
}
}
ErrorReporter.INTERNAL_ERROR();
return;
case BOOLEAN_VALUE:
if (subtypeType != SubType_type.ST_BOOLEAN) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
break;
case VERDICT_VALUE:
if (subtypeType != SubType_type.ST_VERDICTTYPE) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
break;
case BITSTRING_VALUE:
if (subtypeType != SubType_type.ST_BITSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
break;
case HEXSTRING_VALUE:
if (subtypeType != SubType_type.ST_HEXSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
break;
case OCTETSTRING_VALUE:
if (subtypeType != SubType_type.ST_OCTETSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
break;
case CHARSTRING_VALUE:
switch(subtypeType) {
case ST_CHARSTRING:
isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
break;
case ST_UNIVERSAL_CHARSTRING:
isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
break;
default:
ErrorReporter.INTERNAL_ERROR();
return;
}
break;
case UNIVERSALCHARSTRING_VALUE:
if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
break;
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case OBJECTID_VALUE:
case ENUMERATED_VALUE:
case CHOICE_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
case FUNCTION_REFERENCE_VALUE:
case ALTSTEP_REFERENCE_VALUE:
case TESTCASE_REFERENCE_VALUE:
if (value.isUnfoldable(timestamp)) {
return;
}
isValid = subtypeConstraint.isElement(last);
break;
default:
return;
}
if (!isValid) {
value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
}
}
Aggregations