use of org.eclipse.titan.designer.AST.TTCN3.templates.Template_List 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.Template_List 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.Template_List in project titan.EclipsePlug-ins by eclipse.
the class SubType method checkThisTemplateGeneric.
/**
* Does the semantic checking of the provided template according to the
* a specific sub-type.
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param template
* the template to be checked by the type.
*/
public void checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final ITTCN3Template template) {
if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
return;
}
if (template.getIsErroneous(timestamp)) {
return;
}
final TTCN3Template t = template.getTemplateReferencedLast(timestamp);
if (t.getIsErroneous(timestamp)) {
return;
}
switch(t.getTemplatetype()) {
case OMIT_VALUE:
case ANY_OR_OMIT:
case ANY_VALUE:
case VALUE_LIST:
case COMPLEMENTED_LIST:
case SPECIFIC_VALUE:
case TEMPLATE_REFD:
case TEMPLATE_INVOKE:
break;
case TEMPLATE_LIST:
if ((subtypeType == SubType_type.ST_RECORDOF) || (subtypeType == SubType_type.ST_SETOF)) {
if ((lengthRestriction == null) || (lengthRestriction.isEmpty() == TernaryBool.TTRUE)) {
break;
}
final SizeLimit minLimit = (SizeLimit) lengthRestriction.getMinimal();
final SizeLimit maxLimit = (SizeLimit) lengthRestriction.getMaximal();
final Template_List list = (Template_List) template;
final int fixComponents = list.getNofTemplatesNotAnyornone(timestamp);
if (!list.templateContainsAnyornone() && (fixComponents < minLimit.getSize().intValue())) {
template.getLocation().reportSemanticError(MessageFormat.format("At least {0} elements must be present in the list", minLimit.getSize().intValue()));
return;
} else if (!maxLimit.getInfinity() && (fixComponents > maxLimit.getSize().intValue())) {
template.getLocation().reportSemanticError(MessageFormat.format("There must not be more than {0} elements in the list", maxLimit.getSize().intValue()));
return;
}
}
// and set types
break;
case INDEXED_TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case VALUE_RANGE:
// FIXME implement checking
break;
case SUPERSET_MATCH:
{
if (subtypeType != SubType_type.ST_SETOF) {
template.getLocation().reportSemanticError("'superset' template matching mechanism can be used only with 'set of' types");
}
final SupersetMatch_Template temp = (SupersetMatch_Template) template;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
checkThisTemplateGeneric(timestamp, temp.getTemplateByIndex(i));
}
break;
}
case SUBSET_MATCH:
{
if (subtypeType != SubType_type.ST_SETOF) {
template.getLocation().reportSemanticError("'subset' template matching mechanism can be used only with 'set of' types");
}
final SubsetMatch_Template temp = (SubsetMatch_Template) template;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
checkThisTemplateGeneric(timestamp, temp.getTemplateByIndex(i));
}
break;
}
case BSTR_PATTERN:
checkThisTemplatePattern(template, "bitstring", ((BitString_Pattern_Template) template).getMinLengthOfPattern(), ((BitString_Pattern_Template) template).containsAnyornoneSymbol());
break;
case HSTR_PATTERN:
checkThisTemplatePattern(template, "hexstring", ((HexString_Pattern_Template) template).getMinLengthOfPattern(), ((HexString_Pattern_Template) template).containsAnyornoneSymbol());
break;
case OSTR_PATTERN:
checkThisTemplatePattern(template, "octetstring", ((OctetString_Pattern_Template) template).getMinLengthOfPattern(), ((OctetString_Pattern_Template) template).containsAnyornoneSymbol());
break;
case CSTR_PATTERN:
checkThisTemplatePattern(template, "charstring", ((CharString_Pattern_Template) template).getMinLengthOfPattern(), ((CharString_Pattern_Template) template).patternContainsAnyornoneSymbol());
break;
case USTR_PATTERN:
checkThisTemplatePattern(template, "universal charstring", ((UnivCharString_Pattern_Template) template).getMinLengthOfPattern(), ((UnivCharString_Pattern_Template) template).patternContainsAnyornoneSymbol());
break;
default:
break;
}
checkThisTemplateLengthRestriction(timestamp, t);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.Template_List in project titan.EclipsePlug-ins by eclipse.
the class ASN1_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.Template_List in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofTemplatesNotAnyornone.
/**
* Calculates the number of list members which are not the any or none
* symbol.
*
* @return the number calculated.
*/
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
int result = 0;
if (allFrom == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
if (!((SpecificValue_Template) allFrom).isReference()) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
// isReference branch:
final Reference reference = ((SpecificValue_Template) allFrom).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
allFrom.getLocation().reportSemanticError("Assignment not found");
allFrom.setIsErroneous(true);
return result;
}
ITTCN3Template body = null;
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
body = ((Def_Template) assignment).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
body = ((Def_Var_Template) assignment).getInitialValue();
break;
case A_CONST:
final IValue value = ((Def_Const) assignment).getValue();
return getNofValues(value, timestamp);
case A_MODULEPAR:
final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
return getNofValues(mvalue, timestamp);
case A_MODULEPAR_TEMPLATE:
body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
break;
default:
return result;
}
if (body == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
allFrom.setIsErroneous(true);
return result;
}
result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
return result;
}
Aggregations