Search in sources :

Example 6 with Def_Altstep

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

the class RefersExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (referred == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || referredAssignment == null) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RTEMP:
        case A_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Function) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Extfunction) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_ALTSTEP:
            lastValue = new Altstep_Reference_Value((Def_Altstep) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_TESTCASE:
            lastValue = new Testcase_Reference_Value((Def_Testcase) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) Testcase_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 7 with Def_Altstep

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

the class RunsOnScopeReduction method process.

@Override
protected void process(IVisitableNode node, Problems problems) {
    final Set<Identifier> definitions = new HashSet<Identifier>();
    final Identifier componentIdentifier;
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final Identifier identifier;
    boolean isTestCase = false;
    if (node instanceof Def_Function) {
        final Def_Function variable = (Def_Function) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else if (node instanceof Def_Altstep) {
        final Def_Altstep variable = (Def_Altstep) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else {
        final Def_Testcase variable = (Def_Testcase) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
        isTestCase = true;
    }
    final ReferenceCheck chek = new ReferenceCheck();
    node.accept(chek);
    definitions.addAll(chek.getIdentifiers());
    if (definitions.isEmpty()) {
        if (isTestCase) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
        } else {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
        }
    } else if (!definitions.contains(componentIdentifier)) {
        ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
        if (definitions.size() == 1) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
        } else {
            // FIXME: implement other cases
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ArrayList(java.util.ArrayList) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) HashSet(java.util.HashSet)

Example 8 with Def_Altstep

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

the class MetricData method measure.

/**
 * Execute the metrics on the project and compose the results.
 * <p>
 * Note that internally the project is locked.
 *
 * @param project
 *            the project to analyze
 *
 * @return the composed result of the measurements
 */
public static MetricData measure(final IProject project) {
    synchronized (project) {
        // reading the lists of altsteps, testcases, functions and modules
        // that are to be measured
        final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
        final Risks risks = new Risks();
        final MutableMetricData data = new MutableMetricData(risks);
        final List<Module> modules = new ArrayList<Module>();
        final Map<Module, List<Def_Function>> functions = new HashMap<Module, List<Def_Function>>();
        final Map<Module, List<Def_Testcase>> testcases = new HashMap<Module, List<Def_Testcase>>();
        final Map<Module, List<Def_Altstep>> altsteps = new HashMap<Module, List<Def_Altstep>>();
        for (final String modName : parser.getKnownModuleNames()) {
            final Module module = parser.getModuleByName(modName);
            modules.add(module);
        }
        for (final Module module : modules) {
            final List<Def_Function> funs = new ArrayList<Def_Function>();
            final List<Def_Testcase> tcs = new ArrayList<Def_Testcase>();
            final List<Def_Altstep> als = new ArrayList<Def_Altstep>();
            module.accept(new DefinitionCollector(funs, tcs, als));
            functions.put(module, funs);
            testcases.put(module, tcs);
            altsteps.put(module, als);
        }
        data.modules = Collections.unmodifiableList(modules);
        data.functions = Collections.unmodifiableMap(functions);
        data.testcases = Collections.unmodifiableMap(testcases);
        data.altsteps = Collections.unmodifiableMap(altsteps);
        MetricData immutableData = new MetricData(project, data);
        // initiate the metrics
        final Metrics metrics = new Metrics();
        for (final AltstepMetric am : AltstepMetric.values()) {
            metrics.get(am).init(immutableData);
        }
        for (final FunctionMetric fm : FunctionMetric.values()) {
            metrics.get(fm).init(immutableData);
        }
        for (final TestcaseMetric tm : TestcaseMetric.values()) {
            metrics.get(tm).init(immutableData);
        }
        for (final ModuleMetric mm : ModuleMetric.values()) {
            metrics.get(mm).init(immutableData);
        }
        for (final ProjectMetric pm : ProjectMetric.values()) {
            metrics.get(pm).init(immutableData);
        }
        // altstep metrics and statistics
        for (final AltstepMetric am : AltstepMetric.values()) {
            final Statistics projectStats = measureEntities(data.altsteps, metrics.get(am), immutableData, data.altstepMetrics, data.altstepModuleStats);
            data.altstepProjectStats.put(am, projectStats);
            immutableData = new MetricData(project, data);
        }
        // function metrics and statistics
        for (final FunctionMetric fm : FunctionMetric.values()) {
            final Statistics projectStats = measureEntities(data.functions, metrics.get(fm), immutableData, data.functionMetrics, data.functionModuleStats);
            data.functionProjectStats.put(fm, projectStats);
            immutableData = new MetricData(project, data);
        }
        // testcase metrics and statistics
        for (final TestcaseMetric tm : TestcaseMetric.values()) {
            final Statistics projectStats = measureEntities(data.testcases, metrics.get(tm), immutableData, data.testcaseMetrics, data.testcaseModuleStats);
            data.testcaseProjectStats.put(tm, projectStats);
            immutableData = new MetricData(project, data);
        }
        // module metrics and statistics
        for (final ModuleMetric mm : ModuleMetric.values()) {
            final Map<Module, Number> metricResults = new HashMap<Module, Number>();
            final int numberOfModules = data.modules.size();
            double[] projectLevelResults = new double[numberOfModules];
            int projectLevelCounter = 0;
            for (final Module module : data.modules) {
                final Number result = metrics.get(mm).measure(immutableData, module);
                projectLevelResults[projectLevelCounter++] = result.doubleValue();
                metricResults.put(module, result);
            }
            data.moduleMetrics.put(mm, metricResults);
            data.moduleProjectStats.put(mm, new Statistics(projectLevelResults, mm, risks.getRisk(mm)));
        }
        // project metrics
        for (final ProjectMetric pm : ProjectMetric.values()) {
            final Number result = metrics.get(pm).measure(immutableData, project);
            data.projectMetrics.put(pm, result);
        }
        return immutableData;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Metrics(org.eclipse.titanium.metrics.implementation.Metrics) ArrayList(java.util.ArrayList) List(java.util.List) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Module(org.eclipse.titan.designer.AST.Module)

Example 9 with Def_Altstep

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

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

the class ModuleStatNode method getChildren.

@Override
public Object[] getChildren(final MetricData data) {
    if (initialized) {
        return children;
    }
    final List<? super IContentNode> c = new ArrayList<IContentNode>();
    if (metric instanceof FunctionMetric) {
        for (final Def_Function f : data.getFunctions().get(module)) {
            c.add(new FunctionNode((FunctionMetric) metric, f));
        }
    } else if (metric instanceof TestcaseMetric) {
        for (final Def_Testcase t : data.getTestcases().get(module)) {
            c.add(new TestcaseNode((TestcaseMetric) metric, t));
        }
    } else if (metric instanceof AltstepMetric) {
        for (final Def_Altstep a : data.getAltsteps().get(module)) {
            c.add(new AltstepNode((AltstepMetric) metric, a));
        }
    } else {
        throw new AssertionError("ModuleStatNode should have a subModule-metric");
    }
    children = c.toArray();
    initialized = true;
    return children;
}
Also used : TestcaseMetric(org.eclipse.titanium.metrics.TestcaseMetric) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) AltstepMetric(org.eclipse.titanium.metrics.AltstepMetric) ArrayList(java.util.ArrayList) FunctionMetric(org.eclipse.titanium.metrics.FunctionMetric) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

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