Search in sources :

Example 51 with IReferenceChain

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

the class Start_Referenced_Component_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    Component_Type compType = null;
    if (componentReference != null) {
        compType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
    }
    if (dereferredValue == null) {
        return;
    }
    switch(dereferredValue.getValuetype()) {
        case EXPRESSION_VALUE:
            if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
                dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `refers' operation," + " which does not specify any function type.");
                return;
            }
            break;
        case TTCN3_NULL_VALUE:
        case FAT_NULL_VALUE:
            dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `null' value, which does not specify any function type.");
            return;
        default:
            break;
    }
    dereferredValue.setLoweridToReference(timestamp);
    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_type.TYPE_FUNCTION.equals(type.getTypetype())) {
        dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument of `{0}''", type.getTypename()));
        return;
    }
    final Function_Type functionType = (Function_Type) type;
    if (functionType.isRunsOnSelf()) {
        dereferredValue.getLocation().reportSemanticError("The argument cannot be a function reference with 'runs on self' clause");
        return;
    }
    if (!functionType.checkStartable(timestamp, getLocation())) {
        return;
    }
    final IType runsOnType = functionType.getRunsOnType(timestamp);
    if (compType != null && runsOnType != null && !runsOnType.isCompatible(timestamp, compType, null, null, null)) {
        final String message = MessageFormat.format("Component type mismatch: the component reference os of type `{0}'', but functions of type `{1}'' run on `{2}''", compType.getTypename(), functionType.getTypename(), runsOnType.getTypename());
        componentReference.getLocation().reportSemanticError(message);
    }
    final IType returnType = functionType.getReturnType();
    if (returnType != null) {
        if (functionType.returnsTemplate()) {
            dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Function of type `{0}'' return a template of type `{1}''," + " which cannot be retrieved when the test component terminates", functionType.getTypename(), returnType.getTypename()));
        } else {
            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) {
                dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Return type of function type `{0}'' is `{1}'', which does not have the `done'' extension attibute." + " When the test component terminates the returnes value cannot be retrived with a `done'' operation", functionType.getTypename(), returnType.getTypename()));
            }
        }
    }
    actualParameterList2 = new ActualParameterList();
    final FormalParameterList formalParameters = functionType.getFormalParameters();
    if (!formalParameters.checkActualParameterList(timestamp, parameters, actualParameterList2)) {
        actualParameterList2.setFullNameParent(this);
        actualParameterList2.setMyScope(getMyScope());
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 52 with IReferenceChain

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

the class Stop_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    final ExpressionStruct expression = new ExpressionStruct();
    if (componentReference == null) {
        aData.addBuiltinTypeImport("TitanComponent");
        expression.expression.append("TTCN_Runtime.stop_component(TitanComponent.ALL_COMPREF)");
    } else {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = componentReference.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (last.getValuetype() == Value_type.REFERENCED_VALUE) {
            // the argument is a simple component reference
            last.generateCodeExpressionMandatory(aData, expression, true);
            expression.expression.append(".stop()");
        } else {
            boolean refers_to_self = false;
            if (last.getValuetype() == Value_type.EXPRESSION_VALUE) {
                // the argument is a special component reference (mtc, self, etc.)
                switch(((Expression_Value) last).getOperationType()) {
                    case MTC_COMPONENT_OPERATION:
                        {
                            Definition myDefinition = myStatementBlock.getMyDefinition();
                            if (myDefinition != null && myDefinition.getAssignmentType() == Assignment_type.A_TESTCASE) {
                                refers_to_self = true;
                            }
                            break;
                        }
                    case SELF_COMPONENT_OPERATION:
                        refers_to_self = true;
                    default:
                        break;
                }
            }
            if (refers_to_self) {
                expression.expression.append("TTCN_Runtime.stop_execution()");
            } else {
                expression.expression.append("TTCN_Runtime.stop_component(");
                last.generateCodeExpression(aData, expression, false);
                expression.expression.append(')');
            }
        }
    }
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 53 with IReferenceChain

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

the class LogArgument method checkValue.

/**
 * Does the semantic checking of the log argument. Once it was
 * determined that it is a value.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value contained in the log argument.
 */
private void checkValue(final CompilationTimeStamp timestamp, final IValue value) {
    final IValue temp = value.setLoweridToReference(timestamp);
    switch(temp.getValuetype()) {
        case CHARSTRING_VALUE:
            internalLogArgument = new String_InternalLogArgument(((Charstring_Value) temp).getValue());
            break;
        case REFERENCED_VALUE:
            final Reference reference = ((Referenced_Value) temp).getReference();
            internalLogArgument = new Reference_InternalLogArgument(reference);
            checkReference(timestamp, reference);
            return;
        case EXPRESSION_VALUE:
            final Expression_Value castedValue = (Expression_Value) temp;
            if (Operation_type.MATCH_OPERATION.equals(castedValue.getOperationType())) {
                internalLogArgument = new Match_InternalLogArgument((MatchExpression) castedValue);
            } else {
                internalLogArgument = new Value_InternalLogArgument(temp);
            }
            break;
        case MACRO_VALUE:
            internalLogArgument = new Macro_InternalLogArgument((Macro_Value) temp);
            break;
        default:
            internalLogArgument = new Value_InternalLogArgument(temp);
            break;
    }
    final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (governor == null) {
        getLocation().reportSemanticError("Cannot determine the type of the argument");
        isErroneous = true;
        return;
    }
    // TODO: Is the next part necessary ???
    temp.setMyGovernor(governor);
    // TODO:WHY
    governor.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_TEMPLATE, true, true, true, true, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    if (ArgumentType.Value.equals(internalLogArgument.getArgumentType()) && !temp.isUnfoldable(timestamp)) {
        final IValue last = temp.getValueRefdLast(timestamp, chain);
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            internalLogArgument = new String_InternalLogArgument(((Charstring_Value) last).getValue());
        }
    } else if (ArgumentType.Macro.equals(internalLogArgument.getArgumentType())) {
        final IValue last = temp.getValueRefdLast(timestamp, chain);
        switch(last.getValuetype()) {
            case CHARSTRING_VALUE:
                internalLogArgument = new String_InternalLogArgument(((Charstring_Value) last).getValue());
                break;
            case MACRO_VALUE:
                break;
            default:
                internalLogArgument = new Value_InternalLogArgument(temp);
                break;
        }
    }
    chain.release();
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Macro_Value(org.eclipse.titan.designer.AST.TTCN3.values.Macro_Value) MatchExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.MatchExpression) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 54 with IReferenceChain

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

the class ObjectClassField_Type method checkRecursions.

@Override
public /**
 * {@inheritDoc}
 */
void checkRecursions(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (referenceChain.add(this)) {
        final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IType type = getTypeRefd(timestamp, tempReferenceChain);
        tempReferenceChain.release();
        if (null != type && !type.getIsErroneous(timestamp) && !this.equals(type)) {
            type.checkRecursions(timestamp, referenceChain);
        }
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 55 with IReferenceChain

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

the class ObjectClassField_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IType last = getTypeRefd(timestamp, tempReferenceChain);
    tempReferenceChain.release();
    boolean selfReference = false;
    if (null != last && last != this) {
        selfReference = last.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
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