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 Members¶
| Constructors | none |
| Static Methods | add_step_bottom_up_visitor(), create_warningclass(), get_mode(), get_multiprocess_mode(), lookup_warningclass() |
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_statesubclass.- The subclass must define all required
step_statemethods. - The member data values in v must be appropriately initialized: CodeSonar will invoke
v.copy()to create a freshstep_state(subclass) object every time the step traversal enters a function.
- The subclass must define all required
- 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
Ffor which at least one of the following is true.Fis contained in a compilation unit that was compiled in the increment.F'ssummary 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_stateclass 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])
- v (
-
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: Returns: The new warning class, as a
warningclass.Raises: result.ERROR_INVALID_PHASE_FOR_OPERATIONif called from a visitor.result.ERROR_PARAMETER_TOO_LARGEif_name has more than 1024 characters.
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 thewarningclasscreated 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_modeReturns: The analysis_modecorresponding 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_modeReturns: The multiprocess_modecorresponding 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
warningclasswith the specified name.Parameters: _name (str) – The name of the desired warning class.
Return type: Returns: The
warningclasswhose name is_name.Raises: result.ELEMENT_NOT_PRESENTif there is nowarningclassnamed_name.result.ERROR_INVALID_PHASE_FOR_OPERATIONif called from a drop visitor, or your plug-in’s top-level scope.
>>> analysis.lookup_warningclass('Buffer Underrun') <cs.warningclass Buffer Underrun>
-
static
lookup_warningclass(id)¶ Get the
warningclasswith the specified ID.Parameters: id (int) – The ID of the desired warning class.
Return type: Returns: The
warningclasswhose ID isid.Raises: result.ERROR_INVALID_ARGUMENTifidis 0.result.ERROR_INVALID_PHASE_FOR_OPERATIONif called from a drop visitor, or your plug-in’s top-level scope.result.ELEMENT_NOT_PRESENTif there is nowarningclasswith the specifiedid.
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>
-
static