GCC Middle and Back End API Reference
libgdiagnostics.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "intl.h"
#include "diagnostic.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-format-sarif.h"
#include "diagnostic-format-text.h"
#include "logical-location.h"
#include "edit-context.h"
#include "make-unique.h"
#include "libgdiagnostics.h"
Include dependency graph for libgdiagnostics.cc:

Data Structures

class  owned_nullable_string
 
class  content_buffer
 
struct  diagnostic_file
 
struct  diagnostic_physical_location
 
struct  diagnostic_logical_location
 
class  sink
 
struct  diagnostic_text_sink
 
class  sarif_sink
 
class  impl_diagnostic_client_data_hooks
 
class  impl_client_version_info
 
struct  diagnostic_manager
 
class  impl_rich_location
 
class  impl_range_label
 
class  impl_rule
 
class  libgdiagnostics_path_event
 
class  libgdiagnostics_path_thread
 
struct  diagnostic_execution_path
 
struct  diagnostic
 

Macros

#define INCLUDE_MAP
 
#define INCLUDE_VECTOR
 
#define FAIL_IF_NULL(PTR_ARG)
 

Functions

static location_t as_location_t (const diagnostic_physical_location *loc)
 
static diagnostic_event_id as_diagnostic_event_id (diagnostic_event_id_t id)
 
static size_t round_alloc_size (size_t s)
 
static diagnostic_t diagnostic_t_from_diagnostic_level (enum diagnostic_level level)
 
diagnostic_managerdiagnostic_manager_new (void)
 
void diagnostic_manager_release (diagnostic_manager *diag_mgr)
 
void diagnostic_manager_set_tool_name (diagnostic_manager *diag_mgr, const char *value)
 
void diagnostic_manager_set_full_name (diagnostic_manager *diag_mgr, const char *value)
 
void diagnostic_manager_set_version_string (diagnostic_manager *diag_mgr, const char *value)
 
void diagnostic_manager_set_version_url (diagnostic_manager *diag_mgr, const char *value)
 
diagnostic_text_sinkdiagnostic_manager_add_text_sink (diagnostic_manager *diag_mgr, FILE *dst_stream, enum diagnostic_colorize colorize)
 
void diagnostic_text_sink_set_source_printing_enabled (diagnostic_text_sink *text_sink, int value)
 
void diagnostic_text_sink_set_colorize (diagnostic_text_sink *text_sink, enum diagnostic_colorize colorize)
 
void diagnostic_text_sink_set_labelled_source_colorization_enabled (diagnostic_text_sink *text_sink, int value)
 
void diagnostic_manager_add_sarif_sink (diagnostic_manager *diag_mgr, FILE *dst_stream, const diagnostic_file *main_input_file, enum diagnostic_sarif_version version)
 
void diagnostic_manager_write_patch (diagnostic_manager *diag_mgr, FILE *dst_stream)
 
diagnostic_filediagnostic_manager_new_file (diagnostic_manager *diag_mgr, const char *name, const char *sarif_source_language)
 
void diagnostic_file_set_buffered_content (diagnostic_file *file, const char *buf, size_t sz)
 
void diagnostic_manager_debug_dump_file (diagnostic_manager *, const diagnostic_file *file, FILE *out)
 
const diagnostic_physical_locationdiagnostic_manager_new_location_from_file_and_line (diagnostic_manager *diag_mgr, const diagnostic_file *file, diagnostic_line_num_t linenum)
 
const diagnostic_physical_locationdiagnostic_manager_new_location_from_file_line_column (diagnostic_manager *diag_mgr, const diagnostic_file *file, diagnostic_line_num_t line_num, diagnostic_column_num_t column_num)
 
const diagnostic_physical_locationdiagnostic_manager_new_location_from_range (diagnostic_manager *diag_mgr, const diagnostic_physical_location *loc_caret, const diagnostic_physical_location *loc_start, const diagnostic_physical_location *loc_end)
 
void diagnostic_manager_debug_dump_location (const diagnostic_manager *diag_mgr, const diagnostic_physical_location *loc, FILE *out)
 
const diagnostic_logical_locationdiagnostic_manager_new_logical_location (diagnostic_manager *diag_mgr, enum diagnostic_logical_location_kind_t kind, const diagnostic_logical_location *parent, const char *short_name, const char *fully_qualified_name, const char *decorated_name)
 
