Search in sources :

Example 1 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class ASN1_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 expected kind of the value.
 * @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;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
    if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
        value.removeGeneratedValues();
    }
    final boolean isAsn = value.isAsn();
    boolean inSnyc = true;
    final int nofTypeComponents = getNofComponents(timestamp);
    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 (!hasComponentWithName(valueId)) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
            inSnyc = false;
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUBLICATEDFIELDAGAINASN1 : DUBLICATEDFIELDAGAINTTCN3, valueId.getDisplayName()));
                final Location tempLocation = componentMap.get(valueId.getName()).getLocation();
                tempLocation.reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName()));
                inSnyc = false;
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = getComponentByName(valueId);
            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()));
                    }
                } else {
                    CompField field2 = getComponentByIndex(sequenceIndex);
                    final CompField field2Original = field2;
                    boolean isOptional = field2.isOptional();
                    if (!isOptional && field2.hasDefault() && defaultAsOptional) {
                        isOptional = true;
                    }
                    while (implicitOmit && sequenceIndex < getNofComponents(timestamp) && componentField != field2 && isOptional) {
                        ++sequenceIndex;
                        field2 = getComponentByIndex(sequenceIndex);
                    }
                    if (sequenceIndex >= getNofComponents(timestamp) || 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);
                final IValue temporalValue = type.checkThisValueRef(timestamp, componentValue);
                boolean isOptional = componentField.isOptional();
                if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
                    isOptional = true;
                }
                selfReference |= type.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, isOptional, true, implicitOmit, strElem));
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier id = getComponentByIndex(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) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value) Location(org.eclipse.titan.designer.AST.Location)

Example 2 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class Parameterised_Reference method getRefDefdSimple.

/**
 * Resolve the formal parameters of the referenced assignment with the
 * help of the actual parameters. Instantiate a new assignment from it
 * and return a reference to this assignment.
 *
 * @return the reference to the newly instantiated assignment.
 */
public Defined_Reference getRefDefdSimple() {
    final Module module = myScope.getModuleScope();
    // This is a little trick, but otherwise we would not have the
    // true compilation timestamp
    final CompilationTimeStamp compilationTimeStamp = module.getLastImportationCheckTimeStamp();
    if (compilationTimeStamp == null) {
        // compilationTimeStamp = CompilationTimeStamp.getNewCompilationCounter(); //this forces re-check
        return null;
    }
    if (null != lastCheckTimeStamp && !lastCheckTimeStamp.isLess(compilationTimeStamp)) {
        if (isErroneous) {
            return null;
        }
        return finalReference;
    }
    lastCheckTimeStamp = compilationTimeStamp;
    final Assignment parass = assignmentReference.getRefdAssignment(compilationTimeStamp, true, null);
    if (null == parass) {
        isErroneous = true;
        return null;
    } else if (!(parass instanceof ASN1Assignment)) {
        assignmentReference.getLocation().reportSemanticError(ASSIGNMENTEXPECTED);
        isErroneous = true;
        return null;
    }
    final Ass_pard assPard = ((ASN1Assignment) parass).getAssPard();
    if (null == assPard) {
        assignmentReference.getLocation().reportSemanticError(PARAMETERISEDASSIGNMENTEXPECTED);
        isErroneous = true;
        return assignmentReference;
    }
    addAssignments(assPard, compilationTimeStamp);
    // Add the assignments made from the formal and actual
    // parameters to the actual module
    assignments.setRightScope(myScope);
    assignments.setParentScope(parass.getMyScope());
    assignments.setFullNameParent(this);
    assignments.check(compilationTimeStamp);
    // create a copy of the assignment and add it to the actual
    // module
    final ASN1Assignment newAssignment = ((ASN1Assignment) parass).newInstance(module);
    newAssignmentNameStart = new NameReStarter(new StringBuilder(module.getFullName()).append(INamedNode.DOT).append(newAssignment.getIdentifier().getDisplayName()).toString());
    newAssignmentNameStart.setFullNameParent(parass);
    newAssignment.setFullNameParent(newAssignmentNameStart);
    newAssignment.setLocation(location);
    newAssignment.getIdentifier().setLocation(assignmentReference.getLocation());
    ((ASN1Assignments) module.getAssignments()).addDynamicAssignment(compilationTimeStamp, newAssignment);
    newAssignment.setMyScope(assignments);
    newAssignment.check(compilationTimeStamp);
    final List<ISubReference> subreferences = new ArrayList<ISubReference>(1);
    subreferences.add(new FieldSubReference(newAssignment.getIdentifier()));
    finalReference = new Defined_Reference(module.getIdentifier(), subreferences);
    finalReference.setFullNameParent(this);
    finalReference.setMyScope(module);
    return finalReference;
}
Also used : FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) NameReStarter(org.eclipse.titan.designer.AST.NameReStarter) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Module(org.eclipse.titan.designer.AST.Module)

Example 3 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp 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 4 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class SwitchOnBoolean method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof SelectCase_Statement) {
        final SelectCase_Statement s = (SelectCase_Statement) node;
        final Value expression = s.getExpression();
        final CompilationTimeStamp ct = CompilationTimeStamp.getBaseTimestamp();
        if (expression != null && Type_type.TYPE_BOOL.equals(expression.getExpressionReturntype(ct, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
            problems.report(expression.getLocation(), ERROR_MESSAGE);
        }
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Value(org.eclipse.titan.designer.AST.Value)

Example 5 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class UnusedStartedRefFuncRetVal method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Start_Referenced_Component_Statement) {
        final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
        final Start_Referenced_Component_Statement s = (Start_Referenced_Component_Statement) node;
        final Value dereferredValue = s.getDereferredValue();
        if (dereferredValue == null) {
            return;
        }
        switch(dereferredValue.getValuetype()) {
            case EXPRESSION_VALUE:
                if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
                    return;
                }
                break;
            case TTCN3_NULL_VALUE:
            case FAT_NULL_VALUE:
                return;
            default:
                break;
        }
        IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (type != null) {
            type = type.getTypeRefdLast(timestamp);
        }
        if (type == null || type.getIsErroneous(timestamp)) {
            return;
        }
        if (!(type instanceof Function_Type)) {
            return;
        }
        final Function_Type functionType = (Function_Type) type;
        if (functionType.isRunsOnSelf()) {
            return;
        }
        if (!functionType.isStartable(timestamp)) {
            return;
        }
        final IType returnType = functionType.getReturnType();
        if (returnType == null) {
            return;
        }
        if (functionType.returnsTemplate()) {
            return;
        }
        IType lastType = returnType;
        boolean returnTypeCorrect = false;
        while (!returnTypeCorrect) {
            if (lastType.hasDoneAttribute()) {
                returnTypeCorrect = true;
                break;
            }
            if (lastType instanceof IReferencingType) {
                final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                final IType refd = ((IReferencingType) lastType).getTypeRefd(timestamp, refChain);
                refChain.release();
                if (lastType != refd) {
                    lastType = refd;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        if (!returnTypeCorrect) {
            final String msg = MessageFormat.format(PROBLEM, functionType.getTypename(), returnType.getTypename());
            problems.report(dereferredValue.getLocation(), msg);
        }
    }
}
Also used : IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Start_Referenced_Component_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Start_Referenced_Component_Statement) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)13 IType (org.eclipse.titan.designer.AST.IType)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 Module (org.eclipse.titan.designer.AST.Module)3 Type (org.eclipse.titan.designer.AST.Type)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Location (org.eclipse.titan.designer.AST.Location)2 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)2 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)2 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)2 Value (org.eclipse.titan.designer.AST.Value)2 HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1