use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method getSubrefsAsArray.
// This is the same as in ASN1_Sequence_type
@Override
public /**
* {@inheritDoc}
*/
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return true;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
return false;
case fieldSubReference:
{
final Identifier id = subreference.getId();
final CompField compField = components.getCompByName(id);
if (compField == null) {
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
}
final IType fieldType = compField.getType();
if (fieldType == null) {
return false;
}
final int fieldIndex = components.indexOf(compField);
subrefsArray.add(fieldIndex);
typeArray.add(this);
return fieldType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
}
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method isPresentAnyvalueEmbeddedField.
@Override
public /**
* {@inheritDoc}
*/
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return true;
}
if (beginIndex >= subreferences.size()) {
return true;
}
final ISubReference subReference = subreferences.get(beginIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return true;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId);
if (compField.isOptional()) {
return false;
}
return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField 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.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method getFieldType.
// This is the same as in ASN1_Sequence_Type
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
return null;
case fieldSubReference:
final Identifier id = subreference.getId();
final CompField compField = components.getCompByName(id);
if (compField == null) {
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
}
if (interruptIfOptional && compField.isOptional()) {
return null;
}
final Expected_Value_type internalExpectation = (expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE) ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
return compField.getType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Open_Type method addProposal.
/**
* Searches and adds a completion proposal to the provided collector if
* a valid one is found.
* <p>
* In case of structural types, the member fields are checked if they
* could complete the proposal.
*
* @param propCollector
* the proposal collector to add the proposal to, and
* used to get more information
* @param i
* index, used to identify which element of the reference
* (used by the proposal collector) should be checked for
* completions.
*/
@Override
public /**
* {@inheritDoc}
*/
void addProposal(final ProposalCollector propCollector, final int i) {
final List<ISubReference> subreferences = propCollector.getReference().getSubreferences();
if (subreferences.size() <= i) {
return;
}
final ISubReference subreference = subreferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
if (subreferences.size() > i + 1) {
// the reference might go on
final CompField compField = getComponentByName(subreference.getId());
if (compField == null) {
return;
}
final IType type = compField.getType();
if (type != null) {
type.addProposal(propCollector, i + 1);
}
} else {
// final part of the reference
final List<CompField> compFields = compFieldMap.getComponentsWithPrefix(subreference.getId().getName());
for (CompField compField : compFields) {
final String proposalKind = compField.getType().getProposalDescription(new StringBuilder()).toString();
propCollector.addProposal(compField.getIdentifier(), " - " + proposalKind, ImageCache.getImage(compField.getOutlineIcon()), proposalKind);
}
}
}
}
Aggregations