GCC Middle and Back End API Reference
diagnostic-format-json.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
#include "selftest-diagnostic.h"
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-format.h"
#include "diagnostic-buffer.h"
#include "json.h"
#include "selftest.h"
#include "diagnostic-client-data-hooks.h"
#include "logical-location.h"
Include dependency graph for diagnostic-format-json.cc:

Data Structures

class  diagnostic_json_format_buffer
class  json_output_format
class  json_stderr_output_format
class  json_file_output_format

Macros

#define INCLUDE_VECTOR

Functions

static std::unique_ptr< json::objectjson_from_expanded_location (diagnostic_context &context, location_t loc)
static std::unique_ptr< json::objectjson_from_location_range (diagnostic_context &context, const location_range *loc_range, unsigned range_idx)
static std::unique_ptr< json::objectjson_from_fixit_hint (diagnostic_context &context, const fixit_hint *hint)
static std::unique_ptr< json::objectjson_from_metadata (const diagnostic_metadata *metadata)
static std::unique_ptr< json::arraymake_json_for_path (diagnostic_context &context, pretty_printer *ref_pp, const diagnostic_path *path)
static diagnostic_output_formatdiagnostic_output_format_init_json (diagnostic_context &context, std::unique_ptr< json_output_format > fmt)
diagnostic_output_formatdiagnostic_output_format_init_json_stderr (diagnostic_context &context, bool formatted)
diagnostic_output_formatdiagnostic_output_format_init_json_file (diagnostic_context &context, bool formatted, const char *base_file_name)

Macro Definition Documentation

◆ INCLUDE_VECTOR

#define INCLUDE_VECTOR
JSON output for diagnostics Copyright (C) 2018-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. 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/>.

Function Documentation

◆ diagnostic_output_format_init_json()

diagnostic_output_format & diagnostic_output_format_init_json ( diagnostic_context & context,
std::unique_ptr< json_output_format > fmt )
static
Populate CONTEXT in preparation for JSON output (either to stderr, or to a file) using FMT. Return a reference to *FMT.

References gcc_assert, pp_show_color(), diagnostic_context::set_output_format(), and diagnostic_context::set_show_highlight_colors().

Referenced by diagnostic_output_format_init_json_file(), and diagnostic_output_format_init_json_stderr().

◆ diagnostic_output_format_init_json_file()

diagnostic_output_format & diagnostic_output_format_init_json_file ( diagnostic_context & context,
bool formatted,
const char * base_file_name )
Populate CONTEXT in preparation for JSON output to a file named BASE_FILE_NAME.gcc.json. Return a reference to the context's new sink.

References base_file_name(), and diagnostic_output_format_init_json().

Referenced by diagnostic_output_format_init().

◆ diagnostic_output_format_init_json_stderr()

diagnostic_output_format & diagnostic_output_format_init_json_stderr ( diagnostic_context & context,
bool formatted )
Populate CONTEXT in preparation for JSON output to stderr. Return a reference to the context's new sink.

References diagnostic_output_format_init_json().

Referenced by diagnostic_output_format_init().

◆ json_from_expanded_location()

◆ json_from_fixit_hint()

std::unique_ptr< json::object > json_from_fixit_hint ( diagnostic_context & context,
const fixit_hint * hint )
static
Generate a JSON object for HINT.

References json_from_expanded_location().

Referenced by json_output_format::on_report_diagnostic().

◆ json_from_location_range()

std::unique_ptr< json::object > json_from_location_range ( diagnostic_context & context,
const location_range * loc_range,
unsigned range_idx )
static

◆ json_from_metadata()

std::unique_ptr< json::object > json_from_metadata ( const diagnostic_metadata * metadata)
static
Generate a JSON object for METADATA.

References diagnostic_metadata::get_cwe().

Referenced by json_output_format::on_report_diagnostic().

◆ make_json_for_path()

std::unique_ptr< json::array > make_json_for_path ( diagnostic_context & context,
pretty_printer * ref_pp,
const diagnostic_path * path )
static