@@ -26,23 +26,23 @@ Whitespaces:
26
26
- No whitespaces in blank lines
27
27
- Put argument lists on next line (and ident 2 spaces) if too long
28
28
- Put parameters on separate lines (and ident 2 spaces) if too long
29
- - No whitespaces around colon for inheritance,
29
+ - No whitespaces around colon for inheritance,
30
30
put inherited into separate lines in case of multiple inheritance
31
31
- The initializer list follows the constructor without a whitespace
32
32
around the colon. Break line after the colon if required and indent members.
33
33
- if(...), else, for(...), do, and while(...) are always in a separate line
34
- - Break expressions in if, for, while if necessary and align them
34
+ - Break expressions in if, for, while if necessary and align them
35
35
with the first character following the opening parenthesis
36
36
- Use {} instead of ; for the empty statement
37
- - Single line blocks without { } are allowed,
37
+ - Single line blocks without { } are allowed,
38
38
but put braces around multi-line blocks
39
- - Use blank lines to visually separate logically cohesive code blocks
39
+ - Use blank lines to visually separate logically cohesive code blocks
40
40
within a function
41
41
- Have a newline at the end of a file
42
42
43
43
Comments:
44
44
- Do not use /* */ except for file and function comment blocks
45
- - Each source and header file must start with a comment block
45
+ - Each source and header file must start with a comment block
46
46
stating the Module name and Author [will be changed when we roll out doxygen]
47
47
- Each function in the source file (not the header) is preceded
48
48
by a function comment header consisting of a comment block stating
@@ -75,9 +75,9 @@ Comments:
75
75
- Use #ifdef DEBUG to guard debug code
76
76
77
77
Naming:
78
- - Identifiers may use the characters [a-z0-9_] and should start with a
78
+ - Identifiers may use the characters [a-z0-9_] and should start with a
79
79
lower-case letter (parameters in constructors may start with _).
80
- - Use american spelling for identifiers.
80
+ - Use american spelling for identifiers.
81
81
- Separate basic words by _
82
82
- Avoid abbreviations (e.g. prefer symbol_table to of st).
83
83
- User defined type identifiers have to be terminated by 't'. Moreover,
@@ -92,6 +92,35 @@ Header files:
92
92
of the header file rather than in line
93
93
- Guard headers with #ifndef CPROVER_DIRECTORIES_FILE_H, etc
94
94
95
+ Make files
96
+ - Each source file should appear on a separate line
97
+ - The final source file should still be followed by a trailing slash
98
+ - The last line should be a comment to not be deleted, i.e. should look like:
99
+ ```
100
+ SRC = source_file.cpp \
101
+ source_file2.cpp \
102
+ # Empty last line
103
+ ```
104
+ - This ensures the Makefiles can be easily merged.
105
+
106
+ Program Command Line Options
107
+ - Each program contains a program_name_parse_optionst class which should
108
+ contain a define PROGRAM_NAME_PARSE_OPTIONS which is a string of all the
109
+ parse options in brackets (with a colon after the bracket if it takes a
110
+ parameter)
111
+ - Each parameter should be one per line to yield easy merging
112
+ - If parameters are shared between programs, they should be pulled out into
113
+ a common file and then included using a define
114
+ - The defines should be OPT_FLAG_NAMES which should go into the OPTIONS define
115
+ - The defines should include HELP_FLAG_NAMES which should contain the help
116
+ output of the format:
117
+ ```
118
+ " --flag explanations\n" \
119
+ " --another flag more explanation\n" \
120
+ <-------30 chars------>
121
+ - The defines may include PARSE_OPTIONS_FLAG_NAMES which move the options
122
+ from the command line into the options
123
+
95
124
C++ features:
96
125
- Do not use namespaces.
97
126
- Prefer use of 'typedef' insted of 'using'.
@@ -107,7 +136,7 @@ C++ features:
107
136
- Avoid iterators, use ranged for instead
108
137
- Avoid allocation with new/delete, use unique_ptr
109
138
- Avoid pointers, use references
110
- - Avoid char *, use std::string
139
+ - Avoid char *, use std::string
111
140
- For numbers, use int, unsigned, long, unsigned long, double
112
141
- Use mp_integer, not BigInt
113
142
- Use the functions in util for conversions between numbers and strings
@@ -117,13 +146,13 @@ C++ features:
117
146
- Use instances of std::size_t for comparison with return values of .size() of
118
147
STL containers and algorithms, and use them as indices to arrays or vectors.
119
148
- Do not use default values in public functions
120
- - Use assertions to detect programming errors, e.g. whenever you make
149
+ - Use assertions to detect programming errors, e.g. whenever you make
121
150
assumptions on how your code is used
122
- - Use exceptions only when the execution of the program has to abort
151
+ - Use exceptions only when the execution of the program has to abort
123
152
because of erroneous user input
124
- - We allow to use 3rd-party libraries directly.
125
- No wrapper matching the coding rules is required.
126
- Allowed libraries are: STL.
153
+ - We allow to use 3rd-party libraries directly.
154
+ No wrapper matching the coding rules is required.
155
+ Allowed libraries are: STL.
127
156
- When throwing, omit the brackets, i.e. `throw "error"`.
128
157
- Error messages should start with a lower case letter.
129
158
- Use the auto keyword if and only if one of the following
@@ -136,10 +165,38 @@ Architecture-specific code:
136
165
- Don't include architecture-specific header files without #ifdef ...
137
166
138
167
Output:
139
- - Do not output to cout or cerr directly (except in temporary debug code,
168
+ - Do not output to cout or cerr directly (except in temporary debug code,
140
169
and then guard #include <iostream> by #ifdef DEBUG)
141
170
- Derive from messaget if the class produces output and use the streams provided
142
171
(status(), error(), debug(), etc)
143
172
- Use '\n' instead of std::endl
144
173
174
+ Unit tests:
175
+ - Unit tests are written using Catch: https://github.com/philsquared/Catch/
176
+ - For large classes:
177
+ - Create a separate file that contains the tests for each method of each
178
+ class
179
+ - The file should be named according to
180
+ `unit/class/path/class_name/function_name.cpp`
181
+ - For small classes:
182
+ - Create a separate file that contains the tests for all methods of each
183
+ class
184
+ - The file should be named according to unit/class/path/class_name.cpp
185
+ - Catch supports tagging, tests should be tagged with all the following tags:
186
+ - [core] should be used for all tests unless the test takes more than 1
187
+ second to run, then it should be tagged with [long]
188
+ - [folder_name] of the file being tested
189
+ - [class_name] of the class being tested
190
+ - [function_name] of the function being tested
191
+
145
192
You are allowed to break rules if you have a good reason to do so.
193
+
194
+ Pre-commit hook to run cpplint locally
195
+ --------------------------------------
196
+ To install the hook
197
+ cp .githooks/pre-commit .git/hooks/pre-commit
198
+ or use a symbolic link.
199
+ Then, when running git commit, you should get the linter output
200
+ (if any) before being prompted to enter a commit message.
201
+ To bypass the check (e.g. if there was a false positive),
202
+ add the option --no-verify.
0 commit comments