use of org.eclipse.titan.designer.AST.TTCN3.templates.IndexedTemplate 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");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.IndexedTemplate 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.templates.IndexedTemplate in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method getValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getValue() {
if (asValue != null) {
return asValue;
}
final Values values = new Values(true);
for (int i = 0, size = getNofTemplates(); i < size; i++) {
final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
final IndexedValue indexedValue = new IndexedValue(indexedTemplate.getIndex(), indexedTemplate.getTemplate().getValue());
indexedValue.setLocation(indexedTemplate.getLocation());
values.addIndexedValue(indexedValue);
}
asValue = new SequenceOf_Value(values);
asValue.setLocation(getLocation());
asValue.setMyScope(getMyScope());
asValue.setFullNameParent(getNameParent());
asValue.setMyGovernor(getMyGovernor());
return asValue;
}
Aggregations