use of org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression method evaluateTemplate.
/**
* Evaluates a checked template.
*
* @param template
* The template to evaluate
* @param timestamp
* The compilation timestamp
* @return The folded value or -1 if the template is unfoldable.
*/
private long evaluateTemplate(final ITTCN3Template template, final CompilationTimeStamp timestamp) {
switch(template.getTemplatetype()) {
case TEMPLATE_LIST:
{
final Template_List temp = (Template_List) template;
if (temp.templateContainsAnyornone()) {
final LengthRestriction lengthRestriction = temp.getLengthRestriction();
if (lengthRestriction == null) {
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without length restriction");
setIsErroneous(true);
return -1;
}
if (lengthRestriction instanceof RangeLenghtRestriction) {
final IValue upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
if (Value_type.REAL_VALUE.equals(upper.getValuetype()) && ((Real_Value) upper).isPositiveInfinity()) {
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without upper boundary in the length restriction");
setIsErroneous(true);
return -1;
}
if (Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
final int nofComponents = temp.getNofTemplatesNotAnyornone(timestamp);
if (nofComponents == ((Integer_Value) upper).intValue()) {
return nofComponents;
}
final IValue lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
if (lower != null && Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && ((Integer_Value) upper).intValue() == ((Integer_Value) lower).intValue()) {
return ((Integer_Value) upper).intValue();
}
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates without exact size");
setIsErroneous(true);
return -1;
}
} else {
final IValue restriction = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
if (Value_type.INTEGER_VALUE.equals(restriction.getValuetype())) {
return ((Integer_Value) restriction).intValue();
}
}
} else {
int result = 0;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
++result;
}
break;
default:
++result;
}
}
return result;
}
break;
}
case NAMED_TEMPLATE_LIST:
{
int result = 0;
final Named_Template_List temp = (Named_Template_List) template;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i).getTemplate();
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
++result;
}
break;
default:
++result;
}
}
return result;
}
case SUBSET_MATCH:
{
final LengthRestriction restriction = template.getLengthRestriction();
if (restriction instanceof SingleLenghtRestriction) {
final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
return ((Integer_Value) value).getValue();
} else {
return -1;
}
} else if (restriction instanceof RangeLenghtRestriction) {
final IValue minValue = ((RangeLenghtRestriction) restriction).getLowerValue(timestamp);
if (minValue.getValuetype() != Value_type.INTEGER_VALUE || minValue.isUnfoldable(timestamp)) {
return -1;
}
final SubsetMatch_Template temp = (SubsetMatch_Template) template;
if (temp.getNofTemplates() != ((Integer_Value) minValue).getValue()) {
return -1;
}
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
default:
return -1;
}
}
return temp.getNofTemplates();
}
return -1;
}
case SUPERSET_MATCH:
{
final LengthRestriction restriction = template.getLengthRestriction();
if (restriction instanceof SingleLenghtRestriction) {
final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
return ((Integer_Value) value).getValue();
} else {
return -1;
}
} else if (restriction instanceof RangeLenghtRestriction) {
final IValue maxValue = ((RangeLenghtRestriction) restriction).getUpperValue(timestamp);
if (maxValue.getValuetype() != Value_type.INTEGER_VALUE || maxValue.isUnfoldable(timestamp)) {
return -1;
}
final SupersetMatch_Template temp = (SupersetMatch_Template) template;
if (temp.getNofTemplates() != ((Integer_Value) maxValue).getValue()) {
return -1;
}
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
default:
return -1;
}
}
return temp.getNofTemplates();
}
return -1;
}
default:
return -1;
}
return -1;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template 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);
}
Aggregations