use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Float_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);
if (getIsErroneous(timestamp)) {
return false;
}
if (Template_type.VALUE_RANGE.equals(template.getTemplatetype())) {
final ValueRange range = ((Value_Range_Template) template).getValueRange();
final IValue lower = checkBoundary(timestamp, range.getMin());
final IValue upper = checkBoundary(timestamp, range.getMax());
range.setTypeType(getTypetypeTtcn3());
if (lower != null && upper != null) {
if (((Real_Value) lower).getValue() > ((Real_Value) upper).getValue()) {
template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
}
}
// TODO: some checks are still missing
} else {
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Integer_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);
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = false;
switch(template.getTemplatetype()) {
case VALUE_RANGE:
final ValueRange range = ((Value_Range_Template) template).getValueRange();
final IValue lower = checkBoundary(timestamp, range.getMin(), BOUNDARY_TYPE.LOWER);
final IValue upper = checkBoundary(timestamp, range.getMax(), BOUNDARY_TYPE.UPPER);
range.setTypeType(getTypetypeTtcn3());
// Template references are not checked.
if (lower != null && Value.Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && upper != null && Value.Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
if (!getIsErroneous(timestamp) && ((Integer_Value) lower).getValue() > ((Integer_Value) upper).getValue()) {
template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
template.setIsErroneous(true);
}
}
// TODO some checks are still missing
break;
case VALUE_LIST:
final ValueList_Template temp = (ValueList_Template) template;
for (int i = 0; i < temp.getNofTemplates(); i++) {
final TTCN3Template tmp = temp.getTemplateByIndex(i);
selfReference |= checkThisTemplate(timestamp, tmp, isModified, implicitOmit, lhs);
}
break;
case ANY_OR_OMIT:
case ANY_VALUE:
// Allowed
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName()));
template.setIsErroneous(true);
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(LENGTHRESTRICTIONNOTALLOWED);
template.setIsErroneous(true);
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template 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.ITTCN3Template 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.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method checkThisNamedTemplateList.
/**
* Checks the provided named template list against this type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param templateList
* the template list to check
* @param isModified
* true if the template is modified otherwise false.
* @param implicitOmit
* true it the template has implicit omit attribute set,
* false otherwise.
* @param lhs
* the assignment to check against
* @return true if the value contains a reference to lhs
*/
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List templateList, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
templateList.removeGeneratedValues();
boolean selfReference = false;
final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
final int nofTypeComponents = getNofComponents(timestamp);
final int nofTemplateComponents = templateList.getNofTemplates();
for (int i = 0; i < nofTemplateComponents; i++) {
final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
final Identifier identifier = namedTemplate.getName();
final String templateName = identifier.getName();
if (hasComponentWithName(identifier)) {
if (componentMap.containsKey(templateName)) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDFIRST, identifier.getDisplayName()));
componentMap.get(templateName).getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
} else {
componentMap.put(templateName, namedTemplate);
}
final CompField componentField = getComponentByName(identifier);
final Type type = componentField.getType();
if (type != null && !type.getIsErroneous(timestamp)) {
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
componentTemplate.setMyGovernor(type);
componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
boolean isOptional = componentField.isOptional();
if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
isOptional = true;
}
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
}
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
}
}
if (!isModified && strictConstantCheckingSeverity) {
// check missing fields
for (int i = 0; i < nofTypeComponents; i++) {
final Identifier identifier = getComponentIdentifierByIndex(i);
if (!componentMap.containsKey(identifier.getName())) {
if (getComponentByIndex(i).isOptional() && implicitOmit) {
templateList.addNamedValue(new NamedTemplate(new Identifier(Identifier_type.ID_TTCN, identifier.getDisplayName()), new OmitValue_Template(), false));
} else {
templateList.getLocation().reportSemanticError(MessageFormat.format(MISSINGTEMPLATEFIELD, identifier.getDisplayName(), getTypename()));
}
}
}
}
return selfReference;
}
Aggregations