use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Integer_Type method checkThisValueLimit.
// this method accepts REAL_VALUE
public void checkThisValueLimit(final CompilationTimeStamp timestamp, final IValue value, final ValueCheckingOptions valueCheckingOptions) {
super.checkThisValue(timestamp, value, null, valueCheckingOptions);
final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (null == last || last.getIsErroneous(timestamp)) {
return;
}
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return;
}
break;
default:
break;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
case REAL_VALUE:
break;
case NAMED_INTEGER_VALUE:
if (null != namedNumbers) {
// convert it into an integer value
final Identifier name = ((Named_Integer_Value) last).getIdentifier();
final NamedValue namedValue = namedNumbers.getNamedValueByName(name);
IValue tempValue = namedValue.getValue();
final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
final int temp = ((Integer_Value) tempValue).intValue();
final Integer_Value converted = new Integer_Value(temp);
converted.copyGeneralProperties(value);
((Named_Integer_Value) last).setCalculatedValue(converted);
} else {
// FIXME Most probably we were not able
// to build the semantic structure for
// something, because it is not yet
// supported, like referenced values in
// sets
}
}
break;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
break;
default:
value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
value.setIsErroneous(true);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Integer_Type method checkBoundary.
private IValue checkBoundary(final CompilationTimeStamp timestamp, final Value value, final BOUNDARY_TYPE btype) {
if (value == null) {
return null;
}
value.setMyGovernor(this);
IValue temp = checkThisValueRef(timestamp, value);
checkThisValueLimit(timestamp, temp, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
temp = temp.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (Value_type.REAL_VALUE.equals(temp.getValuetype())) {
if (((Real_Value) temp).isNegativeInfinity()) {
if (BOUNDARY_TYPE.UPPER.equals(btype)) {
value.getLocation().reportSemanticError(INCORRECTUPPERBOUNDARY);
value.setIsErroneous(true);
}
return temp;
} else if (((Real_Value) temp).isPositiveInfinity()) {
if (BOUNDARY_TYPE.LOWER.equals(btype)) {
value.getLocation().reportSemanticError(INCORRECTLOWERBOUNDARY);
value.setIsErroneous(true);
}
return temp;
} else {
value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
value.setIsErroneous(true);
return null;
}
}
switch(temp.getValuetype()) {
case INTEGER_VALUE:
break;
default:
temp = null;
break;
}
return temp;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Testcase_Instance_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (dereferredValue == null) {
return;
}
final IValue temporalValue = dereferredValue.setLoweridToReference(timestamp);
IType type = temporalValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null) {
return;
}
if (!Type_type.TYPE_TESTCASE.equals(type.getTypetype())) {
dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type testcase was expected in the argument of `derefers()'' instead of `{0}''", type.getTypename()));
return;
}
if (myStatementBlock.getScopeRunsOn() != null) {
dereferredValue.getLocation().reportSemanticError(DEFINITIONWITHOUTRUNSONEXPECTED);
return;
}
actualParameterList2 = new ActualParameterList();
final FormalParameterList formalParameterList = ((Testcase_Type) type).getFormalParameters();
formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameterList2);
if (timerValue != null) {
timerValue.setLoweridToReference(timestamp);
final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType) {
case TYPE_REAL:
final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (!last.isUnfoldable(timestamp)) {
final Real_Value real = (Real_Value) last;
final double i = real.getValue();
if (i < 0.0) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
} else if (real.isPositiveInfinity()) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED2, real.createStringRepresentation()));
}
}
break;
default:
timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.
the class Float_Type method checkThisTemplate.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
registerUsage(template);
template.setMyGovernor(this);
if (getIsErroneous(timestamp)) {
return false;
}
if (Template_type.VALUE_RANGE.equals(template.getTemplatetype())) {
final ValueRange range = ((Value_Range_Template) template).getValueRange();
final IValue lower = checkBoundary(timestamp, range.getMin());
final IValue upper = checkBoundary(timestamp, range.getMax());
range.setTypeType(getTypetypeTtcn3());
if (lower != null && upper != null) {
if (((Real_Value) lower).getValue() > ((Real_Value) upper).getValue()) {
template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
}
}
// TODO: some checks are still missing
} else {
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.
the class SubType method addTtcnSingle.
/**
* add TTCN-3 single value sub-type constraint to this sub-type
*/
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
value.setMyScope(myOwner.getMyScope());
value.setMyGovernor(myOwner);
final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
value.setFullNameParent(bridge);
IValue last = myOwner.checkThisValueRef(timestamp, value);
// check if this is type reference, if not then fall through
final IValue refValue = value.setLoweridToReference(timestamp);
// Value_type.REFERENCED_VALUE);
if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
final Reference ref = ((Referenced_Value) refValue).getReference();
final Assignment ass = ref.getRefdAssignment(timestamp, false);
if (ass == null) {
// definition was not found, error was reported
return false;
}
if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
IType t = ass.getType(timestamp);
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
final List<ISubReference> subrefs = ref.getSubreferences();
if (subrefs.size() > 1) {
// if there were sub-references then get the referenced field's type
t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
if ((t == null) || t.getIsErroneous(timestamp)) {
return false;
}
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
}
if (!t.isIdentical(timestamp, myOwner)) {
value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
return false;
}
// check subtype of referenced type
final SubType tSt = t.getSubtype();
if ((tSt == null) || (tSt.subtypeConstraint == null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
return false;
}
// check circular sub-type reference
if (!addParentSubtype(tSt)) {
return false;
}
if (tSt.getIsErroneous(timestamp)) {
return false;
}
if (tSt.subtypeType != subtypeType) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add the sub-type as union
if (subtypeConstraint == null) {
subtypeConstraint = tSt.subtypeConstraint;
} else {
subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
}
return true;
}
}
myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
last = last.getValueRefdLast(timestamp, chain);
chain.release();
if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
return false;
}
// create a single value constraint
SubtypeConstraint sc;
switch(subtypeType) {
case ST_INTEGER:
sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
break;
case ST_FLOAT:
sc = new RealRangeListConstraint(((Real_Value) last).getValue());
break;
case ST_BOOLEAN:
sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
break;
case ST_VERDICTTYPE:
sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
break;
case ST_BITSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
break;
case ST_HEXSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
break;
case ST_OCTETSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
break;
case ST_CHARSTRING:
if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
return false;
}
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
break;
case ST_UNIVERSAL_CHARSTRING:
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
break;
case UNIVERSALCHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
break;
default:
return false;
}
break;
case ST_OBJID:
case ST_ENUM:
case ST_UNION:
case ST_RECORD:
case ST_SET:
case ST_FUNCTION:
case ST_ALTSTEP:
case ST_TESTCASE:
sc = new ValueListConstraint(last);
break;
case ST_RECORDOF:
case ST_SETOF:
sc = new ValueListAndSizeConstraint(last);
break;
default:
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add next value using union operation
if (subtypeConstraint == null) {
subtypeConstraint = sc;
} else {
subtypeConstraint = subtypeConstraint.union(sc);
}
return true;
}
Aggregations