Search in sources :

Example 1 with Def_Altstep

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Altguard method generateCodeInvokeInstance.

/**
 * Generate code for an alt guard
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param expression the expression to generate the source to
 */
public void generateCodeInvokeInstance(final JavaGenData aData, final ExpressionStruct expression) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.ALTSTEP_REFERENCE_VALUE) {
        Def_Altstep altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
        expression.expression.append(MessageFormat.format("{0}_instance(", altstep.getGenNameFromScope(aData, expression.expression, myScope, "")));
        actualParameterList.generateCodeAlias(aData, expression);
    } else {
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".invoke(");
        IType governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        governor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        actualParameterList.generateCodeAlias(aData, expression);
    }
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with Def_Altstep

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep in project titan.EclipsePlug-ins by eclipse.

the class Scope method checkRunsOnScope.

/**
 * Checks that operations that can only be executed in definitions that
 * have a runs on scope, are really executed in such a definition. And
 * that the required runs on component is compatible with the runs on
 * component of the definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param assignment
 *                the assignment to check (used or referred to by the
 *                statement).
 * @param errorLocation
 *                the location to report the error to.
 * @param operation
 *                the name of the operation.
 */
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
    Component_Type referencedComponent;
    switch(assignment.getAssignmentType()) {
        case A_ALTSTEP:
            referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
            break;
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
            break;
        case A_TESTCASE:
            referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
            break;
        default:
            return;
    }
    if (referencedComponent == null) {
        return;
    }
    final RunsOnScope runsOnScope = getScopeRunsOn();
    if (runsOnScope == null) {
        errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
    } else {
        final Component_Type localType = runsOnScope.getComponentType();
        if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
            errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
        }
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 3 with Def_Altstep

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep in project titan.EclipsePlug-ins by eclipse.

the class Shorthand method check.

protected void check(final Statement s, final Problems problems) {
    if (s == null) {
        return;
    }
    // shorthand statements are ignored inside alt statements
    INamedNode curr = s;
    while (curr != null) {
        if (curr instanceof Alt_Statement || curr instanceof Call_Statement) {
            return;
        }
        curr = curr.getNameParent();
    }
    final StatementBlock sb = s.getMyStatementBlock();
    if (sb == null) {
        return;
    }
    final Definition d = sb.getMyDefinition();
    if (d == null) {
        return;
    }
    // shorthand statements are marked in functions, test cases and altsteps that have a 'runs on' clause
    if (d instanceof Def_Function && ((Def_Function) d).getRunsOnType(timestamp) != null) {
        problems.report(s.getLocation(), ERROR_MESSAGE_PREFIX + typename + ERROR_MESSAGE_SUFFIX);
        return;
    }
    if (d instanceof Def_Altstep || d instanceof Def_Testcase) {
        problems.report(s.getLocation(), ERROR_MESSAGE_PREFIX + typename + ERROR_MESSAGE_SUFFIX);
    }
}
Also used : Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) INamedNode(org.eclipse.titan.designer.AST.INamedNode) Call_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Call_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 4 with Def_Altstep

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep in project titan.EclipsePlug-ins by eclipse.

the class Reference method checkActivateArgument.

/**
 * Checks whether this is a correct altstep activation reference.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 *
 * @return true if the altstep reference is correct, false otherwise.
 */
public final boolean checkActivateArgument(final CompilationTimeStamp timestamp) {
    final Assignment assignment = getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return false;
    }
    if (!Assignment_type.A_ALTSTEP.semanticallyEquals(assignment.getAssignmentType())) {
        getLocation().reportSemanticError(MessageFormat.format(ALTSTEPEXPECTED, assignment.getDescription()));
        setIsErroneous(true);
        return false;
    }
    if (myScope != null) {
        myScope.checkRunsOnScope(timestamp, assignment, this, "activate");
    }
    if (!subReferences.isEmpty()) {
        if (Subreference_type.parameterisedSubReference.equals(subReferences.get(0).getReferenceType())) {
            final ActualParameterList actualParameters = ((ParameterisedSubReference) subReferences.get(0)).getActualParameters();
            final FormalParameterList formalParameterList = ((Def_Altstep) assignment).getFormalParameterList();
            if (formalParameterList != null) {
                return formalParameterList.checkActivateArgument(timestamp, actualParameters, assignment.getDescription());
            }
        }
    }
    return false;
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)

Example 5 with Def_Altstep

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep in project titan.EclipsePlug-ins by eclipse.

the class ReferenceFinder method detectSmallestScope.

/**
 * Detect the smallest scope where the references should be searched
 *
 * @param assignment
 *                The assignment
 * @return The detected scope
 */
private Scope detectSmallestScope(final Assignment assignment) {
    Scope localScope = assignment.getMyScope();
    final Module module = localScope.getModuleScope();
    if (localScope instanceof StatementBlock) {
        final StatementBlock statementBlock = (StatementBlock) localScope;
        if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
            localScope = localScope.getParentScope();
        }
        if (statementBlock.hasEnclosingLoopOrAltguard()) {
            localScope = localScope.getParentScope();
        }
    }
    if (localScope instanceof NamedBridgeScope) {
        localScope = localScope.getParentScope();
    }
    // control,function,testcase,altstep then it is global
    if (localScope instanceof Assignments && localScope.getParentScope() == module) {
        localScope = module;
    } else // treat it as global definition
    if (localScope instanceof ComponentTypeBody) {
        // FIXME this still does not make them global, that is something completely different.
        localScope = module;
    } else // search for actual named parameters everywhere
    if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
        localScope = module;
    } else // For_Statement that must be searched
    if (localScope instanceof For_Loop_Definitions) {
        localScope = localScope.getParentScope();
    }
    return localScope;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) For_Loop_Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.For_Loop_Definitions) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Aggregations

Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)10 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)5 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)5 ArrayList (java.util.ArrayList)3 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 IType (org.eclipse.titan.designer.AST.IType)2 IValue (org.eclipse.titan.designer.AST.IValue)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 Altstep_Reference_Value (org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 INamedNode (org.eclipse.titan.designer.AST.INamedNode)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 LargeLocation (org.eclipse.titan.designer.AST.LargeLocation)1