Skip to main content

Overview

Important

Static analysis is performed in the current project only for the application code. Libraries and their source codes are not analyzed.

CODESYS Static Analysis helps you during the implementation in order to write better and more readable code and to identify conflicting or unsupported program parts. In particular, potential sources of error are revealed. For example, locations are identified where test code is still contained. Or pointers are found which are not checked for 0 before dereferencing. Or (with the SA0119 rule) the locations are analyzed where object-orientation is used and ports to another development environment, which does not support the object orientation, thus making it impossible. As a reult, the portability of the code can be guaranteed.

For errors which are reported by Static Analysis based on precompile information, there is support for an immediate error handling ("Quickfix"). This allows you to quickly find and fix the locations in the code which are reported during the analysis.

To improve the readability of the source code, you can define naming conventions and check for compliance.

Furthermore, to assess the quality of the code, you can view metrics determined from the source code. Examples include the McCabe metric as a measure of code testability, or cognitive complexity as a measure of source code readability and maintainability. The data flow analysis performed in the static analysis is based on the principle of constant propagation.

  • With the Create → Perform Static Analysis menu command, you explicitly activate the static analysis.

  • In the Settings dialog, you enable a static analysis which is automatically performed after each code compilation.

  • You use pragma statements to exclude individual parts or blocks of code from the analysis.

  • In the Rules dialog, you can find out which rules are configured, how they are activated, and when the checks run on the respective rule. There you activate the rules which are relevant for you.

  • In the Naming Conventions dialog, you assign a prefix to each data type as it is then expected in the declarations. Deviations are reported.

  • In the Static Analysis Settings: Metrics dialog, you activate the metrics relevant for you.

  • With the Show Cognitive Complexity for Current Editor command, the determined increments are displayed line by line in the active editor.

  • The Show Values of Constant Propagation for Current Editor command analyzes the data flow in the active editor in detail and displays it path by path. Depending on this, code improvements are possible.

For more information, see: Rules, Metrics, and Pragmas and Attributes