| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef COMPILER_H | ||
| 2 | #define COMPILER_H | ||
| 3 | |||
| 4 | #include <regex.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <sys/types.h> | ||
| 8 | #include "util/hashmap.h" | ||
| 9 | #include "util/macros.h" | ||
| 10 | #include "util/ptr-array.h" | ||
| 11 | #include "util/string.h" | ||
| 12 | |||
| 13 | enum { | ||
| 14 | ERRORFMT_CAPTURE_MAX = 16 | ||
| 15 | }; | ||
| 16 | |||
| 17 | enum { | ||
| 18 | ERRFMT_FILE, | ||
| 19 | ERRFMT_LINE, | ||
| 20 | ERRFMT_COLUMN, | ||
| 21 | ERRFMT_MESSAGE, | ||
| 22 | NR_ERRFMT_INDICES | ||
| 23 | }; | ||
| 24 | |||
| 25 | typedef struct { | ||
| 26 | int8_t capture_index[NR_ERRFMT_INDICES]; | ||
| 27 | bool ignore; | ||
| 28 | const char *pattern; // Original pattern string (interned) | ||
| 29 | regex_t re; // Compiled pattern | ||
| 30 | } ErrorFormat; | ||
| 31 | |||
| 32 | typedef struct { | ||
| 33 | PointerArray error_formats; | ||
| 34 | } Compiler; | ||
| 35 | |||
| 36 | 253 | static inline Compiler *find_compiler(const HashMap *compilers, const char *name) | |
| 37 | { | ||
| 38 | 253 | return hashmap_get(compilers, name); | |
| 39 | } | ||
| 40 | |||
| 41 | void remove_compiler(HashMap *compilers, const char *name) NONNULL_ARGS; | ||
| 42 | void free_compiler(Compiler *c) NONNULL_ARGS; | ||
| 43 | void free_error_format(ErrorFormat *f) NONNULL_ARGS; | ||
| 44 | ssize_t errorfmt_capture_name_to_index(const char *name) NONNULL_ARGS WARN_UNUSED_RESULT; | ||
| 45 | void collect_errorfmt_capture_names(PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
| 46 | void dump_compiler(const Compiler *c, const char *name, String *s) NONNULL_ARGS; | ||
| 47 | |||
| 48 | NONNULL_ARGS | ||
| 49 | void add_error_fmt ( | ||
| 50 | HashMap *compilers, | ||
| 51 | const char *name, | ||
| 52 | const char *pattern, | ||
| 53 | regex_t *re, // Takes ownership | ||
| 54 | int8_t idx[static NR_ERRFMT_INDICES], | ||
| 55 | bool ignore | ||
| 56 | ); | ||
| 57 | |||
| 58 | #endif | ||
| 59 |