Naming conventions

In the Naming Conventions tab you can define naming conventions. Their compliance is accounted for in the Static Analysis execution. You define mandatory prefixes for the different data types of variables as well as for different scopes, function block types, and data type declarations. The names of all objects for which a convention can be specified are displayed in the project properties as a tree structure. The objects are arranged below organizational nodes.

Naming conventions 1:

Configuration of the naming conventions

Names

Nodes and elements for which a prefix can be defined

The number in brackets after each element, for example "PROGRAM (102)", is the prefix convention number that is output if the naming convention is not followed.

Prefix

You can define the naming conventions by entering the required prefix in this column.

Please note the following notes and options:

  • Several possible prefixes per line
    • Multiple prefixes can be entered separated by commas.
    • Example: "x, b" as prefixes for variables of data type BOOL. "x" and "b" may be used as prefix for Boolean variables.
  • Regular expressions
    • You can also use regular expressions (RegEx) for the prefix. In this case you have to use @ as additional prefix.
    • Example: "@b[a-dA-D]" as prefix for variables of data type BOOL. The name of the boolean variable must start with "b", and may be followed by a character in the range "a-dA-D".
  • Data type placeholder
    • For variables of the Alias data type and for properties you can use the data type placeholder "{datatype}" as prefix.
    • Example: Prefix for the variable data type Alias (33) = "{datatype}"

Prefixes for variables

Organizational node for all variables for which a prefix dependent on their data type or scope can be defined

Prefixes for POUs

Organizational node for all POU types and method validity ranges for which a prefix can be defined

Prefixes for DUTs

Organizational node for the DUT data types Structure, Enumeration, Alias or Union for which a prefix can be defined

Prefixes for user-defined types (NC0160)

Available from TC3.1 Build 4026

Organizational node for special user-defined types, especially those from libraries or for read-only types (e.g. PVOID, HRESULT)

  • You can expand the list with conventions: click the blank line below. Then enter the name of a user-defined type or select a user-defined type in the "Input Assistant" dialog.
  • You can delete a convention by selecting it and choosing the [Del] key.

Note: These conventions take priority over the prefixes defined with the {attribute 'nameprefix' := '<prefix>'} attribute.

Example:

  • In the "Name" column, enter the read-only system data type "PVOID" in an empty line below the prefixes for user-defined types. In the same line in the "Prefix" column, enter the desired prefix, e.g. "p". Variables of type PVOID are checked for this prefix when running Static Analysis.
  • More examples of user-defined types whose desired prefix you can configure at this point:
    • System data type HRESULT
    • TON function block from the Tc2_System library

 

Naming conventions 2:

Formation of the expected prefix

The prefix expected for the different declarations is formed depending on the configuration of the options found in the Naming conventions (2) dialog.

On the Naming conventions (2) page you will also find explanations on how the expected prefix is formed, as well as some samples.

Naming conventions 3:

Placeholder {datatype} with alias variables and properties

Please also note the possibilities of the placeholder {datatype}, which you can use for the prefix definition of alias variables and properties.

Naming conventions 4:

Local prefix definition for structured types

For variables of structured types, you can specify a prefix locally in the data type declaration using the 'nameprefix' attribute.

Syntax of convention violations in the message window

Each naming convention has a unique number (shown in parentheses after the convention in the naming convention configuration view). If a violation of a convention or a preset is detected during the static analysis, the number is output in the error list together with an error description based on the following syntax. The abbreviation "NC" stands for "Naming Convention".

Syntax: "NC<prefix convention number>: <convention description>"

Sample for convention number 151 (DUTs of type Structure): "NC0151: Invalid type name 'STR_Sample'. Expected prefix 'ST_'"

Temporary deactivation of naming conventions

Individual conventions can be disabled temporarily, i.e. for particular code lines. To this end you can add a pragma or an attribute in the declaration or implementation part of the code. For variables of structured types you may specify a prefix locally via an attribute in the data type declaration. For more information see: Pragmas and attributes.

 

Overview of naming conventions

For an overview of naming conventions, see Naming conventions – overview and description.