Debian Codegraph @

src/doc/manual/developer-guide/contributing-code-standards.txi

raw
1 @node Coding standards
2 @subsection Coding standards
3
4 @cindex Coding conventions
5
6 @subsubheading Lisp conventions
7 Lisp code should follow the standard conventions used in the
8 community.
9
10 If the function is local to the file it's used in, then it should be
11 declared as c-local:
12
13 @exindex Lisp convention: local functions
14 @lisp
15 (defun command-arg-error (str &rest fmt-args)
16 ;; Format an error message and quit
17 (declare (si::c-local))
18 (apply #'format *error-output* str fmt-args)
19 (princ *help-message* *error-output*)
20 (quit 1))
21 @end lisp
22
23 @subsubheading C/C++ conventions
24
25 ECL internal C files are preprocessed with the [@ref{Defun
26 preprocessor}]. This results in the ability to use somewhat unusual
27 syntax in the C source files like @verb{|defun|} with the
28 @verb{|&optional|}, @verb{|&rest|}, @verb{|&key|} and @verb{|&aux|}
29 arguments as well as returning multiple values from the function using
30 @verb{|@(return)|}..
31
32 Style used in C/C++ files is 2 space indent, no tabs, similar to
33 @url{https://gcc.gnu.org/codingconventions.html}. Programmer may depend
34 on emacs default indentation (C-. gnu). Lines should be wrapped to 78
35 lines.
36
37 Important note: @verb{|@(return foo bar)|} is expanded to the code
38 block, so if put inside the if statement it should be enclosed in
39 braces:
40
41 @exindex C/C++ convention: sample function
42 @verbatim
43 static cl_object
44 file_truename(cl_object pathname, cl_object filename, int flags)
45 {
46 cl_object kind;
47 if (Null(pathname)) {
48 if (Null(filename)) {
49 ecl_internal_error("file_truename:"
50 " both FILENAME and PATHNAME are null!");
51 }
52 pathname = cl_pathname(filename);
53 } else if (Null(filename)) {
54 filename = ecl_namestring(pathname, ECL_NAMESTRING_FORCE_BASE_STRING);
55 if (Null(filename)) {
56 FEerror("Unprintable pathname ~S found in TRUENAME", 1, pathname);
57 }
58 }
59 kind = file_kind((char*)filename->base_string.self, FALSE);
60 if (kind == ECL_NIL) {
61 FEcannot_open(filename);
62 #ifdef HAVE_LSTAT
63 } else if (kind == @':link' && (flags & FOLLOW_SYMLINKS)) {
64 /* The link might be a relative pathname. In that case
65 * we have to merge with the original pathname. On
66 * the other hand, if the link is broken – return file
67 * truename "as is". */
68 struct stat filestatus;
69 if (safe_stat(filename->base_string.self, &filestatus) < 0) {
70 @(return pathname kind);
71 }
72 filename = si_readlink(filename);
73 pathname = ecl_make_pathname(pathname->pathname.host,
74 pathname->pathname.device,
75 pathname->pathname.directory,
76 ECL_NIL, ECL_NIL, ECL_NIL, @':local');
77 pathname = ecl_merge_pathnames(filename, pathname, @':default');
78 return cl_truename(pathname);
79 #endif
80 } else if (kind == @':directory'){
81 /* If the pathname is a directory but we have supplied
82 a file name, correct the type by appending a directory
83 separator and re-parsing again the namestring */
84 if (pathname->pathname.name != ECL_NIL ||
85 pathname->pathname.type != ECL_NIL) {
86 pathname = si_base_string_concatenate
87 (2, filename,
88 make_constant_base_string("/"));
89 pathname = cl_truename(pathname);
90 }
91 }
92 /* ECL does not contemplate version numbers
93 in directory pathnames */
94 if (pathname->pathname.name == ECL_NIL &&
95 pathname->pathname.type == ECL_NIL) {
96 /* We have to destructively change the
97 * pathname version here. Otherwise
98 * merge_pathnames will not do it. It is
99 * safe because coerce_to_file_pathname
100 * created a copy. */
101 pathname->pathname.version = ECL_NIL;
102 } else {
103 pathname->pathname.version = @':newest';
104 }
105 @(return pathname kind);
106 }
107 @end verbatim