use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method checkThisNamedTemplateList.
// see void Type::chk_this_template_Signature(Template *t, namedbool incomplete_allowed) in Type_chk.cc
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List template, final boolean isModified, final Assignment lhs) {
final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
boolean inSynch = true;
// TODO: alternatives:formalParList.getNofInParameters(); formalParList.getNofOutParameters()
final int nofTypeParameters = getNofParameters();
final int nofTemplateComponents = template.getNofTemplates();
int tI = 0;
boolean selfReference = false;
for (int vI = 0; vI < nofTemplateComponents; vI++) {
final NamedTemplate namedTemplate = template.getTemplateByIndex(vI);
final Identifier identifier = namedTemplate.getName();
final String name = identifier.getName();
if (hasParameterWithName(name)) {
if (componentMap.containsKey(name)) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, identifier.getDisplayName(), getTypename()));
componentMap.get(name).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEPARAMETERFIRST, identifier.getDisplayName()));
inSynch = false;
} else {
componentMap.put(name, namedTemplate);
}
final SignatureFormalParameter parameter = formalParList.getParameterByName(name);
if (inSynch) {
SignatureFormalParameter parameter2 = null;
boolean found = false;
for (; tI < nofTypeParameters && !found; tI++) {
parameter2 = formalParList.getParameterByIndex(tI);
if (parameter == parameter2) {
found = true;
break;
}
}
if (!found) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDPARAMETER, identifier.getDisplayName()));
inSynch = false;
}
}
final Type parameterType = parameter.getType();
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
// FIXME: will be overwritten?
componentTemplate.setMyGovernor(parameterType);
componentTemplate = parameterType.checkThisTemplateRef(timestamp, componentTemplate);
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, parameterType, isModified, false, false, true, false, lhs);
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, identifier.getDisplayName(), getTypename()));
inSynch = false;
}
}
if (isModified) {
SignatureFormalParameter firstUndefIn = null;
SignatureFormalParameter firstUndefOut = null;
for (int i = 0; i < nofTypeParameters; i++) {
final SignatureFormalParameter parameter = formalParList.getParameterByIndex(i);
final Identifier identifier = parameter.getIdentifier();
if (!componentMap.containsKey(identifier.getName()) || Template_type.TEMPLATE_NOTUSED.equals(componentMap.get(identifier.getName()).getTemplate().getTemplatetype())) {
switch(parameter.getDirection()) {
case PARAM_IN:
if (firstUndefIn == null) {
firstUndefIn = parameter;
}
break;
case PARAM_OUT:
if (firstUndefOut == null) {
firstUndefOut = parameter;
}
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE1, identifier.getDisplayName()));
break;
}
}
}
if (firstUndefIn != null && firstUndefOut != null) {
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE2, firstUndefIn.getIdentifier().getDisplayName(), firstUndefOut.getIdentifier().getDisplayName()));
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Choice_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) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
} else {
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.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_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
* is the template modified or not ?
* @param implicitOmit
* true if the implicit omit optional attribute was set
* for the template, false otherwise
*/
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();
final int nofTemplateComponents = templateList.getNofTemplates();
boolean inSync = true;
final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
CompField lastComponentField = null;
int nextIndex = 0;
for (int i = 0; i < nofTemplateComponents; i++) {
final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
final Identifier identifier = namedTemplate.getName();
final String templateName = identifier.getName();
if (realComponents.containsKey(templateName)) {
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.getName());
if (inSync) {
if (isModified) {
boolean found = false;
for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
final CompField componentField2 = getComponentByIndex(j);
if (templateName.equals(componentField2.getIdentifier().getName())) {
lastComponentField = componentField2;
nextIndex = j + 1;
found = true;
}
}
if (!found && lastComponentField != null) {
final String message = MessageFormat.format(INCORRECTTEMPLATEFIELDORDER, identifier.getDisplayName(), lastComponentField.getIdentifier().getDisplayName(), getFullName());
namedTemplate.getLocation().reportSemanticError(message);
inSync = false;
}
} else if (strictConstantCheckingSeverity) {
final CompField componentField2 = getComponentByIndex(i);
if (componentField2 != componentField) {
if (!componentField2.isOptional() || (componentField2.isOptional() && !implicitOmit)) {
final String message = MessageFormat.format(UNEXPECTEDTEMPLATEFIELD, identifier.getDisplayName(), componentField2.getIdentifier().getDisplayName());
namedTemplate.getLocation().reportSemanticError(message);
inSync = false;
}
}
}
}
Type type = componentField.getType();
if (type == null) {
// report Internal error?
return selfReference;
}
type = (Type) type.getTypeRefdLast(timestamp);
if (type == null) {
// report Internal error?
return selfReference;
}
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
componentTemplate.setMyGovernor(type);
componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
final boolean isOptional = componentField.isOptional();
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
inSync = false;
}
}
if (!isModified && strictConstantCheckingSeverity) {
// check missing fields
for (int i = 0; i < nofTypeComponents; i++) {
final Identifier identifier = getComponentIdentifierByIndex(i);
if (identifier == null) {
continue;
}
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;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_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 is the template modified or not ?
* @param implicitOmit indicates whether the template has the implicit omit attribute set or not.
*/
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();
final int nofTemplateComponents = templateList.getNofTemplates();
final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
for (int i = 0; i < nofTemplateComponents; i++) {
final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
final Identifier identifier = namedTemplate.getName();
final String templateName = identifier.getName();
if (realComponents.containsKey(templateName)) {
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.getName());
final Type type = componentField.getType();
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
componentTemplate.setMyGovernor(type);
componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
final boolean isOptional = componentField.isOptional();
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