use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method getSubrefsAsArray.
@Override
public /**
* {@inheritDoc}
*/
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return true;
}
final ISubReference subreference = subreferences.get(actualSubReference);
if (subreference.getReferenceType() != Subreference_type.arraySubReference) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
final Value indexValue = ((ArraySubReference) subreference).getValue();
if (indexValue == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
final IValue last = indexValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_CONSTANT, null);
if (last == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
if (last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_CONSTANT) != Type_type.TYPE_INTEGER) {
return false;
}
if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
return false;
}
final Integer_Value lastInteger = (Integer_Value) last;
if (lastInteger.isNative()) {
final int fieldIndex = (int) lastInteger.getValue();
if (fieldIndex < 0) {
return false;
}
subrefsArray.add(fieldIndex);
typeArray.add(this);
} else {
return false;
}
if (ofType == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
return ofType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method isSubtypeCompatible.
/**
* Checks that the provided type is sub-type compatible with the actual
* set of type.
* <p>
* In case of sequence/set/array this means that the number of their
* fields fulfills the length restriction of the set of type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param other
* the type to check against.
*
* @return true if they are sub-type compatible, false otherwise.
*/
public boolean isSubtypeCompatible(final CompilationTimeStamp timestamp, final IType other) {
if (subType == null || other == null) {
return true;
}
long nofComponents;
switch(other.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
nofComponents = ((ASN1_Sequence_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SEQUENCE:
nofComponents = ((TTCN3_Sequence_Type) other).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComponents = ((ASN1_Set_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SET:
nofComponents = ((TTCN3_Set_Type) other).getNofComponents();
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
if (other.getSubtype() == null) {
return true;
}
return subType.isCompatible(timestamp, other.getSubtype());
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) other).getDimension();
if (dimension.getIsErroneous(timestamp)) {
return false;
}
nofComponents = dimension.getSize();
break;
}
default:
return false;
}
final List<ParsedSubType> tempRestrictions = new ArrayList<ParsedSubType>(1);
final Integer_Value length = new Integer_Value(nofComponents);
tempRestrictions.add(new Length_ParsedSubType(new SingleLenghtRestriction(length)));
final SubType tempSubtype = new SubType(getSubtypeType(), this, tempRestrictions, null);
tempSubtype.check(timestamp);
return subType.isCompatible(timestamp, tempSubtype);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method checkThisValueArray.
private boolean checkThisValueArray(final CompilationTimeStamp timestamp, final IValue originalValue, final Assignment lhs, final Array_Value lastValue, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
if (dimension == null) {
return false;
}
boolean selfReference = false;
final int nofValues = lastValue.getNofComponents();
if (!dimension.getIsErroneous(timestamp) && dimension.getSize() < nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format(TOOMANYEXPECTED, dimension.getSize(), nofValues));
originalValue.setIsErroneous(true);
}
if (lastValue.isIndexed()) {
boolean checkHoles = !dimension.getIsErroneous(timestamp) && Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
final long arraySize = dimension.getSize();
BigInteger maxIndex = BigInteger.valueOf(-1);
final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(lastValue.getNofComponents());
for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
final IValue component = lastValue.getValueByIndex(i);
final Value index = lastValue.getIndexByIndex(i);
dimension.checkIndex(timestamp, index, expectedValue);
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) {
checkHoles = false;
} else {
final BigInteger tempIndex = ((Integer_Value) indexLast).getValueValue();
if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
index.getLocation().reportSemanticError(MessageFormat.format("A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex));
checkHoles = false;
} else if (tempIndex.compareTo(BigInteger.ZERO) == -1) {
index.getLocation().reportSemanticError(MessageFormat.format("A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex));
checkHoles = false;
} else if (indexMap.containsKey(tempIndex)) {
index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1));
checkHoles = false;
} else {
indexMap.put(tempIndex, Integer.valueOf(i + 1));
if (maxIndex.compareTo(tempIndex) == -1) {
maxIndex = tempIndex;
}
}
}
component.setMyGovernor(elementType);
final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
if (checkHoles) {
if (indexMap.size() < arraySize) {
lastValue.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
originalValue.setIsErroneous(true);
}
}
} else {
if (!dimension.getIsErroneous(timestamp)) {
final long arraySize = dimension.getSize();
if (arraySize > nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format("Too few elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
originalValue.setIsErroneous(true);
} else if (arraySize < nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format("Too many elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
originalValue.setIsErroneous(true);
}
}
for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
final IValue component = lastValue.getValueByIndex(i);
component.setMyGovernor(elementType);
if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
if (!incompleteAllowed) {
component.getLocation().reportSemanticError(AbstractOfType.INCOMPLETEPRESENTERROR);
}
} else {
final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class RangeLenghtRestriction method checkNofElements.
@Override
public /**
* {@inheritDoc}
*/
void checkNofElements(final CompilationTimeStamp timestamp, final int nofElements, final boolean lessAllowed, final boolean moreAllowed, final boolean hasAnyornone, final ILocateableNode locatable) {
if (lower == null) {
return;
}
if (!lessAllowed) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = lower.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
final BigInteger length = ((Integer_Value) last).getValueValue();
if (length.compareTo(BigInteger.valueOf(nofElements)) == 1) {
final String message = MessageFormat.format("There are fewer ({0}) elements than it is allowed by the length restriction (at least {1})", nofElements, length);
locatable.getLocation().reportSemanticError(message);
}
}
}
if (upper == null) {
return;
}
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = upper.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
final BigInteger length = ((Integer_Value) last).getValueValue();
if (length.compareTo(BigInteger.valueOf(nofElements)) == -1 && !moreAllowed) {
final String message = MessageFormat.format("There are more ({0} {1}) elements than it is allowed by the length restriction ({2})", hasAnyornone ? "at least" : "", nofElements, length);
locatable.getLocation().reportSemanticError(message);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class RangeLenghtRestriction method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
final Integer_Type integer = new Integer_Type();
lower.setMyGovernor(integer);
IValue last = integer.checkThisValueRef(timestamp, lower);
integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue valueLower = last.getValueRefdLast(timestamp, chain);
chain.release();
if (last.getIsErroneous(timestamp)) {
return;
}
BigInteger lowerInt;
switch(valueLower.getValuetype()) {
case INTEGER_VALUE:
{
lowerInt = ((Integer_Value) valueLower).getValueValue();
if (lowerInt.compareTo(BigInteger.ZERO) == -1) {
final String message = MessageFormat.format("The lower boundary of the length restriction must be a non-negative integer value instead of {0}", lowerInt);
valueLower.getLocation().reportSemanticError(message);
}
break;
}
default:
lowerInt = BigInteger.ZERO;
break;
}
if (upper == null) {
return;
}
upper.setMyGovernor(integer);
last = integer.checkThisValueRef(timestamp, upper);
integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue valueUpper = last.getValueRefdLast(timestamp, chain);
chain.release();
if (last.getIsErroneous(timestamp)) {
return;
}
BigInteger upperInt;
switch(valueUpper.getValuetype()) {
case INTEGER_VALUE:
{
upperInt = ((Integer_Value) valueUpper).getValueValue();
if (upperInt.compareTo(BigInteger.ZERO) == -1) {
final String message = MessageFormat.format("The upper boundary of the length restriction must be a non-negative integer value instead of {0}", upperInt);
valueUpper.getLocation().reportSemanticError(message);
} else if (upperInt.compareTo(lowerInt) == -1) {
getLocation().reportSemanticError(MessageFormat.format("The upper boundary of the length restriction ({0}) cannot be smaller than the lower boundary {1}", upperInt, lowerInt));
}
break;
}
default:
break;
}
}
Aggregations