Search in sources :

Example 36 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Sequence_Type method checkThisValueSeq.

/**
 * Checks the Sequence_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for
 * sure that the value is of sequence type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 * @param expectedValue
 *                the kind of value expected here.
 * @param incompleteAllowed
 *                wheather incomplete value is allowed or not.
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the value, false otherwise
 */
private boolean checkThisValueSeq(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    check(timestamp);
    final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
    if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
        value.removeGeneratedValues();
    }
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    final boolean isAsn = value.isAsn();
    boolean inSnyc = true;
    final int nofTypeComponents = realComponents.size();
    final int nofValueComponents = value.getNofComponents();
    int nextIndex = 0;
    CompField lastCompField = null;
    int sequenceIndex = 0;
    for (int i = 0; i < nofValueComponents; i++, sequenceIndex++) {
        final NamedValue namedValue = value.getSeqValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!realComponents.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
            inSnyc = false;
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                final String duplicateAgain = MessageFormat.format(isAsn ? DUPLICATEDFIELDAGAINASN1 : DUPLICATEDFIELDAGAINTTCN3, valueId.getDisplayName());
                namedValue.getLocation().reportSemanticError(duplicateAgain);
                final String duplicateFirst = MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName());
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(duplicateFirst);
                inSnyc = false;
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = realComponents.get(valueId.getName());
            if (inSnyc) {
                if (incompleteAllowed) {
                    boolean found = false;
                    for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                        final CompField field2 = getComponentByIndex(j);
                        if (valueId.getName().equals(field2.getIdentifier().getName())) {
                            lastCompField = field2;
                            nextIndex = j + 1;
                            found = true;
                        }
                    }
                    if (lastCompField != null && !found) {
                        namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? WRONGFIELDORDERASN1 : WRONGFIELDORDERTTCN3, valueId.getDisplayName(), lastCompField.getIdentifier().getDisplayName()));
                        inSnyc = false;
                    }
                } else {
                    CompField field2 = getComponentByIndex(sequenceIndex);
                    final CompField field2Original = field2;
                    while (implicitOmit && sequenceIndex < getNofComponents() && componentField != field2 && field2.isOptional()) {
                        field2 = getComponentByIndex(sequenceIndex);
                    }
                    if (sequenceIndex >= getNofComponents() || componentField != field2) {
                        namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? UNEXPECTEDFIELDASN1 : UNEXPECTEDFIELDTTCN3, valueId.getDisplayName(), field2Original.getIdentifier().getDisplayName()));
                    }
                }
            }
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
                    if (!incompleteAllowed) {
                        componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                    }
                } else {
                    final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
                    selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, implicitOmit, strElem));
                }
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier id = compFieldMap.fields.get(i).getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (getComponentByIndex(i).isOptional() && implicitOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

Example 37 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class CompFieldMap method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        lastCompilationTimeStamp = null;
        if (doubleComponents != null) {
            fields.addAll(doubleComponents);
            doubleComponents = null;
            lastUniquenessCheck = null;
        }
        boolean enveloped = false;
        int nofDamaged = 0;
        int leftBoundary = location.getOffset();
        int rightBoundary = location.getEndOffset();
        final int damageOffset = reparser.getDamageStart();
        IAppendableSyntax lastAppendableBeforeChange = null;
        IAppendableSyntax lastPrependableBeforeChange = null;
        for (int i = 0, size = fields.size(); i < size && !enveloped; i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            // move offset to commentLocation
            if (field.getCommentLocation() != null) {
                tempLocation.setOffset(field.getCommentLocation().getOffset());
            }
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
                if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                    lastAppendableBeforeChange = field;
                } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                    lastPrependableBeforeChange = field;
                }
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = field;
                }
                if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = field;
                }
            }
        }
        // extend the reparser to the calculated values if the damage was not enveloped
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
        // correct
        if (lastAppendableBeforeChange != null) {
            final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
            if (isBeingExtended) {
                leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (lastPrependableBeforeChange != null) {
            final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
            if (temp != null && reparser.endsWithToken(temp)) {
                rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (nofDamaged != 0) {
            removeStuffInRange(reparser);
        }
        for (int i = 0; i < fields.size(); i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            if (reparser.isAffectedAppended(tempLocation)) {
                try {
                    field.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    reparser.updateLocation(field.getLocation());
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        fields.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                    } else {
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            int result = reparse(reparser);
            if (result == 0) {
                return;
            }
            throw new ReParseException(Math.max(--result, 0));
        }
        return;
    }
    for (int i = 0, size = fields.size(); i < size; i++) {
        final CompField field = fields.get(i);
        field.updateSyntax(reparser, false);
        reparser.updateLocation(field.getLocation());
    }
    if (doubleComponents != null) {
        for (int i = 0, size = doubleComponents.size(); i < size; i++) {
            final CompField field = doubleComponents.get(i);
            field.updateSyntax(reparser, false);
            reparser.updateLocation(field.getLocation());
        }
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 38 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Set_Type method checkThisValueSet.

/**
 * Checks the Set_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for sure
 * that the value is of set type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value we expect to find.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param impliciOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
private boolean checkThisValueSet(final CompilationTimeStamp timestamp, final Set_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean impliciOmit, final boolean strElem) {
    value.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    final boolean isAsn = value.isAsn();
    final int nofValueComponents = value.getNofComponents();
    for (int i = 0; i < nofValueComponents; i++) {
        final NamedValue namedValue = value.getSequenceValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!realComponents.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDASN1 : NONEXISTENTFIELDTTCN3, namedValue.getName().getDisplayName(), getTypename()));
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDAGAINASN1 : DUPLICATEFIELDAGAINTTCN3, valueId.getDisplayName()));
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDFIRSTASN1 : DUPLICATEFIELDFIRSTTTCN3, valueId.getDisplayName()));
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = realComponents.get(valueId.getName());
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
                    if (!incompleteAllowed) {
                        componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                    }
                } else {
                    final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
                    selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, impliciOmit, strElem));
                }
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        final int nofTypeComponents = realComponents.size();
        CompField field;
        for (int i = 0; i < nofTypeComponents; i++) {
            field = compFieldMap.fields.get(i);
            final Identifier id = field.getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (field.isOptional() && impliciOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

Example 39 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Set_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String className = getGenNameOwn();
    final String classReadableName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final List<FieldInfo> namesList = new ArrayList<FieldInfo>();
    boolean hasOptional = false;
    for (final CompField compField : compFieldMap.fields) {
        final IType cfType = compField.getType();
        final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), false, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
        hasOptional |= compField.isOptional();
        namesList.add(fi);
    }
    for (final CompField compField : compFieldMap.fields) {
        final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
        compField.getType().generateCode(aData, tempSource);
    }
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    final RawASTStruct raw = convertRAWCodingAttributes(aData, source, hasRaw, namesList);
    RecordSetCodeGenerator.generateValueClass(aData, source, className, classReadableName, namesList, hasOptional, true, hasRaw, raw);
    RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, true);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : RawASTStruct(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct) ArrayList(java.util.ArrayList) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.RecordSetCodeGenerator.FieldInfo) IType(org.eclipse.titan.designer.AST.IType)

Example 40 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Sequence_Type method checkRecursions.

@Override
public /**
 * {@inheritDoc}
 */
void checkRecursions(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (components == null) {
        return;
    }
    if (referenceChain.add(this)) {
        for (int i = 0, size = components.getNofComps(); i < size; i++) {
            final CompField field = components.getCompByIndex(i);
            final IType type = field.getType();
            if (!field.isOptional() && type != null) {
                referenceChain.markState();
                type.checkRecursions(timestamp, referenceChain);
                referenceChain.previousState();
            }
        }
    }
}
Also used : 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