use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value 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;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_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.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Float2IntExpression 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.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case REAL_VALUE:
lastValue = new Integer_Value((long) ((Real_Value) last).getValue());
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class AddExpression 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)) {
setIsErroneous(true);
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:
// If the operands exist they must be of the same type.
// Avoid
// dependency from BigInteger.
lastValue = ((Integer_Value) last1).add((Integer_Value) last2);
lastValue.copyGeneralProperties(this);
break;
case REAL_VALUE:
final double f1 = ((Real_Value) last1).getValue();
final double f2 = ((Real_Value) last2).getValue();
lastValue = new Real_Value(f1 + f2);
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_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;
}
Aggregations