use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_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.Named_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.Named_Template_List 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;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateEditLocations.
private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
for (ILocateableNode node : nodes) {
int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
if (node instanceof Def_Type) {
Def_Type df = (Def_Type) node;
Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
}
} else if (node instanceof Sequence_Value) {
Sequence_Value sv = (Sequence_Value) node;
vmLen += 6;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < sv.getNofComponents()) {
final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = sv.getNofComponents();
final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (node instanceof TTCN3Template) {
TTCN3Template template = (TTCN3Template) node;
vmLen += 6;
if (template instanceof Named_Template_List) {
Named_Template_List ntl = (Named_Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < ntl.getNofTemplates()) {
final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = ntl.getNofTemplates();
final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (template instanceof Template_List) {
Template_List tl = (Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < tl.getNofTemplates()) {
final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
} else {
int max = tl.getNofTemplates();
final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
}
}
}
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
Type_type tempType1 = null;
IValue value1 = null;
if (templateInstance1 != null) {
final ITTCN3Template temp = templateInstance1.getTemplateBody();
switch(temp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case INDEXED_TEMPLATE_LIST:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR13);
setIsErroneous(true);
return;
default:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
setIsErroneous(true);
return;
}
// temp is specific value:
value1 = ((SpecificValue_Template) temp).getSpecificValue();
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, internalExpectation);
switch(tempType1) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
value1.getValueRefdLast(timestamp, internalExpectation, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
final Type_type tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
if (((Integer_Value) last2).isNative()) {
final long i = ((Integer_Value) last2).getValue();
if (i < 0) {
value2.getLocation().reportSemanticError(OPERANDERROR3);
setIsErroneous(true);
}
} else {
value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR11, ((Integer_Value) last2).getValueValue()));
setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value2.getLocation().reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
break;
}
}
if (value3 != null) {
value3.setLoweridToReference(timestamp);
final Type_type tempType3 = value3.getExpressionReturntype(timestamp, expectedValue);
switch(tempType3) {
case TYPE_INTEGER:
final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
if (((Integer_Value) last3).isNative()) {
final long i = ((Integer_Value) last3).getValue();
if (i < 0) {
value3.getLocation().reportSemanticError(OPERANDERROR4);
setIsErroneous(true);
}
} else {
value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR12, ((Integer_Value) last3).getValueValue()));
setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value3.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
break;
}
}
Type_type tempType4 = null;
IValue value4 = null;
if (templateInstance4 != null) {
final ITTCN3Template temp = templateInstance4.getTemplateBody();
switch(temp.getTemplatetype()) {
case SPECIFIC_VALUE:
value4 = ((SpecificValue_Template) temp).getSpecificValue();
break;
case TEMPLATE_LIST:
if (!((Template_List) temp).isValue(timestamp)) {
templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
return;
}
case NAMED_TEMPLATE_LIST:
case INDEXED_TEMPLATE_LIST:
tempType4 = templateInstance4.getExpressionReturntype(timestamp, expectedValue);
if (Type_type.TYPE_UNDEFINED.equals(tempType4)) {
templateInstance4.getLocation().reportSemanticError(OPERANDERROR13);
}
return;
default:
templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
return;
}
value4.setLoweridToReference(timestamp);
tempType4 = value4.getExpressionReturntype(timestamp, internalExpectation);
switch(tempType4) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
value4.getValueRefdLast(timestamp, internalExpectation, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
break;
}
}
if (tempType1 != null && tempType4 != null && !tempType1.equals(tempType4) && !getIsErroneous(timestamp)) {
location.reportSemanticError(OPERANDERROR7);
setIsErroneous(true);
}
checkExpressionOperandsHelper(timestamp, value1, expectedValue, referenceChain);
}
Aggregations