Skip to content

Commit 4157b84

Browse files
shiqinggdbkinder
authored andcommitted
doc: add some rules related to naming convention
This patch adds some rules related to naming convention. Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
1 parent 518a82d commit 4157b84

File tree

1 file changed

+155
-10
lines changed

1 file changed

+155
-10
lines changed

doc/developer-guides/coding_guidelines.rst

100755100644
Lines changed: 155 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,8 +2776,6 @@ Compliant example::
27762776
if (condition) { do_a();} else {do_b();}
27772777

27782778

2779-
2780-
27812779
CS-03: Tabs shall be used for code indentation
27822780
==============================================
27832781

@@ -2810,8 +2808,6 @@ A tab character shall be considered 8-character wide when limiting the line
28102808
width.
28112809

28122810

2813-
2814-
28152811
CS-05: Trailing whitespace shall not be allowed at the end of lines
28162812
===================================================================
28172813

@@ -2984,8 +2980,6 @@ Compliant example::
29842980
}
29852981

29862982

2987-
2988-
29892983
CS-13: Braces after if/switch/for/do/while shall be in the same line
29902984
====================================================================
29912985

@@ -3035,8 +3029,6 @@ Compliant example::
30353029
}
30363030

30373031

3038-
3039-
30403032
CS-15: A 'switch' statement and its subordinate 'case' shall be aligned
30413033
=======================================================================
30423034

@@ -3092,8 +3084,6 @@ Compliant example::
30923084
param_3);
30933085

30943086

3095-
3096-
30973087
CS-17: '//' shall not be used for single-line comments
30983088
=======================================================
30993089

@@ -3110,3 +3100,158 @@ Compliant example::
31103100
// This is a comment
31113101

31123102

3103+
Naming Convention
3104+
*****************
3105+
3106+
3107+
NC-01: Object-like MACRO shall be named with full upper case
3108+
============================================================
3109+
3110+
Compliant example::
3111+
3112+
#define MAX_CONFIG_NAME_SIZE 32U
3113+
3114+
.. rst-class:: non-compliant-code
3115+
3116+
Non-compliant example::
3117+
3118+
#define max_config_name_size 32U
3119+
3120+
3121+
NC-02: Mixed-use of lower case and upper case in function-like MACRO shall not be allowed
3122+
=========================================================================================
3123+
3124+
Function-like MACRO shall be named with either full lower case or full upper
3125+
case. Mixed-use of lower case and upper case shall not be allowed.
3126+
3127+
Compliant example::
3128+
3129+
#define max(x, y) ((x) < (y)) ? (y) : (x)
3130+
3131+
.. rst-class:: non-compliant-code
3132+
3133+
Non-compliant example::
3134+
3135+
#define Max(x, y) ((x) < (y)) ? (y) : (x)
3136+
3137+
3138+
NC-03: Data structures exposed to external components shall be named with prefix 'acrn'
3139+
=======================================================================================
3140+
3141+
The data structure types include struct, union, and enum.
3142+
This rule applies to the data structure with all the following properties:
3143+
3144+
a) The data structure is used by multiple modules;
3145+
b) The corresponding resource is exposed to external components, such as SOS or
3146+
UOS;
3147+
c) The name meaning is simplistic or common, such as vcpu or vm.
3148+
3149+
Compliant example::
3150+
3151+
struct acrn_vcpu {
3152+
...
3153+
};
3154+
3155+
.. rst-class:: non-compliant-code
3156+
3157+
Non-compliant example::
3158+
3159+
struct vcpu {
3160+
...
3161+
};
3162+
3163+
3164+
NC-04: Data structures only used by hypervisor shall be named with prefix 'hv'
3165+
==============================================================================
3166+
3167+
The data structure types include struct, union, and enum.
3168+
This rule applies to the data structure with all the following properties:
3169+
3170+
a) The data structure is used by multiple modules;
3171+
b) The corresponding resource is only used by hypervisor;
3172+
c) The name meaning is simplistic or common, such as timer.
3173+
3174+
Compliant example::
3175+
3176+
struct hv_timer {
3177+
...
3178+
};
3179+
3180+
.. rst-class:: non-compliant-code
3181+
3182+
Non-compliant example::
3183+
3184+
struct timer {
3185+
...
3186+
};
3187+
3188+
3189+
NC-05: Data structures only used by one module shall be named with the module name as prefix
3190+
============================================================================================
3191+
3192+
The data structure types include struct, union, and enum.
3193+
This rule applies to the data structure with all the following properties:
3194+
3195+
a) The data structure is only used by one module;
3196+
b) The name meaning is simplistic or common, such as context.
3197+
3198+
Compliant example::
3199+
3200+
struct instr_emul_ctxt {
3201+
...
3202+
};
3203+
3204+
.. rst-class:: non-compliant-code
3205+
3206+
Non-compliant example::
3207+
3208+
struct ctxt {
3209+
...
3210+
};
3211+
3212+
3213+
NC-06: Data structures related to hardware resource shall be named with the resource name as suffix
3214+
===================================================================================================
3215+
3216+
The data structure types include struct, union, and enum.
3217+
For example:
3218+
3219+
a) The data structure related to register shall be named with suffix 'reg';
3220+
b) The data structure related to segment selector shall be named with suffix
3221+
'sel'.
3222+
3223+
Compliant example::
3224+
3225+
struct lapic_reg {
3226+
...
3227+
};
3228+
3229+
.. rst-class:: non-compliant-code
3230+
3231+
Non-compliant example::
3232+
3233+
struct lapic {
3234+
...
3235+
};
3236+
3237+
3238+
NC-07: Function pointer shall be named with suffix 'fn'
3239+
=======================================================
3240+
3241+
Compliant example::
3242+
3243+
struct firmware_operations firmware_sbl_ops = {
3244+
.init = sbl_init_fn,
3245+
.get_rsdp = sbl_get_rsdp_fn,
3246+
};
3247+
3248+
.. rst-class:: non-compliant-code
3249+
3250+
Non-compliant example::
3251+
3252+
struct firmware_operations firmware_sbl_ops = {
3253+
.init = sbl_init,
3254+
.get_rsdp = sbl_get_rsdp,
3255+
};
3256+
3257+

0 commit comments

Comments
 (0)