void diagnostic_manager_debug_dump_logical_location (const diagnostic_manager *diag_mgr, const diagnostic_logical_location *loc, FILE *out)
 
void diagnostic_manager_begin_group (diagnostic_manager *diag_mgr)
 
void diagnostic_manager_end_group (diagnostic_manager *diag_mgr)
 
diagnosticdiagnostic_begin (diagnostic_manager *diag_mgr, enum diagnostic_level level)
 
void diagnostic_set_cwe (diagnostic *diag, unsigned cwe_id)
 
void diagnostic_add_rule (diagnostic *diag, const char *title, const char *url)
 
void diagnostic_set_location (diagnostic *diag, const diagnostic_physical_location *loc)
 
void diagnostic_add_location (diagnostic *diag, const diagnostic_physical_location *loc)
 
void diagnostic_add_location_with_label (diagnostic *diag, const diagnostic_physical_location *loc, const char *text)
 
void diagnostic_set_logical_location (diagnostic *diag, const diagnostic_logical_location *logical_loc)
 
void diagnostic_add_fix_it_hint_insert_before (diagnostic *diag, const diagnostic_physical_location *loc, const char *addition)
 
void diagnostic_add_fix_it_hint_insert_after (diagnostic *diag, const diagnostic_physical_location *loc, const char *addition)
 
void diagnostic_add_fix_it_hint_replace (diagnostic *diag, const diagnostic_physical_location *loc, const char *replacement)
 
void diagnostic_add_fix_it_hint_delete (diagnostic *diag, const diagnostic_physical_location *loc)
 
diagnostic_execution_pathdiagnostic_add_execution_path (diagnostic *diag)
 
diagnostic_execution_pathdiagnostic_manager_new_execution_path (diagnostic_manager *manager)
 
void diagnostic_take_execution_path (diagnostic *diag, diagnostic_execution_path *path)
 
void diagnostic_execution_path_release (diagnostic_execution_path *path)
 
diagnostic_event_id diagnostic_execution_path_add_event (diagnostic_execution_path *path, const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, const char *gmsgid,...)
 
diagnostic_event_id diagnostic_execution_path_add_event_va (diagnostic_execution_path *path, const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, const char *gmsgid, va_list *args)
 
void diagnostic_finish (diagnostic *diag, const char *gmsgid,...)
 
void diagnostic_finish_va (diagnostic *diag, const char *gmsgid, va_list *args)
 

Macro Definition Documentation

◆ FAIL_IF_NULL

