Machine Expert > V2.1 > Software > Librerie, Modellis e Esempi > Librerie > CODESYS Libraries > Library Development Summary > Concepts and Elements > Static Analysis

Static Analysis

Note

The CODESYS Professional Developer Edition provides a tool for static code analysis. A rule set is included for automatically checking the naming convention described above.

Under some circumstances it would be necessary to deactivate a specific rule. This can be achieved with a pair of attributes.

{analysis -46}
/// ...
/// some code which does not conforme to rule SA0046
/// ...
{analysis +46}

PLCopen - Coding Guidelines

The official PLCopen document Coding Guidelines summarises the results of the PLCopen workgroup Software Construction Guidelines Task Force Coding Guidelines. It's first official published version dates from April 20, 2016. The aim of this guidelines is to define a set of rules and to provide a PLCopen proposal how these rules can be used.

Please take a look to the homepage of the PLCopen for the related documents.

Every Rule has an classification number, as shown hereunder:

Rule

CODESYS

Name

Comment

N1

SA0047

Avoid physical addresses

N2

Define type prefixes for Variables

see: Naming Conventions

N3

Define the names to avoid

see: Forbidden Symbols

N4

Define the use of case (capitals)

N5

SA0013

Local names shall not shadow global names

N6

SA0101

Define an acceptable name length

N7

Define naming rules for namespaces

see: Namespace

N8

Define the acceptable character set

see: Allow unicode characters for identifiers

N9

SA0013, SA0027

Different element types should not bear the same name

N10

Define name prefixes for user defined types

see: Description of the prefix for a data type

C1

Comments shall describe the intention of the code

C2

SA0162

All elements shall be commented

C3

SA0163

Avoid nested comments

C4

SA0140

Comments may not include code

Exception, see: Literal Blocks

C5

SA0164

Use single line comments

see: LibDocContent

C6

Define comments language

Library developer employed by 3S use English for their comments

CP1

SA0047, SA0048

Access to a member shall be by name

CP2

SA0001, SA0031

All code shall be used in the application

CP3

All variables shall be initialized before being used

see: CODESYS initialize all variables with all bits zero by default

CP4

SA0028

Direct addressing should not overlap

CP5

Applications shall be well designed

CP6

Avoid external variables in functions and function blocks

CP7

SA0009

Error information shall be tested

CP8

SA0054

Floating point comparison shall not be equality or inequality

CP9

SA0150

Limit the complexity of POU code

see: Static Analysis - Metrics in the OnlineHelp

CP10

SA0006

Avoid multiple writes from multiple tasks

CP11

Manage synchronization among tasks

see: CAA_types.library BOLT, SEMA

CP12

SA0004

Physical outputs shall be written once per PLC cycle

CP13

SA0160

POUs shall not call themselves directly or indirectly

CP14

SA0090

POUs shall have a single point of exit

CP15

Read a variable written by another task only once per cycle

CP16

SA0165

Tasks shall only call program POUs and not Function Blocks

CP17

SA0009

Usage of parameters shall match their declaration mode

CP18

SA0121

Use of global variables shall be limited

CP19

Usage of jump and return should be avoided

CP20

SA0105

Function block instances should be called only once

CP21

SA0073

Use VAR_TEMP for temporary variable declaration

CP22

SA0011, SA0033

Select appropriate data type

CP23

SA0166

Define maximum number of input/output/in-out variables of a POU

CP24

SA0032, SA0033, SA0035, SA0036

Do not declare variables that are not used

CP25

SA0019

Data types conversion should be explicit

CP26

SA0043

A global variable may be written only by one PROGRAM

CP27

Avoid deprecated features

CP28

Time and physical measures comparison shall not be equality or inequality

L1

Define indentation

Library developer employed by 3S use four spaces

L2

(FBD) Avoid assignments of intermediate results within networks

L3

(FBD) Define maximum complexity of single network

L4

(LD) A coil should not be followed by a contact

L5

(LD) Define maximum rung complexity

L6

(SFC) Closing divergent paths

L7

(SFC) Do not program an SFC action block in SFC

L8

(SFC) Define maximum complexity

L9

(ST) Define general formatting rules

L10

(ST) Usage of CONTINUE and EXIT instruction should be avoided

L11

(ST) Define the maximum line length

L12

SA0072

(ST) Loop variables should not be modified inside a FOR loop

L13

SA0073

(ST) FOR loop variable usage should not be used outside the FOR loop

L14

(ST) Passing parameters should be clear

L15

(ST) Use parenthesis to explicitly express operation precedence

L16

(ST) Define the use of tabs

Library developer employed by 3S don't use tabs

L17

SA0075

(ST) Each IF instruction should have an ELSE clause

E1

Dynamic memory allocation shall not be used

E2

SA0061

Pointer arithmetic shall not be used

E3

SA0061

Some comparator instructions shall not be used for pointers or reference manipulation