use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkFromClause.
/**
* Checks a from clause reference and a sender redirect to see if they
* really references valid component types.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the source statement to report errors to.
* @param portType
* the type of the port used in the statement. Used to
* find the address type in effect.
* @param fromClause
* the from clause to check
* @param redirectSender
* the sender redirect to check.
*/
public static void checkFromClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final TemplateInstance fromClause, final Reference redirectSender) {
IType addressType = null;
if (portType != null) {
addressType = portType.getPortBody().getAddressType(timestamp);
} else if (source != null && source.getMyStatementBlock() != null) {
final Module module = source.getMyStatementBlock().getModuleScope();
if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
addressType = ((TTCN3Module) module).getAddressType(timestamp);
}
}
boolean senderRedirectChecked = false;
IType fromClauseType = null;
if (fromClause != null) {
fromClauseType = fromClause.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
ITTCN3Template templateBody = fromClause.getTemplateBody();
if (fromClauseType == null) {
if (addressType != null) {
templateBody = addressType.checkThisTemplateRef(timestamp, templateBody);
} else {
templateBody = templateBody.setLoweridToReference(timestamp);
}
fromClauseType = templateBody.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
if (fromClauseType == null) {
fromClauseType = checkSenderRedirect(timestamp, addressType, redirectSender);
senderRedirectChecked = true;
}
if (fromClauseType == null) {
// trying to figure out whether the template is
// a component reference or an SUT address
boolean isComponentReference;
if (Type_type.TYPE_COMPONENT.equals(templateBody.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE))) {
isComponentReference = true;
} else {
switch(templateBody.getTemplatetype()) {
case SPECIFIC_VALUE:
// treat 'null' as component
// reference
isComponentReference = Value_type.TTCN3_NULL_VALUE.equals(((SpecificValue_Template) templateBody).getSpecificValue().getValuetype());
break;
case ANY_VALUE:
case ANY_OR_OMIT:
isComponentReference = true;
break;
default:
isComponentReference = false;
break;
}
}
if (isComponentReference) {
// the argument is a component
// reference: get a pool type
fromClauseType = TypeFactory.createType(Type_type.TYPE_COMPONENT);
} else if (addressType != null) {
// the argument is not a component
// reference: try the address type
fromClauseType = addressType;
}
}
if (fromClauseType != null) {
fromClause.check(timestamp, fromClauseType);
if (addressType == null || !addressType.isCompatible(timestamp, fromClauseType, null, null, null)) {
// from_clause_type must be a component
// type
final IType last = fromClauseType.getTypeRefdLast(timestamp);
if (last.getIsErroneous(timestamp)) {
fromClauseType = null;
} else if (Type_type.TYPE_COMPONENT.equals(last.getTypetype())) {
if (Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
checkComponentReference(timestamp, source, ((SpecificValue_Template) templateBody).getSpecificValue(), true, true);
}
} else {
final String message = MessageFormat.format("The type of the template should be a component type {0} instead of `{1}''", (addressType == null) ? "" : "or the `address' type ", fromClauseType.getTypename());
fromClause.getLocation().reportSemanticError(message);
fromClauseType = null;
}
}
} else {
fromClause.getLocation().reportSemanticError("Cannot determine the type of the template");
}
}
if (!senderRedirectChecked) {
final IType senderRedirectType = checkSenderRedirect(timestamp, addressType, redirectSender);
if (fromClauseType != null && senderRedirectType != null && !fromClauseType.isIdentical(timestamp, senderRedirectType)) {
final String message = MessageFormat.format("The types in `from'' clause and `sender'' redirect are not the same: `{0}'' was expected instead of `{1}''", fromClauseType.getTypename(), senderRedirectType.getTypename());
senderRedirectType.getLocation().reportSemanticError(message);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Open_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;
if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
final Named_Template_List namedTemplateList = (Named_Template_List) template;
final int nofTemplates = namedTemplateList.getNofTemplates();
if (nofTemplates != 1) {
template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
}
for (int i = 0; i < nofTemplates; i++) {
final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
final Identifier name = namedTemplate.getName();
final CompField field = getComponentByName(name);
if (field == null) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
} else {
final Type fieldType = field.getType();
if (fieldType != null && !fieldType.getIsErroneous(timestamp)) {
ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
namedTemplateTemplate.setMyGovernor(fieldType);
namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
}
}
}
} else {
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class TemplateRestriction method check.
public static boolean check(final CompilationTimeStamp timestamp, final Definition definition, final ITTCN3Template template, final Reference ref) {
if (template.getIsErroneous(timestamp)) {
return false;
}
final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
Restriction_type tr = definition.getTemplateRestriction();
tr = getSubRestriction(tr, timestamp, ref);
switch(tr) {
case TR_NONE:
return false;
case TR_VALUE:
return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), false, template.getLocation());
case TR_OMIT:
return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), true, template.getLocation());
case TR_PRESENT:
return last.checkPresentRestriction(timestamp, definition.getAssignmentName(), template.getLocation());
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Anytype_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;
if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
final Named_Template_List namedTemplateList = (Named_Template_List) template;
final int nofTemplates = namedTemplateList.getNofTemplates();
if (nofTemplates != 1) {
template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
}
for (int i = 0; i < nofTemplates; i++) {
final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
final Identifier name = namedTemplate.getName();
final CompField field = compFieldMap.getCompWithName(name);
if (field != null) {
final Type fieldType = field.getType();
ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
namedTemplateTemplate.setMyGovernor(fieldType);
namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
}
}
} else {
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Signature_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, lhs);
break;
case NAMED_TEMPLATE_LIST:
selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) template, isModified, lhs);
break;
case SPECIFIC_VALUE:
((SpecificValue_Template) template).checkSpecificValue(timestamp, false);
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
break;
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
}
return selfReference;
}
Aggregations