Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static code analysis - naming conventions #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<DUT Name="DUT_EPS" Id="{0134451e-57c2-478a-9365-5d6570cca7b2}">
<Declaration><![CDATA[TYPE DUT_EPS :
<DUT Name="ST_EPS" Id="{0134451e-57c2-478a-9365-5d6570cca7b2}">
<Declaration><![CDATA[TYPE ST_EPS :
Comment on lines -3 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge this, I might want to go back through and implement backwards compatibility where possible. We should be able to make a DUT_EPS alias for ST_EPS to ease the transition.

STRUCT
// Contains EPS flags
{attribute 'pytmc' := '
Expand Down
10 changes: 5 additions & 5 deletions LCLSGeneral/LCLSGeneral/Data types/Misc/ST_System.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
TYPE ST_System :
STRUCT

xSwAlmRst : BOOL;(* Global Alarm Reset - EPICS Command *)
xAtVacuum : BOOL;(* System At Vacuum *)
xFirstScan : BOOL; (* This boolean is true for the first scan, and is false thereafter, use for initialization of stuff *)
xOverrideMode : BOOL; //This bit is set when using the override features of the system
xIOState : BOOL; (* ECat Bus Health *)
bSwAlmRst : BOOL;(* Global Alarm Reset - EPICS Command *)
bAtVacuum : BOOL;(* System At Vacuum *)
bFirstScan : BOOL; (* This boolean is true for the first scan, and is false thereafter, use for initialization of stuff *)
bOverrideMode : BOOL; //This bit is set when using the override features of the system
bIOState : BOOL; (* ECat Bus Health *)

END_STRUCT
END_TYPE]]></Declaration>
Expand Down
5 changes: 2 additions & 3 deletions LCLSGeneral/LCLSGeneral/GVLs/GeneralConstants.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ VAR_GLOBAL CONSTANT
// This is the max number of user-defined states (OUT, TARGET1, YAG...)
// You can make this smaller if you want to use less memory in your program in exchange for limiting your max state count
// You can make this larger if you want to use states-based FBs sized beyond the EPICS enum limit
MAX_STATES: UINT := 15;
END_VAR
]]></Declaration>
cnMaxStates: UINT := 15;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see a lot of places in here where other coding styles have bled into the library: some languages recommend ALL_CAPS for constants.

END_VAR]]></Declaration>
</GVL>
</TcPlcObject>
7 changes: 3 additions & 4 deletions LCLSGeneral/LCLSGeneral/GVLs/Global_Variables_EtherCAT.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<GVL Name="Global_Variables_EtherCAT" Id="{d76f2eaf-f0c3-42c2-8317-22c7ba689cf7}">
<Declaration><![CDATA[{attribute 'analysis' := '-33'}
VAR_GLOBAL CONSTANT
iSLAVEADDR_ARR_SIZE : UINT := 256;
ESC_MAX_PORTS : UINT := 3; // Maximum number of ports (4) on ESC
END_VAR
]]></Declaration>
cnSlaveAddrArrSize : UINT := 256;
cnEscMaxPorts : UINT := 3; // Maximum number of ports (4) on ESC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like declaring that something is a constant via the name has more value than declaring the types, that's a useful reminder for how the variable is used and that you cannot change it.

I'm surprised that global variables don't have a prefix assigned, I'd assume that knowing at a glance that a variable is a global and not a local could be useful when it comes to understanding the program flow, especially if the GVL file doesn't have the qualified_only pragma.

After some thought, maybe the correct convention to set is to always use the qualified_only pragma, rather than enforce some sort of globals prefix.

END_VAR]]></Declaration>
</GVL>
</TcPlcObject>
Loading