use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Template_ActualParameter method generateCodeDefaultValue.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeDefaultValue(final JavaGenData aData, final StringBuilder source) {
if (template == null) {
return;
}
final TTCN3Template temp = template.getTemplateBody();
final Reference baseReference = template.getDerivedReference();
if (baseReference != null) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(MessageFormat.format("{0}.assign(", temp.get_lhs_name()));
baseReference.generateCode(aData, expression);
expression.expression.append(')');
}
// FIXME handle the needs conversion case
// temp.generateCodeInit(aData, source, temp.get_lhs_name());
// FIXME generate restriction check code if needed
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class ComplementedList_Template 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();
aData.addBuiltinTypeImport("Base_Template.template_sel");
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
setType.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
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.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class SubsetMatch_Template 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();
aData.addBuiltinTypeImport("Base_Template.template_sel");
String ofTypeName;
switch(myGovernor.getTypetype()) {
case TYPE_SEQUENCE_OF:
ofTypeName = ((SequenceOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_SET_OF:
ofTypeName = ((SetOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_ARRAY:
ofTypeName = ((Array_Type) myGovernor).getElementType().getGenNameTemplate(aData, source, myScope);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing subset match template `" + getFullName() + "''");
return;
}
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
expression.expression.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3}{4});\n", ofTypeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3});\n", ofTypeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
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.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class TTCN3Template method getReferencedArrayTemplate.
/**
* Checks whether array indexing is allowed for a given template sub
* reference or not.
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param arrayIndex
* the index to check.
* @param referenceChain
* the reference chain use to detect circular references.
*/
protected ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
switch(getTemplatetype()) {
case OMIT_VALUE:
case ANY_VALUE:
case ANY_OR_OMIT:
case VALUE_LIST:
case COMPLEMENTED_LIST:
case SUPERSET_MATCH:
case SUBSET_MATCH:
arrayIndex.getLocation().reportSemanticError(MessageFormat.format("Reference with index to an element of {0} `{1}''", getTemplateTypeName(), getFullName()));
break;
default:
break;
}
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;
} else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
return null;
} else {
final int nofElements = ((Template_List) this).getNofTemplates();
if (index > nofElements) {
final String message = MessageFormat.format("Index overflow in a template of `sequence of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
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;
} else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
return null;
} else {
final int nofElements = ((Template_List) this).getNofTemplates();
if (index > nofElements) {
final String message = MessageFormat.format("Index overflow in a template of `set of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
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 (Template_type.TEMPLATE_LIST.equals(getTemplatetype()) && !dimension.getIsErroneous(timestamp)) {
// re-base the index
index -= dimension.getOffset();
if (index < 0 || index > ((Template_List) this).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:
{
final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
}
if (this instanceof Template_List) {
final TTCN3Template returnValue = ((Template_List) this).getTemplateByIndex((int) index);
if (Template_type.TEMPLATE_NOTUSED.equals(returnValue.getTemplatetype())) {
if (baseTemplate != null) {
return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
}
return null;
}
return returnValue;
} else {
return null;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class ValueList_Template 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();
aData.addBuiltinTypeImport("Base_Template.template_sel");
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
expression.expression.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
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