use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Integer_Type method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == namedNumbers) {
parseBlockInt();
}
if (isErroneous || null == namedNumbers) {
return;
}
/* check named numbers */
final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
final Identifier identifier = namedValue.getName();
if (nameMap.containsKey(identifier.getName())) {
final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
nameMap.put(identifier.getName(), identifier);
}
}
final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
final IValue value = namedValue.getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
continue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
{
final Integer_Value integerValue = (Integer_Value) last;
if (integerValue.isNative()) {
final Integer intValue = Integer.valueOf(integerValue.intValue());
if (valueMap.containsKey(intValue)) {
value.getLocation().reportSemanticError(MessageFormat.format("Duplicate number {0} for name `{1}''", intValue, namedValue.getName().getDisplayName()));
final NamedValue temp = valueMap.get(intValue);
temp.getLocation().reportSemanticError(MessageFormat.format("Number {0} is already assigned to name `{1}''", intValue, temp.getName().getDisplayName()));
} else {
valueMap.put(intValue, namedValue);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Integer value `{0}'' is too big to be used as a named number", integerValue.getValueValue()));
value.setIsErroneous(true);
}
break;
}
default:
namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named number `{0}''", namedValue.getName().getDisplayName()));
value.setIsErroneous(true);
break;
}
}
nameMap.clear();
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ISO2022String_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);
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)) {
if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
final int index = ((Integer_Value) valueIndex).intValue();
return getStringElement(index, arrayIndex.getLocation());
}
arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
return null;
}
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 DivideExpression 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 expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
Type_type tempType1 = null;
Type_type tempType2 = null;
if (value1 != null) {
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
switch(tempType1) {
case TYPE_INTEGER:
value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
break;
case TYPE_REAL:
value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value1.getLocation().reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
{
final IValue lastValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!lastValue.getIsErroneous(timestamp) && !lastValue.isUnfoldable(timestamp)) {
if (((Integer_Value) lastValue).equals(new Integer_Value(0L))) {
value2.getLocation().reportSemanticError(ZEROOPERANDERROR);
setIsErroneous(true);
}
}
break;
}
case TYPE_REAL:
value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value2.getLocation().reportSemanticError(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value1 != null && value2 != null && !getIsErroneous(timestamp)) {
if (value1.getIsErroneous(timestamp) || value2.getIsErroneous(timestamp)) {
setIsErroneous(true);
return;
}
if (tempType1 != tempType2) {
location.reportSemanticError(SAMEOPERANDERROR);
setIsErroneous(true);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class DivideExpression 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:
// If the operands exist they must be of the same type.
lastValue = ((Integer_Value) last1).divide((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 SubType method addTtcnLength.
private boolean addTtcnLength(final CompilationTimeStamp timestamp, final LengthRestriction lengthRestriction, final int restrictionIndex) {
lengthRestriction.setMyScope(myOwner.getMyScope());
final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<length_restriction_" + restrictionIndex + ">");
lengthRestriction.setFullNameParent(bridge);
lengthRestriction.check(timestamp, Expected_Value_type.EXPECTED_CONSTANT);
IValue lower = null, upper = null;
if (lengthRestriction instanceof SingleLenghtRestriction) {
lower = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
if (lower == null || lower.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lower.getValuetype()) || lower.isUnfoldable(timestamp)) {
return false;
}
if (!checkBoundaryValid(lower, "length restriction value")) {
return false;
}
final SizeLimit boundaryLimit = new SizeLimit(((Integer_Value) lower).getValueValue());
return setTtcnLength(boundaryLimit, boundaryLimit);
}
lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
if (lower == null || lower.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(lower.getValuetype()) || lower.isUnfoldable(timestamp)) {
return false;
}
if (!checkBoundaryValid(lower, "lower boundary")) {
return false;
}
upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
if (upper != null) {
if (upper.getMyScope() == null) {
upper.setMyScope(myOwner.getMyScope());
}
if (upper.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(upper.getValuetype()) || upper.isUnfoldable(timestamp)) {
return false;
}
if (!checkBoundaryValid(upper, "upper boundary")) {
return false;
}
return setTtcnLength(new SizeLimit(((Integer_Value) lower).getValueValue()), new SizeLimit(((Integer_Value) upper).getValueValue()));
}
// upper is infinity
return setTtcnLength(new SizeLimit(((Integer_Value) lower).getValueValue()), SizeLimit.MAXIMUM);
}
Aggregations