use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Bit2IntExpression method bit2int.
public static Integer_Value bit2int(final String bitString) {
Integer_Value result = new Integer_Value(0);
final byte[] bytes = bitString.getBytes();
int startIndex = 0;
while (startIndex < bytes.length && '0' == bytes[startIndex]) {
startIndex++;
}
for (int i = startIndex; i < bytes.length; i++) {
result = result.shiftLeft(1);
if (bytes[i] == '1') {
result = result.add(new Integer_Value(1));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Char2IntExpression 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 CHARSTRING_VALUE:
final String string = ((Charstring_Value) last).getValue();
final CharstringExtractor cs = new CharstringExtractor(string);
lastValue = new Integer_Value(cs.getExtractedString().charAt(0));
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 Def_Timer method checkArrayDuration.
private void checkArrayDuration(final CompilationTimeStamp timestamp, final IValue duration, final int startDimension) {
final ArrayDimension dim = dimensions.get(startDimension);
final boolean arraySizeKnown = !dim.getIsErroneous(timestamp);
int arraySize = 0;
if (arraySizeKnown) {
arraySize = (int) dim.getSize();
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (v.getIsErroneous(timestamp)) {
// error
return;
}
if (v.getValuetype() == Value_type.SEQUENCEOF_VALUE) {
final SequenceOf_Value value = (SequenceOf_Value) v;
final int nofComp = value.getNofComponents();
// Value-list notation.
if (!value.isIndexed()) {
if (arraySizeKnown) {
if (arraySize > nofComp) {
duration.getLocation().reportSemanticError("Too few elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
} else if (arraySize < nofComp) {
duration.getLocation().reportSemanticError("Too many elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
}
}
final boolean last_dim = startDimension + 1 >= dimensions.size();
for (int i = 0; i < nofComp; ++i) {
final IValue array_v = value.getValueByIndex(i);
if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
if (last_dim) {
checkSingleDuration(timestamp, array_v);
} else {
checkArrayDuration(timestamp, array_v, startDimension + 1);
}
}
} else {
// Indexed-notation.
final boolean last_dim = startDimension + 1 >= dimensions.size();
final Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
for (int i = 0; i < nofComp; ++i) {
final IValue array_v = value.getValueByIndex(i);
if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
if (last_dim) {
checkSingleDuration(timestamp, array_v);
} else {
checkArrayDuration(timestamp, array_v, startDimension + 1);
}
final IValue array_index = value.getIndexByIndex(i);
dim.checkIndex(timestamp, array_index, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
final IValue tmp = array_index.getValueRefdLast(timestamp, referenceChain);
if (tmp.getValuetype() == Value_type.INTEGER_VALUE) {
final BigInteger index = ((Integer_Value) tmp).getValueValue();
if (index.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
array_index.getLocation().reportSemanticError(MessageFormat.format("An integer value less than {0} was expected for indexing timer array instead of {1}", Integer.MAX_VALUE, index));
array_index.setIsErroneous(true);
} else {
final int IndexValue = index.intValue();
if (indexMap.containsKey(IndexValue)) {
array_index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value {0} for timer array elements {1} and {2}", index, i + 1, indexMap.get(IndexValue)));
array_index.setIsErroneous(true);
} else {
indexMap.put(IndexValue, i + 1);
}
}
}
}
// It's not possible to have "indexMap.size() > arraySize", since we
// add only correct constant-index values into the map. It's possible
// to create partially initialized timer arrays.
indexMap.clear();
}
} else {
if (arraySizeKnown) {
duration.getLocation().reportSemanticError("An array value (with " + arraySize + " elements) was expected as default duration of timer array");
} else {
duration.getLocation().reportSemanticError("An array value was expected as default duration of timer array");
}
duration.setIsErroneous(true);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method hasDefaultDuration.
/**
* Returns false if it is sure that the timer referred by array indices
* reference does not have a default duration. Otherwise it returns
* true.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param reference
* might be NULL when examining a single timer.
*
* @return true if the timer has a default duration, false otherwise.
*/
public boolean hasDefaultDuration(final CompilationTimeStamp timestamp, final Reference reference) {
if (defaultDuration == null) {
return false;
} else if (dimensions == null || reference == null) {
return true;
}
IValue v = defaultDuration;
final List<ISubReference> subreferences = reference.getSubreferences();
final int nofDimensions = dimensions.size();
final int nofReferences = subreferences.size() - 1;
final int upperLimit = (nofDimensions < nofReferences) ? nofDimensions : nofReferences;
for (int i = 0; i < upperLimit; i++) {
v = v.getValueRefdLast(timestamp, null);
if (Value_type.SEQUENCEOF_VALUE.equals(v.getValuetype())) {
final ISubReference ref = subreferences.get(i + 1);
if (!Subreference_type.arraySubReference.equals(ref.getReferenceType())) {
return true;
}
final IValue index = ((ArraySubReference) ref).getValue();
if (!Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
return true;
}
final long realIndex = ((Integer_Value) index).getValue() - dimensions.get(i).getOffset();
if (realIndex >= 0 && realIndex < ((SequenceOf_Value) v).getNofComponents()) {
v = ((SequenceOf_Value) v).getValueByIndex((int) realIndex);
}
}
}
return !Value_type.NOTUSED_VALUE.equals(v.getValuetype());
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_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);
}
}
Aggregations