use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_Type method checkThisTemplate.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
registerUsage(template);
template.setMyGovernor(this);
boolean selfReference = false;
switch(template.getTemplatetype()) {
case TEMPLATE_LIST:
final ITTCN3Template transformed = template.setTemplatetype(timestamp, Template_type.NAMED_TEMPLATE_LIST);
selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) transformed, isModified, implicitOmit, lhs);
break;
case NAMED_TEMPLATE_LIST:
selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) template, isModified, implicitOmit, lhs);
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
break;
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class SpecificValue_Template method checkSpecificValue.
@Override
public /**
* {@inheritDoc}
*/
void checkSpecificValue(final CompilationTimeStamp timestamp, final boolean allowOmit) {
if (specificValue == null) {
return;
}
switch(specificValue.getValuetype()) {
case EXPRESSION_VALUE:
// checked later
break;
case OMIT_VALUE:
if (!allowOmit) {
getLocation().reportSemanticError(OmitValue_Template.SPECIFICVALUEEXPECTED);
}
return;
default:
return;
}
final Expression_Value expressionValue = (Expression_Value) specificValue;
if (!Operation_type.APPLY_OPERATION.equals(expressionValue.getOperationType())) {
return;
}
expressionValue.setLoweridToReference(timestamp);
IType type = ((ApplyExpression) expressionValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
return;
}
type = type.getTypeRefdLast(timestamp);
if (Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
final ITTCN3Template template = setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
template.checkSpecificValue(timestamp, allowOmit);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template 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.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method reArrangeInitCode.
/**
* Walks through the templateinstance recursively and appends the java
* initialization sequence of all (directly or indirectly) referenced
* non-parameterized templates and the default values of all
* parameterized templates to source and returns the resulting string.
* Only objects belonging to module usageModule are initialized.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source for code generated
* @param usageModule the module where the template is to be used.
*/
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
if (derivedReference != null) {
final List<ISubReference> subreferences = derivedReference.getSubreferences();
if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
final ActualParameterList actualParameterList = subreference.getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
return;
}
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the referred template is parameterized
// the embedded referenced templates shall be visited
template.reArrangeInitCode(aData, source, usageModule);
// FIXME implement
} else {
// its entire body has to be initialized now
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
}
}
if (templateBody != null) {
templateBody.reArrangeInitCode(aData, source, usageModule);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class 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;
}
final int nofElements = 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;
}
final int nofElements = 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 (!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:
{
final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
}
final ITTCN3Template returnValue = 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;
}
Aggregations