]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/ccanlint.h
tools: fix warnings from Ubuntu strict compiler.
[ccan] / tools / ccanlint / ccanlint.h
1 #ifndef CCAN_LINT_H
2 #define CCAN_LINT_H
3 #include <ccan/list/list.h>
4 #include <stdbool.h>
5 #include "../doc_extract.h"
6
7 #define REGISTER_TEST(name, ...) extern struct ccanlint name
8 #include "generated-compulsory-tests"
9 #include "generated-normal-tests"
10 #undef REGISTER_TEST
11
12 #define REGISTER_TEST(name, ...) 
13
14 struct manifest {
15         char *dir;
16         /* The module name, ie. final element of dir name */
17         char *basename;
18         struct ccan_file *info_file;
19
20         struct list_head c_files;
21         struct list_head h_files;
22
23         struct list_head run_tests;
24         struct list_head api_tests;
25         struct list_head compile_ok_tests;
26         struct list_head compile_fail_tests;
27         struct list_head other_test_c_files;
28         struct list_head other_test_files;
29
30         struct list_head other_files;
31
32         /* From tests/check_depends_exist.c */
33         struct list_head dep_dirs;
34         /* From tests/check_depends_built.c */
35         struct list_head dep_objs;
36 };
37
38 struct manifest *get_manifest(const void *ctx, const char *dir);
39
40 struct ccanlint {
41         struct list_node list;
42
43         /* Unique name of test */
44         const char *name;
45
46         /* Total score that this test is worth. */
47         unsigned int total_score;
48
49         /* Can we run this test?  Return string explaining why, if not. */
50         const char *(*can_run)(struct manifest *m);
51
52         /* If this returns non-NULL, it means the check failed. */
53         void *(*check)(struct manifest *m);
54
55         /* The non-NULL return from check is passed to one of these: */
56
57         /* So, what did this get out of the total_score?  (NULL means 0). */
58         unsigned int (*score)(struct manifest *m, void *check_result);
59
60         /* Verbose description of what was wrong. */
61         const char *(*describe)(struct manifest *m, void *check_result);
62
63         /* Can we do something about it? (NULL if not) */
64         void (*handle)(struct manifest *m, void *check_result);
65
66         /* Internal use fields: */
67         /* Who depends on us? */
68         struct list_head dependencies;
69         /* How many things do we (still) depend on? */
70         unsigned int num_depends;
71         /* Did we skip a dependency?  If so, must skip this, too. */
72         bool skip;
73         /* Did we fail a dependency?  If so, skip and mark as fail. */
74         bool skip_fail;
75 };
76
77 /* Ask the user a yes/no question: the answer is NO if there's an error. */
78 bool ask(const char *question);
79
80 enum line_info_type {
81         PREPROC_LINE, /* Line starts with # */
82         CODE_LINE, /* Code (ie. not pure comment). */
83         DOC_LINE, /* Line with kernel-doc-style comment. */
84         COMMENT_LINE, /* (pure) comment line */
85 };
86
87 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
88  * and #if <SYMBOL>/#if !<SYMBOL> */
89 struct pp_conditions {
90         /* We're inside another ifdef? */
91         struct pp_conditions *parent;
92
93         enum {
94                 PP_COND_IF,
95                 PP_COND_IFDEF,
96                 PP_COND_UNKNOWN,
97         } type;
98
99         bool inverse;
100         const char *symbol;
101 };
102
103 /* Preprocessor information about each line. */
104 struct line_info {
105         enum line_info_type type;
106
107         /* Is this actually a continuation of line above? (which ends in \) */
108         bool continued;
109
110         /* Conditions for this line to be compiled. */
111         struct pp_conditions *cond;
112 };
113
114 struct ccan_file {
115         struct list_node list;
116
117         /* Name (usually, within m->dir). */
118         char *name;
119
120         /* Full path name. */
121         char *fullname;
122
123         /* Pristine version of the original file.
124          * Use get_ccan_file_lines to fill this. */
125         const char *contents;
126         size_t contents_size;
127
128         /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
129         unsigned int num_lines;
130         char **lines;
131         struct line_info *line_info;
132
133         struct list_head *doc_sections;
134
135         /* If this file gets compiled (eg. .C file to .o file), result here. */
136         char *compiled;
137 };
138
139 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
140 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
141
142 /* Use this rather than accessing f->lines directly: loads on demand. */
143 char **get_ccan_file_lines(struct ccan_file *f);
144
145 /* Use this rather than accessing f->lines directly: loads on demand. */
146 struct line_info *get_ccan_line_info(struct ccan_file *f);
147
148 enum line_compiled {
149         NOT_COMPILED,
150         COMPILED,
151         MAYBE_COMPILED,
152 };
153
154 /* Simple evaluator.  If symbols are set this way, is this condition true?
155  * NULL values mean undefined, NULL symbol terminates. */
156 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
157                                     const char *symbol,
158                                     const unsigned int *value, ...);
159
160 /* Get token if it's equal to token. */
161 bool get_token(const char **line, const char *token);
162 /* Talloc copy of symbol token, or NULL.  Increment line. */
163 char *get_symbol_token(void *ctx, const char **line);
164
165 /* Similarly for ->doc_sections */
166 struct list_head *get_ccan_file_docs(struct ccan_file *f);
167
168
169 /* Call the reporting on every line in the file.  sofar contains
170  * previous results. */
171 char *report_on_lines(struct list_head *files,
172                       char *(*report)(const char *),
173                       char *sofar);
174
175 /* Normal tests. */
176 extern struct ccanlint trailing_whitespace;
177
178 /* Dependencies */
179 struct dependent {
180         struct list_node node;
181         struct ccanlint *dependent;
182 };
183
184 /* Are we happy to compile stuff, or just non-intrusive tests? */
185 extern bool safe_mode;
186
187 /* Where is the ccan dir?  Available after first manifest. */
188 extern const char *ccan_dir;
189
190 #endif /* CCAN_LINT_H */