use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method evaluateIspresent.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method evaluateIsbound.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIsbound(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.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.Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method checkEnumItem.
/**
* Helper function for checking a single enumeration item. Checks if the
* name of the item is not a duplicate, and its value is in correct
* order. Also for items after the ellipsis if the value is missing a
* new one is assigned.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param item
* the enumeration item to work on.
* @param afterEllipsis
* true if the enumeration item is after the ellipsis.
* @param valueMap
* a value map so that the correctness of the item's
* value can be checked.
*/
private final void checkEnumItem(final CompilationTimeStamp timestamp, final EnumItem item, final boolean afterEllipsis, final Map<Integer, EnumItem> valueMap) {
final Identifier itemID = item.getId();
if (nameMap.containsKey(itemID.getName())) {
nameMap.get(itemID.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, itemID.getDisplayName()));
itemID.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATEDREPEATED, itemID.getDisplayName()));
} else {
nameMap.put(itemID.getName(), item);
}
if (!itemID.getHasValid(Identifier_type.ID_TTCN)) {
itemID.getLocation().reportSemanticWarning(MessageFormat.format(ASN1Assignment.UNREACHABLE, itemID.getDisplayName()));
}
final Value value = item.getValue();
if (!item.isOriginal()) {
if (afterEllipsis) {
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
valueMap.put(firstUnused, item);
// again.
if (null == value || ((Integer_Value) value).getValue() != firstUnused) {
final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
tempValue.setLocation(item.getLocation());
item.setValue(tempValue);
}
}
return;
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
return;
}
if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", itemID.getDisplayName()));
value.setIsErroneous(true);
return;
}
final Integer_Value temp = (Integer_Value) last;
if (!temp.isNative()) {
value.getLocation().reportSemanticError(MessageFormat.format("The numeric value of enumeration `{0}'' ({1}) is too large for being represented in memory", itemID.getDisplayName(), temp.getValueValue()));
value.setIsErroneous(true);
return;
}
final Integer enumValue = Integer.valueOf(temp.intValue());
if (afterEllipsis) {
if (enumValue >= firstUnused) {
valueMap.put(enumValue, item);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("ENUMERATED values shall be monotonically growing after the ellipsis: the value of `{0}'' must be at least {1} instead of {2}", itemID.getDisplayName(), firstUnused, enumValue));
value.setIsErroneous(true);
}
} else {
if (valueMap.containsKey(enumValue)) {
final Location tempLocation = valueMap.get(enumValue).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumValue, valueMap.get(enumValue).getId().getDisplayName()));
value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumValue, itemID.getDisplayName()));
setIsErroneous(true);
} else {
valueMap.put(enumValue, item);
}
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
if (asValue != null) {
asValue.generateCodeInit(aData, source, name);
return;
}
if (myGovernor == null) {
return;
}
// FIXME actually a bit more complex
final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
String ofTypeName;
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
ofTypeName = ((SequenceOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_SET_OF:
ofTypeName = ((SetOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_ARRAY:
ofTypeName = ((Array_Type) type).getElementType().getGenNameTemplate(aData, source, myScope);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing indexed template `" + getFullName() + "''");
return;
}
if (indexedTemplates.getNofTemplates() == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
}
// else is not needed as the loop will not run
for (int i = 0; i < indexedTemplates.getNofTemplates(); i++) {
final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
final Value index = indexedTemplate.getIndex().getValue();
if (Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, ((Integer_Value) index).getValue()));
} else {
final String tempId2 = aData.getTemporaryVariableName();
source.append(MessageFormat.format("TitanInteger {0} = new TitanInteger();\n", tempId2));
index.generateCodeInit(aData, source, tempId2);
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, tempId2));
}
indexedTemplate.getTemplate().generateCodeInit(aData, source, tempId);
source.append("}\n");
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
Aggregations