Search in sources :

Example 6 with RunsOnScope

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

the class RenameRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    // search
    idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
    // add the referred identifier to the map of found identifiers
    Identifier refdIdentifier = rf.getReferredIdentifier();
    Module refdModule = rf.assignment.getMyScope().getModuleScope();
    if (idsMap.containsKey(refdModule)) {
        idsMap.get(refdModule).add(new Hit(refdIdentifier));
    } else {
        ArrayList<Hit> identifierList = new ArrayList<Hit>();
        identifierList.add(new Hit(refdIdentifier));
        idsMap.put(refdModule, identifierList);
    }
    // scopes
    if (rf.fieldId == null) {
        // check that in all affected scopes there is no
        // definition with the new name
        Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
        if (rf.scope.getModuleScope() instanceof ASN1Module) {
            idType = Identifier_type.ID_ASN;
        }
        Identifier newId = new Identifier(idType, newIdentifierName);
        // check for assignment with given id in all sub-scopes
        // of the assignment's scope
        // TODO: this does not detect runs on <-> component
        // member conflicts because the RunsOnScope is not a
        // sub-scope of the ComponentTypeBody scope,
        // also it does not go into other modules
        Scope rootScope = rf.assignment.getMyScope();
        if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
            rootScope = rootScope.getParentScope();
        }
        SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
        module.accept(subScopeVisitor);
        List<Scope> subScopes = subScopeVisitor.getSubScopes();
        subScopes.add(rootScope);
        for (Scope ss : subScopes) {
            if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
                List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(newId));
                Reference reference = new Reference(null, subReferences);
                Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
                if (assignment != null && assignment.getLocation() != null) {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
                } else {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
                }
                // to avoid spam and multiple messages for the same conflict
                return result;
            }
        }
    } else {
        boolean alreadyExists = false;
        // name
        if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
            alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
        } else if (rf.type instanceof TTCN3_Enumerated_Type) {
            alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Choice_Type) {
            alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Enumerated_Type) {
            alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Sequence_Type) {
            alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Set_Type) {
            alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        }
        if (alreadyExists) {
            result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
        }
    }
    return result;
}
Also used : Identifier_type(org.eclipse.titan.designer.AST.Identifier.Identifier_type) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) SubScopeVisitor(org.eclipse.titan.designer.AST.SubScopeVisitor) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) ASN1_Enumerated_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)

Example 7 with RunsOnScope

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

Example 8 with RunsOnScope

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

the class SelfComponentExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (myGovernor == null || myScope == null) {
        return;
    }
    final IType governorLast = myGovernor.getTypeRefdLast(timestamp);
    if (!Type_type.TYPE_COMPONENT.equals(governorLast.getTypetype())) {
        return;
    }
    final RunsOnScope runsOnScope = myScope.getScopeRunsOn();
    if (runsOnScope == null) {
        return;
    }
    final Type componentType = runsOnScope.getComponentType();
    if (componentType != null && !governorLast.isCompatible(timestamp, componentType, null, null, null)) {
        getLocation().reportSemanticError(MessageFormat.format("Incompatible component types: a component reference of type `{0}'' was expected, but `self'' has type `{1}''", governorLast.getTypename(), componentType.getTypename()));
        setIsErroneous(true);
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 9 with RunsOnScope

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

the class Altstep_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Altstep altstep = null;
    switch(last.getValuetype()) {
        case ALTSTEP_REFERENCE_VALUE:
            altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
            if (altstep == null) {
                setIsErroneous(true);
                return selfReference;
            }
            altstep.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(ALTSTEPREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
    final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnSelf) {
            // check against the runs on component type of the scope of the value
            final Scope valueScope = value.getMyScope();
            if (valueScope == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
            if (runsOnScope != null) {
                final Component_Type componentType = runsOnScope.getComponentType();
                if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope " + "expects component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            } else {
                // compatibility using this component type as the scope
                if (valueScope instanceof ComponentTypeBody) {
                    final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                    if (!runsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' " + "clause and the current component definition is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' clause and the current scope does not have a `runs on'' clause," + " but {1} runs on `{2}''", getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            }
        } else {
            if (runsOnRef == null) {
                value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                value.setIsErroneous(true);
            } else {
                if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                }
            }
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 10 with RunsOnScope

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

the class Testcase_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    runsOnType = null;
    systemType = null;
    lastTimeChecked = timestamp;
    isErroneous = false;
    parseAttributes(timestamp);
    if (runsOnRef != null) {
        runsOnType = runsOnRef.chkComponentypeReference(timestamp);
        if (runsOnType != null) {
            final Scope formalParlistPreviosScope = formalParList.getParentScope();
            if (formalParlistPreviosScope instanceof RunsOnScope && ((RunsOnScope) formalParlistPreviosScope).getParentScope() == myScope) {
                ((RunsOnScope) formalParlistPreviosScope).setComponentType(runsOnType);
            } else {
                final Scope tempScope = new RunsOnScope(runsOnType, myScope);
                formalParList.setMyScope(tempScope);
            }
        }
    }
    if (systemRef != null) {
        systemType = systemRef.chkComponentypeReference(timestamp);
    }
    formalParList.reset();
    formalParList.check(timestamp, Assignment_type.A_TESTCASE);
    formalParList.checkNoLazyParams();
    checkSubtypeRestrictions(timestamp);
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Aggregations

RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)9 Scope (org.eclipse.titan.designer.AST.Scope)6 IType (org.eclipse.titan.designer.AST.IType)4 Assignment (org.eclipse.titan.designer.AST.Assignment)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 ArrayList (java.util.ArrayList)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 ASN1Module (org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)1 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)1 ASN1_Enumerated_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type)1 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)1 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Identifier_type (org.eclipse.titan.designer.AST.Identifier.Identifier_type)1 Module (org.eclipse.titan.designer.AST.Module)1 NamedBridgeScope (org.eclipse.titan.designer.AST.NamedBridgeScope)1