#define FAIL_IF_NULL ( PTR_ARG)
Value:
do { \
volatile const void *p = (PTR_ARG); \
if (!p) { \
fprintf (stderr, "%s: %s must be non-NULL\n", \
__func__, #PTR_ARG); \
abort (); \
} \
} while (0)
Error-checking at the API boundary.   

Referenced by diagnostic_add_execution_path(), diagnostic_add_fix_it_hint_delete(), diagnostic_add_fix_it_hint_insert_after(), diagnostic_add_fix_it_hint_insert_before(), diagnostic_add_fix_it_hint_replace(), diagnostic_add_location(), diagnostic_add_location_with_label(), diagnostic_add_rule(), diagnostic_begin(), diagnostic_execution_path_add_event(), diagnostic_execution_path_add_event_va(), diagnostic_file_set_buffered_content(), diagnostic_finish(), diagnostic_finish_va(), diagnostic_manager_add_sarif_sink(), diagnostic_manager_add_text_sink(), diagnostic_manager_begin_group(), diagnostic_manager_debug_dump_file(), diagnostic_manager_debug_dump_location(), diagnostic_manager_debug_dump_logical_location(), diagnostic_manager_end_group(), diagnostic_manager_new_execution_path(), diagnostic_manager_new_file(), diagnostic_manager_new_location_from_file_and_line(), diagnostic_manager_new_location_from_file_line_column(), diagnostic_manager_new_location_from_range(), diagnostic_manager_new_logical_location(), diagnostic_manager_set_full_name(), diagnostic_manager_set_tool_name(), diagnostic_manager_set_version_string(), diagnostic_manager_set_version_url(), diagnostic_manager_write_patch(), diagnostic_set_cwe(), diagnostic_set_location(), diagnostic_set_logical_location(), diagnostic_take_execution_path(), diagnostic_text_sink_set_colorize(), diagnostic_text_sink_set_labelled_source_colorization_enabled(), diagnostic_text_sink_set_source_printing_enabled(), and sarif_replay_path().

◆ INCLUDE_MAP

#define INCLUDE_MAP
C++ implementation of a pure C API for emitting diagnostics.
   Copyright (C) 2023-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

◆ INCLUDE_VECTOR

#define INCLUDE_VECTOR

Function Documentation

◆ as_diagnostic_event_id()

◆ as_location_t()

◆ diagnostic_add_execution_path()

diagnostic_execution_path * diagnostic_add_execution_path ( diagnostic * diag)
Public entrypoint.   

References diagnostic::add_execution_path(), and FAIL_IF_NULL.

◆ diagnostic_add_fix_it_hint_delete()

◆ diagnostic_add_fix_it_hint_insert_after()

◆ diagnostic_add_fix_it_hint_insert_before()

◆ diagnostic_add_fix_it_hint_replace()

◆ diagnostic_add_location()

◆ diagnostic_add_location_with_label()

◆ diagnostic_add_rule()

void diagnostic_add_rule ( diagnostic * diag,
const char * title,
const char * url )
Public entrypoint.   

References diagnostic::add_rule(), and FAIL_IF_NULL.

Referenced by libgdiagnostics::diagnostic::add_rule().

◆ diagnostic_begin()

diagnostic * diagnostic_begin ( diagnostic_manager * diag_mgr,
enum diagnostic_level level )
Public entrypoint.   

References FAIL_IF_NULL.

Referenced by libgdiagnostics::manager::begin_diagnostic().

◆ diagnostic_execution_path_add_event()

diagnostic_event_id diagnostic_execution_path_add_event ( diagnostic_execution_path * path,
const diagnostic_physical_location * physical_loc,
const diagnostic_logical_location * logical_loc,
unsigned stack_depth,
const char * gmsgid,
... )
Public entrypoint.   

References as_diagnostic_event_id(), and FAIL_IF_NULL.

◆ diagnostic_execution_path_add_event_va()

diagnostic_event_id diagnostic_execution_path_add_event_va ( diagnostic_execution_path * path,
const diagnostic_physical_location * physical_loc,
const diagnostic_logical_location * logical_loc,
unsigned stack_depth,
const char * gmsgid,
va_list * args )

◆ diagnostic_execution_path_release()

void diagnostic_execution_path_release ( diagnostic_execution_path * path)
Public entrypoint.   

References path.

Referenced by libgdiagnostics::execution_path::~execution_path().

◆ diagnostic_file_set_buffered_content()

void diagnostic_file_set_buffered_content ( diagnostic_file * file,
const char * buf,
size_t sz )

◆ diagnostic_finish()

void diagnostic_finish ( diagnostic * diag,
const char * gmsgid,
... )
Public entrypoint.   

References diagnostic_finish_va(), and FAIL_IF_NULL.

Referenced by diagnostic_manager_debug_dump_location().

◆ diagnostic_finish_va()

◆ diagnostic_manager_add_sarif_sink()

void diagnostic_manager_add_sarif_sink ( diagnostic_manager * diag_mgr,
FILE * dst_stream,
const diagnostic_file * main_input_file,
enum diagnostic_sarif_version version )

◆ diagnostic_manager_add_text_sink()

diagnostic_text_sink * diagnostic_manager_add_text_sink ( diagnostic_manager * diag_mgr,
FILE * dst_stream,
enum diagnostic_colorize colorize )

◆ diagnostic_manager_begin_group()

void diagnostic_manager_begin_group ( diagnostic_manager * diag_mgr)
Public entrypoint.   

References diagnostic_manager::begin_group(), and FAIL_IF_NULL.

Referenced by libgdiagnostics::group::group().

◆ diagnostic_manager_debug_dump_file()

void diagnostic_manager_debug_dump_file ( diagnostic_manager * diag_mgr,
const diagnostic_file * file,
FILE * out )
Write a representation of FILE to OUT, for debugging.   

References FAIL_IF_NULL, diagnostic_file::get_content(), diagnostic_file::get_name(), and diagnostic_file::get_sarif_source_language().

◆ diagnostic_manager_debug_dump_location()

◆ diagnostic_manager_debug_dump_logical_location()

◆ diagnostic_manager_end_group()

void diagnostic_manager_end_group ( diagnostic_manager * diag_mgr)
extern
Public entrypoint.   

References diagnostic_manager::end_group(), and FAIL_IF_NULL.

Referenced by libgdiagnostics::group::~group().

◆ diagnostic_manager_new()

diagnostic_manager * diagnostic_manager_new ( void )
Public entrypoints.   
Public entrypoint for clients to acquire a diagnostic_manager.   

◆ diagnostic_manager_new_execution_path()

diagnostic_execution_path * diagnostic_manager_new_execution_path ( diagnostic_manager * manager)

◆ diagnostic_manager_new_file()

diagnostic_file * diagnostic_manager_new_file ( diagnostic_manager * diag_mgr,
const char * name,
const char * sarif_source_language )
Public entrypoint.   

References FAIL_IF_NULL, and diagnostic_manager::new_file().

Referenced by libgdiagnostics::manager::new_file().

◆ diagnostic_manager_new_location_from_file_and_line()

const diagnostic_physical_location * diagnostic_manager_new_location_from_file_and_line ( diagnostic_manager * diag_mgr,
const diagnostic_file * file,
diagnostic_line_num_t linenum )

◆ diagnostic_manager_new_location_from_file_line_column()

const diagnostic_physical_location * diagnostic_manager_new_location_from_file_line_column ( diagnostic_manager * diag_mgr,
const diagnostic_file * file,
diagnostic_line_num_t line_num,
diagnostic_column_num_t column_num )

◆ diagnostic_manager_new_location_from_range()

const diagnostic_physical_location * diagnostic_manager_new_location_from_range ( diagnostic_manager * diag_mgr,
const diagnostic_physical_location * loc_caret,
const diagnostic_physical_location * loc_start,
const diagnostic_physical_location * loc_end )

◆ diagnostic_manager_new_logical_location()

const diagnostic_logical_location * diagnostic_manager_new_logical_location ( diagnostic_manager * diag_mgr,
enum diagnostic_logical_location_kind_t kind,
const diagnostic_logical_location * parent,
const char * short_name,
const char * fully_qualified_name,
const char * decorated_name )

◆ diagnostic_manager_release()

void diagnostic_manager_release ( diagnostic_manager * diag_mgr)
Public entrypoint for clients to release a diagnostic_manager.   

Referenced by libgdiagnostics::manager::~manager().

◆ diagnostic_manager_set_full_name()

void diagnostic_manager_set_full_name ( diagnostic_manager * diag_mgr,
const char * value )

◆ diagnostic_manager_set_tool_name()

void diagnostic_manager_set_tool_name ( diagnostic_manager * diag_mgr,
const char * value )

◆ diagnostic_manager_set_version_string()

void diagnostic_manager_set_version_string ( diagnostic_manager * diag_mgr,
const char * value )

◆ diagnostic_manager_set_version_url()

void diagnostic_manager_set_version_url ( diagnostic_manager * diag_mgr,
const char * value )

◆ diagnostic_manager_write_patch()

void diagnostic_manager_write_patch ( diagnostic_manager * diag_mgr,
FILE * dst_stream )

◆ diagnostic_set_cwe()

void diagnostic_set_cwe ( diagnostic * diag,
unsigned cwe_id )
Public entrypoint.   

References FAIL_IF_NULL, and diagnostic::set_cwe().

Referenced by libgdiagnostics::diagnostic::set_cwe().

◆ diagnostic_set_location()

◆ diagnostic_set_logical_location()

void diagnostic_set_logical_location ( diagnostic * diag,
const diagnostic_logical_location * logical_loc )

◆ diagnostic_t_from_diagnostic_level()

static diagnostic_t diagnostic_t_from_diagnostic_level ( enum diagnostic_level level)
static

◆ diagnostic_take_execution_path()

void diagnostic_take_execution_path ( diagnostic * diag,
diagnostic_execution_path * path )
extern

◆ diagnostic_text_sink_set_colorize()

void diagnostic_text_sink_set_colorize ( diagnostic_text_sink * text_sink,
enum diagnostic_colorize colorize )

◆ diagnostic_text_sink_set_labelled_source_colorization_enabled()

void diagnostic_text_sink_set_labelled_source_colorization_enabled ( diagnostic_text_sink * text_sink,
int value )

◆ diagnostic_text_sink_set_source_printing_enabled()

void diagnostic_text_sink_set_source_printing_enabled ( diagnostic_text_sink * text_sink,
int value )

◆ round_alloc_size()

static size_t round_alloc_size ( size_t s)
static
Helper for the linemap code.