use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Enumerated_Type method generateCode.
/**
* Add generated java code on this level.
* @param aData only used to update imports if needed
* @param source the source code generated
*/
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String ownName = getGenNameOwn();
final String displayName = getFullName();
generateCodeTypedescriptor(aData, source);
final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
final ArrayList<Enum_field> fields = new ArrayList<EnumeratedGenerator.Enum_field>(items.getItems().size());
for (int i = 0; i < items.getItems().size(); i++) {
final EnumItem tempItem = items.getItems().get(i);
fields.add(new Enum_field(tempItem.getId().getName(), tempItem.getId().getDisplayName(), ((Integer_Value) tempItem.getValue()).getValue()));
}
final Enum_Defs e_defs = new Enum_Defs(fields, ownName, displayName, getGenNameTemplate(aData, source, myScope), hasRaw);
EnumeratedGenerator.generateValueClass(aData, source, e_defs);
EnumeratedGenerator.generateTemplateClass(aData, source, e_defs);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Enumerated_Type method check.
/**
* Does the semantic checking of the enumerations.
*
* @param timestamp the timestamp of the actual semantic check cycle.
*/
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
parseAttributes(timestamp);
nameMap = new HashMap<String, EnumItem>(items.getItems().size());
final Map<Long, EnumItem> valueMap = new HashMap<Long, EnumItem>(items.getItems().size());
final List<EnumItem> enumItems = items.getItems();
// check duplicated names and values
for (int i = 0, size = enumItems.size(); i < size; i++) {
final EnumItem item = enumItems.get(i);
final Identifier id = item.getId();
final String fieldName = id.getName();
if (nameMap.containsKey(fieldName)) {
nameMap.get(fieldName).getId().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERFIRST, id.getDisplayName()));
id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERREPEATED, id.getDisplayName()));
} else {
nameMap.put(fieldName, item);
}
final Value value = item.getValue();
if (value != null && item.isOriginal()) {
if (value.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(value.getValuetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", id.getDisplayName()));
setIsErroneous(true);
} else {
final Integer_Value enumValue = (Integer_Value) value;
if (!enumValue.isNative()) {
enumValue.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERERROR, enumValue.getValueValue()));
setIsErroneous(true);
} else {
final Long enumLong = enumValue.getValue();
if (valueMap.containsKey(enumLong)) {
valueMap.get(enumLong).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumLong, valueMap.get(enumLong).getId().getDisplayName()));
value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumLong, id.getDisplayName()));
setIsErroneous(true);
} else {
valueMap.put(enumLong, item);
}
}
}
}
}
// Assign default values
if (!getIsErroneous(timestamp) && lastTimeChecked == null) {
Long firstUnused = Long.valueOf(0);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
for (int i = 0, size = enumItems.size(); i < size; i++) {
final EnumItem item = enumItems.get(i);
if (!item.isOriginal()) {
// optimization: if the same value was already assigned, there is no need to create it again.
final IValue value = item.getValue();
if (value == null || ((Integer_Value) value).getValue() != firstUnused) {
final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
tempValue.setLocation(item.getLocation());
item.setValue(tempValue);
}
valueMap.put(firstUnused, item);
firstUnused = Long.valueOf(firstUnused.longValue() + 1);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
}
}
}
valueMap.clear();
lastTimeChecked = timestamp;
checkSubtypeRestrictions(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 SequenceOf_Type method checkThisValueSequenceOf.
/**
* Checks the SequenceOf_value kind value against this type.
* <p>
* Please note, that this function can only be called once we know for sure
* that the value is of set-of type.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expectedValue the kind of value expected here.
* @param incompleteAllowed wheather incomplete value is allowed or not.
* @param implicitOmit true if the implicit omit optional attribute was set
* for the value, false otherwise
*/
public boolean checkThisValueSequenceOf(final CompilationTimeStamp timestamp, final SequenceOf_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
boolean selfReference = false;
if (value.isIndexed()) {
boolean checkHoles = Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
BigInteger maxIndex = BigInteger.valueOf(-1);
final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(value.getNofComponents());
for (int i = 0, size = value.getNofComponents(); i < size; i++) {
final IValue component = value.getValueByIndex(i);
final IValue index = value.getIndexByIndex(i);
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
final IType tempType = TypeFactory.createType(Type_type.TYPE_INTEGER);
tempType.check(timestamp);
indexLast.setMyGovernor(tempType);
final IValue temporalValue = tempType.checkThisValueRef(timestamp, indexLast);
tempType.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, true, false, false));
if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(temporalValue.getValuetype())) {
checkHoles = false;
} else {
final BigInteger tempIndex = ((Integer_Value) temporalValue).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(getOfType());
final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
if (checkHoles) {
if (maxIndex.compareTo(BigInteger.valueOf(indexMap.size() - 1)) != 0) {
value.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
}
}
} else {
for (int i = 0, size = value.getNofComponents(); i < size; i++) {
final IValue component = value.getValueByIndex(i);
component.setMyGovernor(getOfType());
if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
if (!incompleteAllowed) {
component.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
}
} else {
final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class SequenceOf_Type method getFieldType.
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value indexValue = ((ArraySubReference) subreference).getValue();
if (indexValue != null) {
indexValue.setLoweridToReference(timestamp);
final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
switch(tempType) {
case TYPE_INTEGER:
final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
final Integer_Value lastInteger = (Integer_Value) last;
if (lastInteger.isNative()) {
final long temp = lastInteger.getValue();
if (temp < 0) {
indexValue.getLocation().reportSemanticError(MessageFormat.format(NONNEGATIVINDEXEXPECTED, temp));
indexValue.setIsErroneous(true);
}
} else {
indexValue.getLocation().reportSemanticError(MessageFormat.format(TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
indexValue.setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
indexValue.setIsErroneous(true);
break;
default:
indexValue.getLocation().reportSemanticError(INTEGERINDEXEXPECTED);
indexValue.setIsErroneous(true);
break;
}
}
if (getOfType() != null) {
return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
}
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
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 AbstractOfType method getFieldType.
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value indexValue = ((ArraySubReference) subreference).getValue();
if (indexValue != null) {
indexValue.setLoweridToReference(timestamp);
final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
switch(tempType) {
case TYPE_INTEGER:
final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
final Integer_Value lastInteger = (Integer_Value) last;
if (lastInteger.isNative()) {
final long temp = lastInteger.getValue();
if (temp < 0) {
indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.NONNEGATIVINDEXEXPECTED, temp));
indexValue.setIsErroneous(true);
}
} else {
indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
indexValue.setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
indexValue.setIsErroneous(true);
break;
default:
indexValue.getLocation().reportSemanticError(SequenceOf_Type.INTEGERINDEXEXPECTED);
indexValue.setIsErroneous(true);
break;
}
}
if (getOfType() != null) {
return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
}
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
Aggregations