22 #define COLOUR_UNKNOWN eColourMagenta
23 #define COLOUR_SORRY eColourMagenta
24 #define COLOUR_INTERNAL eColourCyan
25 #define COLOUR_FATAL eColourRed
26 #define COLOUR_WARN eColourYellow
27 #define COLOUR_INFO eColourGreen
28 #define COLOUR_DEBUG eColourGreen
33 if (override_fatal && severity == eSeverityWarn)
return eSeverityFatal;
42 case eSeveritySorry:
return "sorry";
43 case eSeverityInternal:
return "internal";
44 case eSeverityFatal:
return "error";
45 case eSeverityWarn:
return "warning";
46 case eSeverityInfo:
return "info";
47 case eSeverityDebug:
return "debug";
48 default:
return "unknown";
67 static int segment_cmp(
const void *lhs,
const void *rhs)
75 CTASSERTF(scan_lhs == scan_rhs,
"segments must be in the same scan (%s and %s)",
105 for (
size_t i = 0; i < len; i++)
111 if (other != scan)
continue;
163 const char *start = text->
source.text;
169 const char *next = (i == SIZE_MAX) ? end : start + i;
173 .length = next - start,
178 offset += info.
length + 1;
186 cache->
arena = arena;
202 const void *memory =
io_map(io, eOsProtectRead);
216 text_cache_t *cache = text_cache_new(io, view, 32, arena);
218 if (
io_error(io) == 0) load_lineinfo(cache);
229 text_cache_t *cache = text_cache_new(NULL, view, 32, arena);
231 load_lineinfo(cache);
267 const char *key = NULL;
271 text_cache_delete(cache);
282 if (cache != NULL && cache_is_valid(cache))
return cache;
290 if (cache_is_valid(text))
return text;
301 if (cache != NULL && cache_is_valid(cache))
return cache;
334 static const char *
const kHexChars =
"0123456789abcdef";
336 static bool get_escaped_char(
char *buf,
char c)
348 buf[1] = kHexChars[c >> 4];
349 buf[2] = kHexChars[c & 0xf];
361 if (cached != NULL)
return *cached;
372 bool in_colour =
false;
373 size_t used = column_limit;
374 for (
size_t i = 0; i < view.
length; i++)
376 char c = view.text[i];
377 bool is_notprint = get_escaped_char(buffer, c);
378 if (is_notprint && !in_colour)
384 else if (!is_notprint && in_colour)
410 if (set == NULL)
return false;
437 size_t warning_count = 0;
438 size_t error_count = 0;
439 size_t bug_count = 0;
442 for (
size_t i = 0; i < len; i++)
455 if (warn_budget == 0)
continue;
460 if (error_budget == 0)
continue;
476 case eSeverityInternal:
497 io_printf(io,
"compilation failed during stage: %s\n", title);
505 if (warning_count > 0)
517 char *msg =
str_join(
", ", parts, arena);
520 else if (warning_count > 0)
522 io_printf(io,
"compilation succeeded with warnings during stage: %s\n", title);
STA_DECL char * colour_format(format_context_t context, colour_t idx, const char *fmt,...)
CT_NODISCARD CT_PUREFN CT_SCAN_API const char * scan_path(const scan_t *scan)
get the path of a scanner
CT_NODISCARD CT_PUREFN CT_SCAN_API text_view_t scan_source(const scan_t *scan)
get a text span of the scanners contents
CT_NODISCARD CT_PUREFN CT_SCAN_API bool scan_is_builtin(const scan_t *scan)
check if a scanner is the builtin scanner
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
CT_NODISCARD CT_PUREFN CT_BASE_API size_t ctu_strlen(const char *str)
get the length of a string not including the null terminator equivalent to strlen but with safety che...
CT_CONSTFN CT_BASE_API text_view_t text_view_make(STA_READS(length) const char *text, size_t length)
create a new non-owning text array text must be at least length bytes long
CT_PUREFN CT_BASE_API text_view_t text_view_from(const char *text)
create a new non-owning text array this is a shortcut for
STA_RET_STRING CT_PUREFN CT_FORMAT_API const char * colour_get(const colour_pallete_t *colours, colour_t idx)
get a colours string form from a pallete
STA_RET_STRING CT_PUREFN CT_FORMAT_API const char * colour_reset(const colour_pallete_t *colours)
get a reset string from a pallete
#define CT_EXIT_OK
no user errors or internal errors
#define CT_EXIT_INTERNAL
internal compiler errors have occurred
#define CT_EXIT_ERROR
the user has made an error
CT_MEMORY_API arena_t * get_global_arena(void)
get the global memory arena
CT_NODISCARD CT_STD_API map_t * map_optimal(size_t size, hash_info_t info, arena_t *arena)
create a new map with an optimal size
#define CTU_MAP_NEXT(iter, key, value)
get the next key-value pair from a map iterator
CT_NODISCARD CT_PUREFN CT_STD_API map_iter_t map_iter(const map_t *map)
create a new map iterator
CT_STD_API void map_set(map_t *map, const void *key, void *value)
set a key-value pair in a map
CT_NODISCARD CT_PUREFN CT_STD_API void * map_get(const map_t *map, const void *key)
get a value from a map
CT_NODISCARD CT_PUREFN CT_STD_API bool set_contains(const set_t *set, const void *key)
check if a set contains a key
CT_NODISCARD CT_IO_API io_t * io_file(const char *path, os_access_t mode, arena_t *arena)
create an IO object from a file
CT_NODISCARD CT_IO_API os_error_t io_error(const io_t *io)
get the last error from the io object
CT_IO_API os_error_t io_close(INOUT_NOTNULL io_t *io)
destroy an IO object
CT_NODISCARD CT_IO_API size_t io_size(io_t *io)
get the total size of an io objects contents
CT_IO_API size_t io_printf(io_t *io, STA_FORMAT_STRING const char *fmt,...)
printf to an io object
CT_NODISCARD CT_IO_API const char * io_name(const io_t *io)
get the name of an io object
CT_NODISCARD CT_IO_API void * io_map(io_t *io, os_protect_t protect)
map an io object into memory maps an io objects entire contents into memory.
CT_NODISCARD CT_PUREFN CT_SCAN_API const scan_t * node_get_scan(const node_t *node)
get the associated source file of a node
CT_NODISCARD CT_PUREFN CT_SCAN_API bool node_is_builtin(const node_t *node)
check if a node is the builtin node
CT_NODISCARD CT_PUREFN CT_SCAN_API where_t node_get_location(const node_t *node)
get the location of a node inside its source file
#define ARENA_MALLOC(size, name, parent, arena)
allocate memory from a custom allocator
CT_ARENA_API void arena_free(STA_RELEASE void *ptr, size_t size, arena_t *arena)
release memory from a custom allocator
severity_t
the default severity of a diagnostic
#define CTASSERT(expr)
assert a condition, prints the condition as a message
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
CT_PUREFN CT_STD_API size_t str_find(const char *str, const char *sub)
find the first instance of a substring in a string
CT_NODISCARD CT_STD_API char * str_join(const char *sep, const vector_t *parts, arena_t *arena)
join strings
CT_NODISCARD STA_FORMAT_STRING const char * fmt
CT_STD_API const hash_info_t kTypeInfoString
type information for a c style string
CT_STD_API void typevec_sort(typevec_t *vec, int(*cmp)(const void *, const void *))
sort a vector
CT_STD_API void * typevec_push(typevec_t *vec, const void *src)
push a value onto the vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t typevec_len(const typevec_t *vec)
get the length of a vector
CT_NODISCARD CT_PUREFN CT_STD_API void * typevec_data(const typevec_t *vec)
get a pointer to the underlying data
CT_STD_API void typevec_append(typevec_t *vec, const void *src, size_t len)
append multiple values onto the vector
CT_NODISCARD CT_STD_API typevec_t * typevec_new(size_t width, size_t len, arena_t *arena)
create a new typed vector on the heap
CT_NODISCARD CT_PUREFN CT_STD_API void * typevec_offset(const typevec_t *vec, size_t index)
get a pointer to the value at the given index
CT_NODISCARD CT_STD_API vector_t * vector_new(size_t size, arena_t *arena)
create a new vector with an initial capacity
CT_STD_API void vector_push(vector_t **vector, void *value)
push a value onto the end of a vector
severity_t severity
the severity of the diagnostic
an event handle TODO: make this and segment_t opaque
the configuration for a file
bool override_fatal
if true all warnings are treated as fatal
bool zeroth_line
the zeroth line of a file is the first line
a formatting context when using colours
a position in a source file
text_config_t text_config
text_format_t report_format
a segment inside an event
node_t node
the related node
const colour_pallete_t * colours
cache_map_t * cache
a shared cache between all reports, set to NULL to disable caching
size_t length
the number of characters in the text
a non-owning view of text
size_t length
the number of characters in the text
A vector with a fixed type size.
a generic vector of pointers
a location inside a scanner locations are inclusive and 0-based
ctu_column_t first_column
the first column of the location
ctu_line_t first_line
the first line of the location