Naming conventions (2)
The Naming Conventions (2) tab contains options that extend the settings of the Naming conventions tab. You can use these options to configure how the expected overall prefix for variables/declarations is to be composed.
The observance of the naming conventions is checked during the execution of the Static Analysis.
1) First character after prefix should be an upper case letter
- If enabled: The static code analysis reports an error for a variable if the first character of the variable name after the defined prefix is not an upper case letter.
- If disabled: Upper case/lower case spelling is not checked.
- Default setting: disabled
Examples:
- Variable "bvar" with the expected prefix "b"
- Function block "FB_sample" with the expected prefix "FB_"
Option | State | Result of the static analysis |
---|---|---|
First character after prefix should be an upper case letter | Enabled | For the definitions mentioned above, an error will be reported in each case that the first letter after the prefix must be an upper case letter. Correct identifiers would be "bVar" and "FB_Sample". |
Disabled | The identifiers "bvar" and "FB_sample" are permissible. No upper/lower case error is output. |
2) Recursive prefixes for combinable data types
- If enabled: Variables of combinable data types (POINTER, REFRENCE, ARRAY, SUBRANGE) must have a composite data type prefix. The composite prefix is formed from the individual prefixes configured for the individual components of the combined data type.
- If disabled: Only the prefix of the outermost data type is expected as the date type prefix.
- Default setting: enabled
- Examples: see below
3) Combine scope prefix with data type prefix
(namespace = scope)
- If enabled: A variable must have the prefix for its scope defined in the naming conventions, followed by its data type prefix.
- If disabled: The expected overall prefix depends on whether or not a scope prefix is defined for a variable.
- If the associated scope prefix is defined for a variable, the variable must have only the prefix for its scope defined in the naming conventions. The data type prefix is not expected after the scope prefix.
- If the associated scope prefix is not defined for a variable, the variable must have only the data type prefix defined for it.
- Default setting: enabled
- Examples: see below
Examples
- Prefix configuration for data types:
- POINTER (26) = "p"
- ARRAY (30) = "a"
- INT (14) = "n"
- BOOL (3) = "b"
- Prefix configuration for scope
- Case 1: Function block variables (54) = "_local_"
- Case 2: Function block variables (54) = empty field/not configured
- INFO: Further examples of a scope include VAR_GLOBAL (51), VAR_INPUT (56) and VAR CONSTANT (62).
- Declaration:
FUNCTION_BLOCK FB_Sample
VAR
var1 : POINTER TO ARRAY[1..3] OF INT;
var2 : ARRAY[10..20] OF ARRAY[3..5] OF BOOL;
END_VAR
Option scenario 1:
Option | State | Expected overall prefix for case 1 (NC0054 = "_local_") | Expected overall prefix for case 2 (NC0054 = empty) |
---|---|---|---|
Recursive prefixes for combinable data types | Enabled | For var1: '_local_pan' For var2: '_local_aab' | For var1: 'pan' For var2: 'aab' |
Combine scope prefix with data type prefix | Enabled |
Explanation:
- As the option "Recursive prefixes for combinable data types" is enabled, the prefix composed of the individual prefixes is expected as the data type prefix. Consequently, the sub-prefixes "p" for POINTER, "a" for ARRAY and "n" for INT are combined to form the data type prefix "pan", or the sub-prefixes "a" for ARRAY, "a" for ARRAY again and "b" for BOOL are combined to form the data type prefix "aab".
- As the option "Combine scope prefix with data type prefix" is also enabled, the combination of scope prefix and data type prefix is expected as the overall prefix.
- Case 1: _local_ + pan = _local_pan
- Case 2: <empty> + pan = pan
Option scenario 2:
Option | State | Expected overall prefix for case 1 (NC0054 = "_local_") | Expected overall prefix for case 2 (NC0054 = empty) |
---|---|---|---|
Recursive prefixes for combinable data types | Disabled | For var1: '_local_p' For var2: '_local_a' | For var1: 'p' For var2: 'a' |
Combine scope prefix with data type prefix | Enabled |
Explanation:
- As the option "Recursive prefixes for combinable data types" is disabled, only the prefix of the outermost data type is expected as the data type prefix. The expected data type prefix is therefore "p" or "a".
- As the option "Combine scope prefix with data type prefix" is enabled, the combination of scope prefix and data type prefix is expected as the overall prefix for variables.
- Case 1: _local_ + p = _local_p
- Case 2: <empty> + p = p
Option scenario 3:
Option | State | Expected overall prefix for case 1 (NC0054 = "_local_") | Expected overall prefix for case 2 (NC0054 = empty) |
---|---|---|---|
Recursive prefixes for combinable data types | Enabled | For var1: '_local_' For var2: '_local_' | For var1: 'pan' For var2: 'aab' |
Combine scope prefix with data type prefix | Disabled |
Explanation:
- See option scenario 1: As the option "Recursive prefixes for combinable data types" is enabled, the prefix composed of the individual prefixes is expected as the data type prefix. This results in "pan" or "aab" as the data type prefix.
- As the option "Combine scope prefix with data type prefix" is disabled, the expected overall prefix depends on whether or not a scope prefix is defined for a variable.
- If scope prefix is defined (case 1): The variable must only have the scope prefix. The data type prefix is not expected after the scope prefix. This results for both variables in "_local_" as the expected overall prefix.
- If scope prefix is not defined (case 2): The variable must only have the data type prefix. This results in "pan" or "aab" as the expected overall prefix.
Option scenario 4:
Option | State | Expected overall prefix for case 1 (NC0054 = "_local_") | Expected overall prefix for case 2 (NC0054 = empty) |
---|---|---|---|
Recursive prefixes for combinable data types | Disabled | For var1: '_local_' For var2: '_local_' | For var1: 'p' For var2: 'a' |
Combine scope prefix with data type prefix | Disabled |
Explanation:
- See option scenario 2: As the option "Recursive prefixes for combinable data types" is disabled, only the prefix of the outermost data type is expected as the data type prefix. This results in "p" or "a" as the data type prefix.
- As the option "Combine scope prefix with data type prefix" is disabled, the expected overall prefix depends on whether or not a scope prefix is defined for a variable.
- If scope prefix is defined (case 1): The variable must only have the scope prefix. The data type prefix is not expected after the scope prefix. This results for both variables in "_local_" as the expected overall prefix.
- If scope prefix is not defined (case 2): The variable must only have the data type prefix. This results in "p" or "a" as the expected overall prefix.
Further notes/examples:
For POUs with an access modifier (methods or properties), the combination of the prefix for the scope (NC0121-NC0124: PRIVATE/PROTECTED/INTERNAL/PUBLIC) and the prefix for the POU type (NC0105 for method, NC0107 for property) is expected as the overall prefix. Examples:
- If the prefix "priv_" has been configured for PRIVATE (121) and the prefix "M_" for METHOD (105), the overall prefix "priv_M_" is expected for a PRIVATE method.
- If the prefix "M_" is still configured for METHOD (105), but no prefix has been configured for PRIVATE (121), that is, if the field is empty in the naming conventions, the overall prefix "M_" is expected for a PRIVATE method.