@@ -26,23 +26,23 @@ Whitespaces:
2626- No whitespaces in blank lines
2727- Put argument lists on next line (and ident 2 spaces) if too long
2828- 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,
3030 put inherited into separate lines in case of multiple inheritance
3131- The initializer list follows the constructor without a whitespace
3232 around the colon. Break line after the colon if required and indent members.
3333- 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
3535 with the first character following the opening parenthesis
3636- Use {} instead of ; for the empty statement
37- - Single line blocks without { } are allowed,
37+ - Single line blocks without { } are allowed,
3838 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
4040 within a function
4141- Have a newline at the end of a file
4242
4343Comments:
4444- 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
4646 stating the Module name and Author [will be changed when we roll out doxygen]
4747- Each function in the source file (not the header) is preceded
4848 by a function comment header consisting of a comment block stating
@@ -75,9 +75,9 @@ Comments:
7575- Use #ifdef DEBUG to guard debug code
7676
7777Naming:
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
7979 lower-case letter (parameters in constructors may start with _).
80- - Use american spelling for identifiers.
80+ - Use american spelling for identifiers.
8181- Separate basic words by _
8282- Avoid abbreviations (e.g. prefer symbol_table to of st).
8383- User defined type identifiers have to be terminated by 't'. Moreover,
@@ -92,6 +92,35 @@ Header files:
9292 of the header file rather than in line
9393- Guard headers with #ifndef CPROVER_DIRECTORIES_FILE_H, etc
9494
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+
95124C++ features:
96125- Do not use namespaces.
97126- Prefer use of 'typedef' insted of 'using'.
@@ -107,7 +136,7 @@ C++ features:
107136- Avoid iterators, use ranged for instead
108137- Avoid allocation with new/delete, use unique_ptr
109138- Avoid pointers, use references
110- - Avoid char *, use std::string
139+ - Avoid char *, use std::string
111140- For numbers, use int, unsigned, long, unsigned long, double
112141- Use mp_integer, not BigInt
113142- Use the functions in util for conversions between numbers and strings
@@ -117,13 +146,13 @@ C++ features:
117146- Use instances of std::size_t for comparison with return values of .size() of
118147 STL containers and algorithms, and use them as indices to arrays or vectors.
119148- 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
121150 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
123152 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.
127156- When throwing, omit the brackets, i.e. `throw "error"`.
128157- Error messages should start with a lower case letter.
129158- Use the auto keyword if and only if one of the following
@@ -136,10 +165,38 @@ Architecture-specific code:
136165- Don't include architecture-specific header files without #ifdef ...
137166
138167Output:
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,
140169 and then guard #include <iostream> by #ifdef DEBUG)
141170- Derive from messaget if the class produces output and use the streams provided
142171 (status(), error(), debug(), etc)
143172- Use '\n' instead of std::endl
144173
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+
145192You 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