Search in sources :

Example 76 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain 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)

Example 77 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Integer_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == namedNumbers) {
        parseBlockInt();
    }
    if (isErroneous || null == namedNumbers) {
        return;
    }
    /* check named numbers */
    final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final Identifier identifier = namedValue.getName();
        if (nameMap.containsKey(identifier.getName())) {
            final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            nameMap.put(identifier.getName(), identifier);
        }
    }
    final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final IValue value = namedValue.getValue();
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = value.getValueRefdLast(timestamp, referenceChain);
        referenceChain.release();
        if (last.getIsErroneous(timestamp)) {
            continue;
        }
        switch(last.getValuetype()) {
            case INTEGER_VALUE:
                {
                    final Integer_Value integerValue = (Integer_Value) last;
                    if (integerValue.isNative()) {
                        final Integer intValue = Integer.valueOf(integerValue.intValue());
                        if (valueMap.containsKey(intValue)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Duplicate number {0} for name `{1}''", intValue, namedValue.getName().getDisplayName()));
                            final NamedValue temp = valueMap.get(intValue);
                            temp.getLocation().reportSemanticError(MessageFormat.format("Number {0} is already assigned to name `{1}''", intValue, temp.getName().getDisplayName()));
                        } else {
                            valueMap.put(intValue, namedValue);
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("Integer value `{0}'' is too big to be used as a named number", integerValue.getValueValue()));
                        value.setIsErroneous(true);
                    }
                    break;
                }
            default:
                namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named number `{0}''", namedValue.getName().getDisplayName()));
                value.setIsErroneous(true);
                break;
        }
    }
    nameMap.clear();
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Example 78 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Sequence_Type method trCompsof.

/**
 * Check the components of member to reveal possible recursive
 * referencing.
 *
 * @param timestamp
 *                the actual compilation cycle.
 * @param referenceChain
 *                the reference chain used to detect recursive
 *                referencing
 */
public void trCompsof(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (trCompsofTimestamp != null && !trCompsofTimestamp.isLess(timestamp)) {
        return;
    }
    if (referenceChain != null) {
        components.trCompsof(timestamp, referenceChain, false);
    } else {
        final IReferenceChain temporalReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        components.trCompsof(timestamp, temporalReferenceChain, false);
        temporalReferenceChain.release();
    }
    trCompsofTimestamp = timestamp;
    components.trCompsof(timestamp, null, true);
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 79 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Set_Type method trCompsof.

/**
 * Check the components of member to reveal possible recursive
 * referencing.
 *
 * @param timestamp
 *                the actual compilation cycle.
 * @param referenceChain
 *                the reference chain used to detect recursive
 *                referencing
 */
public void trCompsof(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (trCompsofTimestamp != null && !trCompsofTimestamp.isLess(timestamp)) {
        return;
    }
    if (referenceChain != null) {
        components.trCompsof(timestamp, referenceChain, false);
    } else {
        final IReferenceChain temporalReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        components.trCompsof(timestamp, temporalReferenceChain, false);
        temporalReferenceChain.release();
    }
    trCompsofTimestamp = timestamp;
    components.trCompsof(timestamp, null, true);
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 80 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class ObjectClassField_Type method checkThisValueRef.

@Override
public /**
 * {@inheritDoc}
 */
IValue checkThisValueRef(final CompilationTimeStamp timestamp, final IValue value) {
    if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(value.getValuetype())) {
        final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IType refd = getTypeRefd(timestamp, tempReferenceChain);
        tempReferenceChain.release();
        if (null == refd) {
            return value;
        }
        return refd.checkThisValueRef(timestamp, value);
    }
    return value;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)154 IValue (org.eclipse.titan.designer.AST.IValue)102 IType (org.eclipse.titan.designer.AST.IType)55 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)18 Value (org.eclipse.titan.designer.AST.Value)18 Assignment (org.eclipse.titan.designer.AST.Assignment)16 BigInteger (java.math.BigInteger)15 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)14 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)13 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Reference (org.eclipse.titan.designer.AST.Reference)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)7 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)7 HashMap (java.util.HashMap)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)5