ccanlint.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. struct manifest {
  7. char *basename;
  8. struct ccan_file *info_file;
  9. struct list_head c_files;
  10. struct list_head h_files;
  11. struct list_head run_tests;
  12. struct list_head api_tests;
  13. struct list_head compile_ok_tests;
  14. struct list_head compile_fail_tests;
  15. struct list_head other_test_files;
  16. struct list_head other_files;
  17. };
  18. struct manifest *get_manifest(void);
  19. struct ccanlint {
  20. struct list_node list;
  21. /* Unique name of test */
  22. const char *name;
  23. /* Total score that this test is worth. 0 means compulsory tests. */
  24. unsigned int total_score;
  25. /* If this returns non-NULL, it means the check failed. */
  26. void *(*check)(struct manifest *m);
  27. /* The non-NULL return from check is passed to one of these: */
  28. /* So, what did this get out of the total_score? (NULL means 0). */
  29. unsigned int (*score)(struct manifest *m, void *check_result);
  30. /* Verbose description of what was wrong. */
  31. const char *(*describe)(struct manifest *m, void *check_result);
  32. /* Can we do something about it? (NULL if not) */
  33. void (*handle)(struct manifest *m, void *check_result);
  34. };
  35. /* Ask the user a yes/no question: the answer is NO if there's an error. */
  36. bool ask(const char *question);
  37. enum line_info_type {
  38. PREPROC_LINE, /* Line starts with # */
  39. CODE_LINE, /* Code (ie. not pure comment). */
  40. DOC_LINE, /* Line with kernel-doc-style comment. */
  41. COMMENT_LINE, /* (pure) comment line */
  42. };
  43. /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
  44. * and #if <SYMBOL>/#if !<SYMBOL> */
  45. struct pp_conditions {
  46. /* We're inside another ifdef? */
  47. struct pp_conditions *parent;
  48. enum {
  49. PP_COND_IF,
  50. PP_COND_IFDEF,
  51. PP_COND_UNKNOWN,
  52. } type;
  53. bool inverse;
  54. const char *symbol;
  55. };
  56. /* Preprocessor information about each line. */
  57. struct line_info {
  58. enum line_info_type type;
  59. /* Is this actually a continuation of line above? (which ends in \) */
  60. bool continued;
  61. /* Conditions for this line to be compiled. */
  62. struct pp_conditions *cond;
  63. };
  64. struct ccan_file {
  65. struct list_node list;
  66. char *name;
  67. /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
  68. unsigned int num_lines;
  69. char **lines;
  70. struct line_info *line_info;
  71. struct list_head *doc_sections;
  72. };
  73. /* Use this rather than accessing f->lines directly: loads on demand. */
  74. char **get_ccan_file_lines(struct ccan_file *f);
  75. /* Use this rather than accessing f->lines directly: loads on demand. */
  76. struct line_info *get_ccan_line_info(struct ccan_file *f);
  77. enum line_compiled {
  78. NOT_COMPILED,
  79. COMPILED,
  80. MAYBE_COMPILED,
  81. };
  82. /* Simple evaluator. If symbols are set this way, is this condition true?
  83. * NULL values mean undefined, NULL symbol terminates. */
  84. enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
  85. const char *symbol,
  86. const unsigned int *value, ...);
  87. /* Get token if it's equal to token. */
  88. bool get_token(const char **line, const char *token);
  89. /* Talloc copy of symbol token, or NULL. Increment line. */
  90. char *get_symbol_token(void *ctx, const char **line);
  91. /* Similarly for ->doc_sections */
  92. struct list_head *get_ccan_file_docs(struct ccan_file *f);
  93. /* Call the reporting on every line in the file. sofar contains
  94. * previous results. */
  95. char *report_on_lines(struct list_head *files,
  96. char *(*report)(const char *),
  97. char *sofar);
  98. /* The critical tests which mean fail if they don't pass. */
  99. extern struct ccanlint no_info;
  100. extern struct ccanlint has_main_header;
  101. /* Normal tests. */
  102. extern struct ccanlint trailing_whitespace;
  103. #endif /* CCAN_LINT_H */