use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsValueExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param referenceChain
* the referencechain to detect circular references.
* @param expectedValue
* the expected value of the template instance.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
ITTCN3Template template = templateInstance.getTemplateBody();
if (governor == null) {
template = template.setLoweridToReference(timestamp);
governor = template.getExpressionGovernor(timestamp, internalExpectation);
}
if (governor == null) {
if (!template.getIsErroneous(timestamp)) {
templateInstance.getLocation().reportSemanticError(OPERANDERROR);
}
setIsErroneous(true);
} else {
templateInstance.getExpressionReturntype(timestamp, internalExpectation);
checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsValueExpression method checkExpressionTemplateInstance.
/**
* Checks if the templateinstance parameter (which is a parameter of the
* expression parameter) is actually a constant or static value or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expression
* the expression to report the possible errors to.
* @param instance
* the template instance parameter of the expression to
* be checked.
* @param type
* the type against which the template instance shall be
* checked.
* @param referenceChain
* the referencechain to detect circular references.
* @param expectedValue
* the expected value of the template instance.
*/
public static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
Expected_Value_type internalExpectation;
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
} else {
internalExpectation = expectedValue;
}
instance.check(timestamp, type);
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(CONSTEXPECTED1);
} else {
instance.getLocation().reportSemanticError(STATICEXPECTED1);
}
expression.setIsErroneous(true);
}
ITTCN3Template template = instance.getTemplateBody();
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
switch(template.getTemplatetype()) {
case TEMPLATE_REFD:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
template = template.getTemplateReferencedLast(timestamp, referenceChain);
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
} else {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
} else {
instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
}
expression.setIsErroneous(true);
}
break;
case SPECIFIC_VALUE:
final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
switch(tempValue.getValuetype()) {
case REFERENCED_VALUE:
type.checkThisValueRef(timestamp, tempValue);
break;
case EXPRESSION_VALUE:
tempValue.getValueRefdLast(timestamp, referenceChain);
break;
default:
break;
}
if (tempValue.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type 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.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class ModuloExpression 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:
final BigInteger i1 = ((Integer_Value) last1).getValueValue();
final BigInteger i2Abs = ((Integer_Value) last2).getValueValue().abs();
final BigInteger temp = i1.remainder(i2Abs);
final BigInteger result = i1.compareTo(BigInteger.ZERO) >= 0 ? temp : (temp.equals(BigInteger.ZERO) ? BigInteger.ZERO : temp.add(i2Abs));
lastValue = new Integer_Value(result);
lastValue.copyGeneralProperties(this);
break;
default:
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Not4bExpression 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 BITSTRING_VALUE:
lastValue = new Bitstring_Value(not4bBit(((Bitstring_Value) last).getValue()));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
lastValue = new Hexstring_Value(not4bHex(((Hexstring_Value) last).getValue()));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
lastValue = new Octetstring_Value(not4bHex(((Octetstring_Value) last).getValue()));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
Aggregations