Search in sources :

Example 1 with Start_Referenced_Component_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Start_Referenced_Component_Statement 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

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)1 IType (org.eclipse.titan.designer.AST.IType)1 Start_Referenced_Component_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Start_Referenced_Component_Statement)1 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)1 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)1 Value (org.eclipse.titan.designer.AST.Value)1 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)1