class analysis

Manages the warning classes ( warningclass ) and visitors (see Visitor Decorators) for the analysis.

You do not need to instantiate this class: all members are static.

For more information, see the CodeSonar manual:

analysis Details

class cs.analysis

Manages the warning classes ( warningclass ) and visitors (see Visitor Decorators) for the analysis.

static add_step_bottom_up_visitor(v[, langs = ( language.WILDCARD, )])

Add a bottom-up phase step visitor.

Parameters:
  • v (step_state) –

    An object of a concrete step_state subclass.

    • The subclass must define all required step_state methods.
    • The member data values in v must be appropriately initialized: CodeSonar will invoke v.copy() to create a fresh step_state (subclass) object every time the step traversal enters a function.
  • langs (iterable of language) – (optional) The visitor will be applied to CFG edges in compilation units whose language is one of these.
Return type:

NoneType

  • Side effects: Modifies self.

During the bottom-up analysis phase, the visitor will be applied to CFG edges contained in compilation units whose language appears in langs.

  • In base analyses, it will be applied to every such CFG edge in the project.
  • In incremental analyses, it will be applied only to CFG edges contained in procedures F for which at least one of the following is true.
    • F is contained in a compilation unit that was compiled in the increment.
    • F's summary is needed for incremental analysis and had to be recomputed because it relied on elements that were deleted or modified by changes in the increment.

For more information about step visitors, see the step_state class documentation and the Visitors manual page.

* [drop phase]              (incremental only)
* program setup visitors
* [serial depth-first phase]
* [parallel depth-first phase]
* [pointer analysis]
* program bottom-up visitors
*   (bottom-up traversal)
*     procedure bottom up visitors applied to proc1
*         [point bottom up visitors applied to points in proc1]
*         step visitors applied to proc1cfgedge1            <========
*         step visitors applied to proc1cfgedge2            <========
*         [remaining CFG edges in proc1]                    <--------
*     procedure bottom up finish visitors applied to proc1
*     [remaining procedures]                                <--------
* program bottom-up finish visitors
*

Only suitable for use in your plug-in’s top-level scope. Do not use it inside visitors.

>>> class print_step(step_state):
...    def __init__(self):
...        super(print_step, self).__init__()
...
...    def copy(self):
...        return print_step()
...
...    def transition(self,
...                   srcpt,
...                   edgelabel,
...                   destpt,
...                   tosrc_xform,
...                   edge_xform,
...                   tosrc_path):
...        # This output is written to the CodeSonar Analysis Log.
...        print('transitioning {0} --{1}--> {2} '.format( *[str(s) for s in (srcpt, edgelabel,destpt) ] ) )
>>> analysis.add_step_bottom_up_visitor(print_step(), [language.WILDCARD])
static create_warningclass(_name[, categories = ""[, rank = 10.0[, flags =  warningclass_flags.NONE[, significance =  warning_significance.UNSPECIFIED]]]])

Create and return a new warning class ( warningclass ).

Parameters:
  • _name (str) – The name for the new warning class. Do not specify a name containing the ‘$’ character: behavior is undefined in this case.
  • categories (str) – (optional) The categories for the class, as a semicolon-separated list of items, such as: “CWE:124;LANG.MEM.BO”. Can be empty.
  • rank (float) – (optional) The warning class “base rank”: a value that will be used as a starting point for calculating the rank for warnings of this class, which in turn will determine where those warnings appear in the recommended review order. Warnings from built in warning classes have ranks in the range 1 (most important) to 100 (least important).
  • flags (warningclass_flags) – (optional) The desired properties of the new warning class.
  • significance (warning_significance) – (optional) The significance setting for the class.
Return type:

warningclass

Returns:

The new warning class, as a warningclass .

Raises:

Only suitable for use in your plug-in’s top-level scope. Do not use it inside visitors.

If there are multiple calls to analysis.create_warningclass() with the same _name, the second and subsequent calls will ignore all other parameters and just return the warningclass created for the first call.

>>> analysis.create_warningclass('Suspicious Symbol Set', 'SUSP.SYMBOLSET', 5.3, warningclass_flags.PAD_ABOVE, warning_significance.STYLE)
<cs.warningclass Suspicious Symbol Set>
>>> analysis.create_warningclass('Suspicious Point Set', 'SUSP.POINTSET', 8.7, warningclass_flags.SHOW_ENTIRE_PROCEDURE)
<cs.warningclass Suspicious Point Set>
>>> analysis.create_warningclass('Suspicious Symbol', 'SUSP.SYM', 3.4)
<cs.warningclass Suspicious Symbol>
>>> analysis.create_warningclass('Suspicious Procedure', 'SUSP.PROC')
<cs.warningclass Suspicious Procedure>
>>> analysis.create_warningclass('Suspicious Point')
<cs.warningclass Suspicious Point>
static get_mode()

Get the analysis mode for the CodeSonar process in which the plug-in is running.

Return type:analysis_mode
Returns:The analysis_mode corresponding to the current mode of the CodeSonar process.
>>> analysis.get_mode()
<cs.analysis_mode normal>
static get_multiprocess_mode()

Get the multiprocess mode for the CodeSonar process in which the plug-in is running.

Return type:multiprocess_mode
Returns:The multiprocess_mode corresponding to the current mode of the CodeSonar process.

See Parallelism in CodeSonar: Analysis for more information.

>>> analysis.get_multiprocess_mode()
<cs.multiprocess_mode master>
static lookup_warningclass(_name)

Get the warningclass with the specified name.

Parameters:

_name (str) – The name of the desired warning class.

Return type:

warningclass

Returns:

The warningclass whose name is _name.

Raises:
>>> analysis.lookup_warningclass('Buffer Underrun')
<cs.warningclass Buffer Underrun>
static lookup_warningclass(id)

Get the warningclass with the specified ID.

Parameters:

id (int) – The ID of the desired warning class.

Return type:

warningclass

Returns:

The warningclass whose ID is id.

Raises:

To get the ID of a warningclass, use warningclass.get_id(). Note that a single warning class may have different ID values in different analyses.

>>> analysis.lookup_warningclass('Buffer Underrun').get_id()
39
>>> analysis.lookup_warningclass(39)
<cs.warningclass Buffer Underrun>