Search in sources :

Example 51 with CompField

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;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Example 52 with CompField

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);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Example 53 with CompField

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;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) HashMap(java.util.HashMap) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Example 54 with CompField

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;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 55 with CompField

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);
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)64 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)62 Identifier (org.eclipse.titan.designer.AST.Identifier)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)32 Type (org.eclipse.titan.designer.AST.Type)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)19 IValue (org.eclipse.titan.designer.AST.IValue)19 ArrayList (java.util.ArrayList)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 HashMap (java.util.HashMap)9 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)9 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)9 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)9 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)8 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)8 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)8 Value (org.eclipse.titan.designer.AST.Value)8 Reference (org.eclipse.titan.designer.AST.Reference)6