Performing Code Analysis

Before downloading, CODESYS uses static code analysis for checking the target system so that the source code of a project complies with defined coding guidelines according to the concept of the LINT analyzer.

These define the required set of rules in the Static Analysis Light dialog of the Project Settings.

The test is performed automatically each time the code is generated.

Any divergence from the rules is reported as an error message in the Build category of the message view. The error numbers are named “SA<number>”.

Attention

CODESYS analyzes only the application code of the project; libraries are ignored.

GVL variables of the POU view: If you have a project with several applications, then CODESYS handles only the objects in the active application. If you have only one application, then the objects in the common POU pool are also affected.

Note

“Static Analysis Light” includes a reduced set of rules in the default development system. An extended range of rules and additional naming conventions and metrics are provided after installing the CODESYS Static Analysis package.

See also

Pragma and Attribute for Static Analysis Light

By using pragmas and attributes, you can exclude parts of code from the test.

Requirement: The rules in the project settings are activated.

Note

Rule SA0004 “Multiple write access on output” cannot be deactivated by a pragma.

Pragma {analysis …}

Use the {analysis} pragma for enabling individual coding rules for specific lines of code in the implementation part of a program block. Insert the pragma above the first of these lines of code and after the last one. Then, provide the number of each rule to be deactivated and reactivated: Numbers are prepended with either a minus sign (-) to deactivate the rule or a plus sign (+) to reactivate the rule. Depending on the rule, use the pragma in the declaration part or implementation part of the programming object.

Syntax:

{analysis <sign><rule number>|,<other sign and rule combinations, comma-delimited>}

Example

You want to deactivate Rule 24 “typed literals only” for two lines (writing nTest:=DINT#99 is not necessary in these lines) and then reactivate it:

{analysis -24}
nTest := 99;
iVar := INT#2;
{analysis +24}

Defining several rules:

{analysis -10, -24, -18}

Attribute {attribute ‘analysis’ := ‘…’}

The {attribute 'analysis' := '<sign><rule number>'} attribute in the declaration part deactivates certain rules for an entire programming object:

Syntax:

{attribute 'analysis' := '<sign><rule number>|,<other rule numbers, comma-delimited>'}

Example

To deactivate Rules 33 and 31 for the entire structure:

{attribute 'analysis' := '-33, -31'}
TYPE My_Structure :
STRUCT
\ iLocal : INT;
\ uiLocal : UINT;
\ udiLocal : UDINT;
END_STRUCT
END_TYPE

To deactivate Rule 100 for the array:

{attribute 'analysis' := '-100'}
big: ARRAY[1..10000] OF DWORD;