use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class Array_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);
if (type.getIsErroneous(timestamp) || !Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
return null;
}
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)) {
return null;
}
if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
final ArrayDimension dimension = ((Array_Type) type).getDimension();
dimension.checkIndex(timestamp, valueIndex, Expected_Value_type.EXPECTED_CONSTANT);
if (dimension.getIsErroneous(timestamp)) {
return null;
}
final int index = ((Integer_Value) valueIndex).intValue() - (int) dimension.getOffset();
if (isIndexed()) {
for (int i = 0; i < values.getNofIndexedValues(); i++) {
IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
indexedValue = indexedValue.getValueRefdLast(timestamp, refChain);
if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
return values.getIndexedValueByIndex(i).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
}
arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
} else if (index < 0 || index >= values.getNofValues()) {
// the error was already reported
} else {
return values.getValueByIndex(index).getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
}
arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
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.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method generateClassCode.
private String generateClassCode(final JavaGenData aData, final StringBuilder sb, final ArrayList<String> list) {
String tempId1 = "TitanTimer";
for (int i = 0; i < dimensions.size(); ++i) {
final ArrayDimension dim = dimensions.get(dimensions.size() - i - 1);
final String tempId2 = aData.getTemporaryVariableName();
list.add(tempId2);
sb.append(MessageFormat.format("public static class {0} extends TitanTimerArray<{1}> '{'\n", tempId2, tempId1));
sb.append(MessageFormat.format("public {0}() '{'\n", tempId2));
sb.append(MessageFormat.format("super({0}.class, {1}, {2});\n", tempId1, dim.getSize(), dim.getOffset()));
sb.append("}\n");
sb.append(MessageFormat.format("public {0}({0} otherValue) '{'\n", tempId2));
sb.append("super(otherValue);\n");
sb.append("}\n }\n\n");
tempId1 = tempId2;
}
return tempId1;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension 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.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method getReferencedArrayTemplate.
@Override
protected /**
* {@inheritDoc}
*/
ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
if (indexValue.getIsErroneous(timestamp)) {
return null;
}
long index = 0;
if (!indexValue.isUnfoldable(timestamp)) {
if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
index = ((Integer_Value) indexValue).getValue();
} else {
arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
return null;
}
} else {
return null;
}
final IType tempType = myGovernor.getTypeRefdLast(timestamp);
if (tempType.getIsErroneous(timestamp)) {
return null;
}
switch(tempType.getTypetype()) {
case TYPE_SEQUENCE_OF:
{
if (index < 0) {
final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
break;
}
case TYPE_SET_OF:
{
if (index < 0) {
final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
break;
}
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!dimension.getIsErroneous(timestamp)) {
// re-base the index
index -= dimension.getOffset();
if (index < 0 || index > getNofTemplates()) {
arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
return null;
}
} else {
return null;
}
break;
}
default:
arrayIndex.getLocation().reportSemanticError(MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename()));
return null;
}
for (int i = 0, size = indexedTemplates.getNofTemplates(); i < size; i++) {
final IndexedTemplate template = indexedTemplates.getTemplateByIndex(i);
IValue lastValue = template.getIndex().getValue();
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
lastValue = lastValue.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(lastValue.getValuetype())) {
final long tempIndex = ((Integer_Value) lastValue).getValue();
if (index == tempIndex) {
final ITTCN3Template realTemplate = template.getTemplate();
if (Template_type.TEMPLATE_NOTUSED.equals(realTemplate.getTemplatetype())) {
if (baseTemplate != null) {
return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
}
return null;
}
return realTemplate;
}
}
}
switch(tempType.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_ARRAY:
// unfoldable (for now)
break;
default:
// the error was reported earlier
break;
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class RangeLenghtRestriction method checkArraySize.
@Override
public /**
* {@inheritDoc}
*/
void checkArraySize(final CompilationTimeStamp timestamp, final ArrayDimension dimension) {
if (lastTimeChecked == null || dimension.getIsErroneous(timestamp)) {
return;
}
boolean errorFlag = false;
final long arraySize = dimension.getSize();
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue lowerLast = lower.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(lowerLast.getValuetype()) && !lowerLast.getIsErroneous(timestamp)) {
final BigInteger length = ((Integer_Value) lowerLast).getValueValue();
if (length.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
final String message = MessageFormat.format("An integer value less then `{0}'' was expected as the lower boundary of the length restriction instead of `{1}''", Integer.MAX_VALUE, length);
lower.getLocation().reportSemanticError(message);
errorFlag = true;
} else if (length.compareTo(BigInteger.valueOf(arraySize)) == 1) {
final String message = MessageFormat.format("There number of elements allowed by the length restriction (at least {0}) contradicts the array size ({1})", length, arraySize);
lower.getLocation().reportSemanticError(message);
errorFlag = true;
}
}
if (upper != null) {
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue upperLast = upper.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(upperLast.getValuetype()) && !upperLast.getIsErroneous(timestamp)) {
final BigInteger length = ((Integer_Value) upperLast).getValueValue();
if (length.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
final String message = MessageFormat.format("An integer value less then `{0}'' was expected as the upper boundary of the length restriction instead of `{1}''", Integer.MAX_VALUE, length);
upper.getLocation().reportSemanticError(message);
errorFlag = true;
} else if (length.compareTo(BigInteger.valueOf(arraySize)) == 1) {
final String message = MessageFormat.format("There number of elements allowed by the length restriction (at most {0}) contradicts the array size ({1})", length, arraySize);
upper.getLocation().reportSemanticError(message);
errorFlag = true;
}
}
}
if (!errorFlag) {
getLocation().reportSemanticWarning("Length restriction is useless for an array template");
}
}
Aggregations