diagnostics/digraphs.o \
diagnostics/state-graphs.o \
diagnostics/state-graphs-to-dot.o \
+ diagnostics/selftest-logical-locations.o \
edit-context.o \
graphviz.o pex.o \
pretty-print.o intl.o \
selftest.o selftest-diagnostic.o sort.o \
selftest-diagnostic-path.o \
selftest-json.o \
- selftest-logical-location.o \
text-art/box-drawing.o \
text-art/canvas.o \
text-art/ruler.o \
location_t get_location () const final override { return m_loc; }
int get_stack_depth () const final override { return m_effective_depth; }
- logical_location get_logical_location () const final override
+ diagnostics::logical_locations::key
+ get_logical_location () const final override
{
return m_logical_loc;
}
int m_effective_depth;
pending_diagnostic *m_pending_diagnostic;
diagnostic_event_id_t m_emission_id; // only set once all pruning has occurred
- logical_location m_logical_loc;
+ diagnostics::logical_locations::key m_logical_loc;
};
/* A concrete event subclass for a purely textual event, for use in
}
}
-const logical_location_manager &
+const diagnostics::logical_locations::manager &
diagnostic_manager::get_logical_location_manager () const
{
gcc_assert (global_dc);
}
private:
- const logical_location_manager &
+ const diagnostics::logical_locations::manager &
get_logical_location_manager () const;
void build_emission_path (const path_builder &pb,
#ifndef GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H
#define GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
class sarif_object;
class client_version_info;
/* Get version info for this client, or NULL. */
virtual const client_version_info *get_any_version_info () const = 0;
- /* Get the current logical_location_manager for this client, or NULL. */
- virtual const logical_location_manager *get_logical_location_manager () const = 0;
+ /* Get the current logical_locations::manager for this client, or null. */
+ virtual const diagnostics::logical_locations::manager *
+ get_logical_location_manager () const = 0;
- /* Get the current logical_location, or null.
- If this returns a non-null logical_location, then
- get_logical_location_manager must return non-NULL. */
- virtual logical_location get_current_logical_location () const = 0;
+ /* Get the current logical location, or null.
+ If this returns a non-null logical location, then
+ get_logical_location_manager must return non-null. */
+ virtual diagnostics::logical_locations::key
+ get_current_logical_location () const = 0;
/* Get a sourceLanguage value for FILENAME, or return NULL.
See SARIF v2.1.0 Appendix J for suggested values. */
#include "json.h"
#include "selftest-xml.h"
+using namespace diagnostics;
+
// struct html_generation_options
html_generation_options::html_generation_options ()
diagnostic_t orig_diag_kind,
diagnostic_html_format_buffer *buffer);
void emit_diagram (const diagnostic_diagram &diagram);
- void emit_global_graph (const diagnostics::digraphs::lazy_digraph &);
+ void emit_global_graph (const digraphs::lazy_digraph &);
void end_group ();
pop_nesting_level ();
void
- add_graph (const diagnostics::digraphs::digraph &dg,
+ add_graph (const digraphs::digraph &dg,
xml::element &parent_element);
diagnostic_context &m_context;
pretty_printer *m_printer;
const line_maps *m_line_maps;
html_generation_options m_html_gen_opts;
- const logical_location_manager *m_logical_loc_mgr;
+ const logical_locations::manager *m_logical_loc_mgr;
std::unique_ptr<xml::document> m_document;
xml::element *m_head_element;
std::vector<xml::element *> m_cur_nesting_levels;
int m_next_diag_id; // for handing out unique IDs
json::array m_ui_focus_ids;
- logical_location m_last_logical_location;
+ logical_locations::key m_last_logical_location;
location_t m_last_location;
expanded_location m_last_expanded_location;
};
if (m_cur_diagnostic_element && nesting_level > 0)
alert = false;
if (!m_cur_diagnostic_element)
- m_last_logical_location = logical_location ();
+ m_last_logical_location = logical_locations::key ();
auto diag_element
= make_element_for_diagnostic (diagnostic, orig_diag_kind, alert);
if (buffer)
return nullptr;
// Convert it to .dot AST
- auto dot_graph
- = diagnostics::state_graphs::make_dot_graph (*state_graph,
+ auto dot_graph = state_graphs::make_dot_graph (*state_graph,
*m_logical_loc_mgr);
gcc_assert (dot_graph);
}
static const char *
-get_label_for_logical_location_kind (enum logical_location_kind kind)
+get_label_for_logical_location_kind (enum logical_locations::kind kind)
{
switch (kind)
{
default:
gcc_unreachable ();
- case logical_location_kind::unknown:
+ case logical_locations::kind::unknown:
return nullptr;
/* Kinds within executable code. */
- case logical_location_kind::function:
+ case logical_locations::kind::function:
return "Function";
- case logical_location_kind::member:
+ case logical_locations::kind::member:
return "Member";
- case logical_location_kind::module_:
+ case logical_locations::kind::module_:
return "Module";
- case logical_location_kind::namespace_:
+ case logical_locations::kind::namespace_:
return "Namespace";
- case logical_location_kind::type:
+ case logical_locations::kind::type:
return "Type";
- case logical_location_kind::return_type:
+ case logical_locations::kind::return_type:
return "Return type";
- case logical_location_kind::parameter:
+ case logical_locations::kind::parameter:
return "Parameter";
- case logical_location_kind::variable:
+ case logical_locations::kind::variable:
return "Variable";
/* Kinds within XML or HTML documents. */
- case logical_location_kind::element:
+ case logical_locations::kind::element:
return "Element";
- case logical_location_kind::attribute:
+ case logical_locations::kind::attribute:
return "Attribute";
- case logical_location_kind::text:
+ case logical_locations::kind::text:
return "Text";
- case logical_location_kind::comment:
+ case logical_locations::kind::comment:
return "Comment";
- case logical_location_kind::processing_instruction:
+ case logical_locations::kind::processing_instruction:
return "Processing Instruction";
- case logical_location_kind::dtd:
+ case logical_locations::kind::dtd:
return "DTD";
- case logical_location_kind::declaration:
+ case logical_locations::kind::declaration:
return "Declaration";
/* Kinds within JSON documents. */
- case logical_location_kind::object:
+ case logical_locations::kind::object:
return "Object";
- case logical_location_kind::array:
+ case logical_locations::kind::array:
return "Array";
- case logical_location_kind::property:
+ case logical_locations::kind::property:
return "Property";
- case logical_location_kind::value:
+ case logical_locations::kind::value:
return "Value";
}
}
if (auto logical_loc = client_data_hooks->get_current_logical_location ())
if (logical_loc != m_last_logical_location)
{
- enum logical_location_kind kind
+ enum logical_locations::kind kind
= m_logical_loc_mgr->get_kind (logical_loc);;
if (const char *label = get_label_for_logical_location_kind (kind))
if (const char *name_with_scope
}
void
-html_builder::add_graph (const diagnostics::digraphs::digraph &dg,
+html_builder::add_graph (const digraphs::digraph &dg,
xml::element &parent_element)
{
if (auto dot_graph = dg.make_dot_graph ())
}
void
-html_builder::emit_global_graph (const diagnostics::digraphs::lazy_digraph &ldg)
+html_builder::emit_global_graph (const digraphs::lazy_digraph &ldg)
{
auto &dg = ldg.get_or_create_digraph ();
gcc_assert (m_body_element);
}
void
- report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) final override
+ report_global_digraph (const digraphs::lazy_digraph &ldg) final override
{
m_builder.emit_global_graph (ldg);
}
#include "diagnostic-buffer.h"
#include "json.h"
#include "cpplib.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
#include "text-art/canvas.h"
#include "backtrace.h"
#include "xml.h"
+using namespace diagnostics;
+
/* A json::array where the values are "unique" as per
SARIF v2.1.0 section 3.7.3 ("Array properties with unique values"). */
m_printer = &printer;
}
- const logical_location_manager *
+ const logical_locations::manager *
get_logical_location_manager () const
{
return m_logical_loc_mgr;
void end_group ();
void
- report_global_digraph (const diagnostics::digraphs::lazy_digraph &);
+ report_global_digraph (const digraphs::lazy_digraph &);
std::unique_ptr<sarif_result> take_current_result ()
{
std::unique_ptr<sarif_location>
make_location_object (sarif_location_manager *loc_mgr,
const rich_location &rich_loc,
- logical_location logical_loc,
+ logical_locations::key logical_loc,
enum diagnostic_artifact_role role);
std::unique_ptr<sarif_location>
make_location_object (sarif_location_manager &loc_mgr,
const sarif_generation_options &get_opts () const { return m_sarif_gen_opts; }
std::unique_ptr<sarif_logical_location>
- make_minimal_sarif_logical_location (logical_location);
+ make_minimal_sarif_logical_location (logical_locations::key);
private:
class sarif_token_printer : public token_printer
location_t where);
void
set_any_logical_locs_arr (sarif_location &location_obj,
- logical_location logical_loc);
+ logical_locations::key logical_loc);
std::unique_ptr<sarif_location>
make_location_object (sarif_location_manager &loc_mgr,
const diagnostic_event &event,
make_region_object_for_hint (const fixit_hint &hint) const;
int
- ensure_sarif_logical_location_for (logical_location k);
+ ensure_sarif_logical_location_for (logical_locations::key k);
std::unique_ptr<sarif_multiformat_message_string>
make_multiformat_message_string (const char *msg) const;
const line_maps *m_line_maps;
sarif_token_printer m_token_printer;
- const logical_location_manager *m_logical_loc_mgr;
+ const logical_locations::manager *m_logical_loc_mgr;
/* The JSON object for the invocation object. */
std::unique_ptr<sarif_invocation> m_invocation_obj;
often they won't. */
auto location_obj
= builder.make_location_object (this, *diagnostic.richloc,
- logical_location (),
+ logical_locations::key (),
diagnostic_artifact_role::result_file);
auto message_obj
= builder.make_message_object (pp_formatted_text (builder.get_printer ()));
void
sarif_builder::
-report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg)
+report_global_digraph (const digraphs::lazy_digraph &ldg)
{
auto &dg = ldg.get_or_create_digraph ();
enum diagnostic_artifact_role role)
{
auto locations_arr = std::make_unique<json::array> ();
- logical_location logical_loc;
+ logical_locations::key logical_loc;
if (auto client_data_hooks = m_context.get_client_data_hooks ())
logical_loc = client_data_hooks->get_current_logical_location ();
void
sarif_builder::
set_any_logical_locs_arr (sarif_location &location_obj,
- logical_location logical_loc)
+ logical_locations::key logical_loc)
{
if (!logical_loc)
return;
std::unique_ptr<sarif_location>
sarif_builder::make_location_object (sarif_location_manager *loc_mgr,
const rich_location &rich_loc,
- logical_location logical_loc,
+ logical_locations::key logical_loc,
enum diagnostic_artifact_role role)
{
class escape_nonascii_renderer : public content_renderer
std::move (phs_loc_obj));
/* "logicalLocations" property (SARIF v2.1.0 section 3.28.4). */
- logical_location logical_loc = event.get_logical_location ();
+ logical_locations::key logical_loc = event.get_logical_location ();
set_any_logical_locs_arr (*location_obj, logical_loc);
/* "message" property (SARIF v2.1.0 section 3.28.5). */
Return nullptr if unknown. */
static const char *
-maybe_get_sarif_kind (enum logical_location_kind kind)
+maybe_get_sarif_kind (enum logical_locations::kind kind)
{
+ using namespace logical_locations;
+
switch (kind)
{
default:
gcc_unreachable ();
- case logical_location_kind::unknown:
+ case logical_locations::kind::unknown:
return nullptr;
/* Kinds within executable code. */
- case logical_location_kind::function:
+ case logical_locations::kind::function:
return "function";
- case logical_location_kind::member:
+ case logical_locations::kind::member:
return "member";
- case logical_location_kind::module_:
+ case logical_locations::kind::module_:
return "module";
- case logical_location_kind::namespace_:
+ case logical_locations::kind::namespace_:
return "namespace";
- case logical_location_kind::type:
+ case logical_locations::kind::type:
return "type";
- case logical_location_kind::return_type:
+ case logical_locations::kind::return_type:
return "returnType";
- case logical_location_kind::parameter:
+ case logical_locations::kind::parameter:
return "parameter";
- case logical_location_kind::variable:
+ case logical_locations::kind::variable:
return "variable";
/* Kinds within XML or HTML documents. */
- case logical_location_kind::element:
+ case logical_locations::kind::element:
return "element";
- case logical_location_kind::attribute:
+ case logical_locations::kind::attribute:
return "attribute";
- case logical_location_kind::text:
+ case logical_locations::kind::text:
return "text";
- case logical_location_kind::comment:
+ case logical_locations::kind::comment:
return "comment";
- case logical_location_kind::processing_instruction:
+ case logical_locations::kind::processing_instruction:
return "processingInstruction";
- case logical_location_kind::dtd:
+ case logical_locations::kind::dtd:
return "dtd";
- case logical_location_kind::declaration:
+ case logical_locations::kind::declaration:
return "declaration";
/* Kinds within JSON documents. */
- case logical_location_kind::object:
+ case logical_locations::kind::object:
return "object";
- case logical_location_kind::array:
+ case logical_locations::kind::array:
return "array";
- case logical_location_kind::property:
+ case logical_locations::kind::property:
return "property";
- case logical_location_kind::value:
+ case logical_locations::kind::value:
return "value";
}
}
void
sarif_property_bag::set_logical_location (const char *property_name,
sarif_builder &builder,
- logical_location logical_loc)
+ logical_locations::key logical_loc)
{
set<sarif_logical_location>
(property_name,
}
static void
-copy_any_property_bag (const diagnostics::digraphs::object &input_obj,
+copy_any_property_bag (const digraphs::object &input_obj,
sarif_object &output_obj)
{
if (input_obj.get_property_bag ())
}
std::unique_ptr<sarif_graph>
-make_sarif_graph (const diagnostics::digraphs::digraph &g,
+make_sarif_graph (const digraphs::digraph &g,
sarif_builder *builder,
sarif_location_manager *sarif_location_mgr)
{
}
std::unique_ptr<sarif_node>
-make_sarif_node (const diagnostics::digraphs::node &n,
+make_sarif_node (const digraphs::node &n,
sarif_builder *builder,
sarif_location_manager *sarif_location_mgr)
{
}
std::unique_ptr<sarif_edge>
-make_sarif_edge (const diagnostics::digraphs::edge &e,
+make_sarif_edge (const digraphs::edge &e,
sarif_builder *builder)
{
auto result = std::make_unique<sarif_edge> ();
sarif_property_bag::set_graph (const char *property_name,
sarif_builder &builder,
sarif_location_manager *sarif_location_mgr,
- const diagnostics::digraphs::digraph &g)
+ const digraphs::digraph &g)
{
set<sarif_graph> (property_name,
make_sarif_graph (g, &builder, sarif_location_mgr));
int
sarif_builder::
-ensure_sarif_logical_location_for (logical_location k)
+ensure_sarif_logical_location_for (logical_locations::key k)
{
gcc_assert (m_logical_loc_mgr);
sarif_logical_loc->set_string ("decoratedName", internal_name);
/* "kind" property (SARIF v2.1.0 section 3.33.7). */
- enum logical_location_kind kind = m_logical_loc_mgr->get_kind (k);
+ enum logical_locations::kind kind = m_logical_loc_mgr->get_kind (k);
if (const char *sarif_kind_str = maybe_get_sarif_kind (kind))
sarif_logical_loc->set_string ("kind", sarif_kind_str);
std::unique_ptr<sarif_logical_location>
sarif_builder::
-make_minimal_sarif_logical_location (logical_location logical_loc)
+make_minimal_sarif_logical_location (logical_locations::key logical_loc)
{
gcc_assert (m_logical_loc_mgr);
}
void
- report_global_digraph (const diagnostics::digraphs::lazy_digraph &lazy_digraph) final override
+ report_global_digraph (const digraphs::lazy_digraph &lazy_digraph) final override
{
m_builder.report_global_digraph (lazy_digraph);
}
std::unique_ptr<sarif_location> location_obj
= builder.make_location_object
- (&result, richloc, logical_location (),
+ (&result, richloc, logical_locations::key (),
diagnostic_artifact_role::analysis_target);
ASSERT_NE (location_obj, nullptr);
#include "json.h"
#include "diagnostic-format.h"
#include "diagnostic-output-file.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
/* Enum for choosing what format to serializing the generated SARIF into. */
public:
void set_logical_location (const char *property_name,
sarif_builder &,
- logical_location logical_loc);
+ diagnostics::logical_locations::key logical_loc);
void set_graph (const char *property_name,
sarif_builder &,
sarif_location_manager *sarif_location_mgr,
namespace {
+using namespace diagnostics;
+
/* A bundle of state for printing a path. */
class path_print_policy
{
public:
per_thread_summary (const diagnostic_path &path,
- const logical_location_manager &logical_loc_mgr,
+ const logical_locations::manager &logical_loc_mgr,
label_text name, unsigned swimlane_idx)
: m_path (path),
m_logical_loc_mgr (logical_loc_mgr),
friend struct event_range;
const diagnostic_path &m_path;
- const logical_location_manager &m_logical_loc_mgr;
+ const logical_locations::manager &m_logical_loc_mgr;
const label_text m_name;
struct stack_frame
{
stack_frame (std::unique_ptr<stack_frame> parent,
- logical_location logical_loc,
+ logical_locations::key logical_loc,
int stack_depth)
: m_parent (std::move (parent)),
m_logical_loc (logical_loc),
{}
std::unique_ptr<stack_frame> m_parent;
- logical_location m_logical_loc;
+ logical_locations::key m_logical_loc;
const int m_stack_depth;
};
static std::unique_ptr<stack_frame>
begin_html_stack_frame (xml::printer &xp,
std::unique_ptr<stack_frame> parent,
- logical_location logical_loc,
+ logical_locations::key logical_loc,
int stack_depth,
- const logical_location_manager *logical_loc_mgr)
+ const logical_locations::manager *logical_loc_mgr)
{
if (logical_loc)
{
const diagnostic_path &m_path;
const diagnostic_event &m_initial_event;
- logical_location m_logical_loc;
+ logical_locations::key m_logical_loc;
int m_stack_depth;
unsigned m_start_idx;
unsigned m_end_idx;
bool colorize = false,
bool show_event_links = true);
- const logical_location_manager &get_logical_location_manager () const
+ const logical_locations::manager &get_logical_location_manager () const
{
return m_logical_loc_mgr;
}
return **slot;
}
- const logical_location_manager &m_logical_loc_mgr;
+ const logical_locations::manager &m_logical_loc_mgr;
auto_delete_vec <event_range> m_ranges;
auto_delete_vec <per_thread_summary> m_per_thread_summary;
hash_map<int_hash<diagnostic_thread_id_t, -1, -2>,
void
print_swimlane_for_event_range_as_text (diagnostic_text_output_format &text_output,
pretty_printer *pp,
- const logical_location_manager &logical_loc_mgr,
+ const logical_locations::manager &logical_loc_mgr,
event_range *range,
diagnostic_source_effect_info *effect_info)
{
for (auto t : ps.m_per_thread_summary)
thread_event_printers.push_back (thread_event_printer (*t, show_depths));
- const logical_location_manager *logical_loc_mgr
+ const logical_locations::manager *logical_loc_mgr
= dc.get_logical_location_manager ();
xp.push_tag_with_class ("div", "event-ranges", false);
const int swimlane_idx
= range->m_per_thread_summary.get_swimlane_index ();
- const logical_location this_logical_loc = range->m_logical_loc;
+ const logical_locations::key this_logical_loc = range->m_logical_loc;
const int this_depth = range->m_stack_depth;
if (curr_frame)
{
/* -fdiagnostics-path-format=separate-events doesn't print
fndecl information, so with -fdiagnostics-show-path-depths
print the fndecls too, if any. */
- if (logical_location logical_loc
+ if (logical_locations::key logical_loc
= event.get_logical_location ())
{
label_text name
# pragma GCC diagnostic ignored "-Wformat-diag"
#endif
+using namespace diagnostics;
+
/* class diagnostic_event. */
/* struct diagnostic_event::meaning. */
for (unsigned i = 0; i < num; i++)
{
const diagnostic_event &event = get_event (i);
- if (logical_location logical_loc = event.get_logical_location ())
+ if (logical_locations::key logical_loc = event.get_logical_location ())
if (m_logical_loc_mgr.function_p (logical_loc))
{
*out_idx = i;
#include "diagnostic.h" /* for ATTRIBUTE_GCC_DIAG. */
#include "diagnostic-event-id.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
namespace xml { class document; }
virtual void print_desc (pretty_printer &pp) const = 0;
/* Get a logical location for this event, or null if there is none. */
- virtual logical_location get_logical_location () const = 0;
+ virtual diagnostics::logical_locations::key get_logical_location () const = 0;
virtual meaning get_meaning () const = 0;
class diagnostic_path
{
public:
+ using logical_location_manager = diagnostics::logical_locations::manager;
+
virtual ~diagnostic_path () {}
virtual unsigned num_events () const = 0;
virtual const diagnostic_event & get_event (int idx) const = 0;
#include "cpplib.h"
#include "text-art/theme.h"
#include "pretty-print-urlifier.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
#include "diagnostic-buffer.h"
#ifdef HAVE_TERMIOS_H
delete node.m_urlifier;
}
-const logical_location_manager *
+const diagnostics::logical_locations::manager *
diagnostic_context::get_logical_location_manager () const
{
if (!m_client_data_hooks)
return false;
}
-/* class logical_location_manager. */
+/* class diagnostics::logical_locations::manager. */
/* Return true iff this is a function or method. */
bool
-logical_location_manager::function_p (key k) const
+diagnostics::logical_locations::manager::function_p (key k) const
{
switch (get_kind (k))
{
default:
gcc_unreachable ();
- case logical_location_kind::unknown:
- case logical_location_kind::module_:
- case logical_location_kind::namespace_:
- case logical_location_kind::type:
- case logical_location_kind::return_type:
- case logical_location_kind::parameter:
- case logical_location_kind::variable:
+ case kind::unknown:
+ case kind::module_:
+ case kind::namespace_:
+ case kind::type:
+ case kind::return_type:
+ case kind::parameter:
+ case kind::variable:
return false;
- case logical_location_kind::function:
- case logical_location_kind::member:
+ case kind::function:
+ case kind::member:
return true;
}
}
#include "diagnostic-core.h"
namespace diagnostics {
+
+ // diagnostics::digraphs
namespace digraphs {
class lazy_digraph;
- } // namespace digraphs
+ } // namespace diagnostics::digraphs
+
+ // diagnostics::logical_locations
+ namespace logical_locations {
+ class manager;
+ } // namespace diagnostics::logical_locations
+
} // namespace diagnostics
namespace text_art
class edit_context;
class diagnostic_client_data_hooks;
-class logical_location_manager;
class diagnostic_diagram;
class diagnostic_source_effect_info;
class diagnostic_output_format;
return m_client_data_hooks;
}
- const logical_location_manager *
+ const diagnostics::logical_locations::manager *
get_logical_location_manager () const;
const urlifier *get_urlifier () const;
#define GCC_DIAGNOSTICS_DIGRAPHS_H
#include "json.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
class graphviz_out;
m_physical_loc = physical_loc;
}
- logical_location
+ logical_locations::key
get_logical_loc () const
{
return m_logical_loc;
}
void
- set_logical_loc (logical_location logical_loc)
+ set_logical_loc (logical_locations::key logical_loc)
{
m_logical_loc = logical_loc;
}
std::unique_ptr<std::string> m_label;
std::vector<std::unique_ptr<node>> m_children;
location_t m_physical_loc;
- logical_location m_logical_loc;
+ logical_locations::key m_logical_loc;
};
// An edge in a directed graph, corresponding to SARIF v2.1.0 section 3.41.
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-#ifndef GCC_LOGICAL_LOCATION_H
-#define GCC_LOGICAL_LOCATION_H
+#ifndef GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H
+#define GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H
#include "label-text.h"
+namespace diagnostics {
+namespace logical_locations {
+
/* An enum for discriminating between different kinds of logical location
for a diagnostic.
Roughly corresponds to logicalLocation's "kind" property in SARIF v2.1.0
(section 3.33.7). */
-enum class logical_location_kind
+enum class kind
{
unknown,
libgdiagnostics internals), and without requiring heap allocation of an
interface class when emitting a diagnostic.
- To do this, we split the implementation into logical_location, which is
- a wrapper around a (const void *), and logical_location_manager which
+ To do this, we split the implementation into logical_locations::key, which is
+ a wrapper around a (const void *), and logical_locations::manager which
is provided by the client and has vfunc hooks for interpreting
- logical_location instances.
+ key instances.
- Every logical_location is associated with a logical_location_manager and
- only has meaning in relation to that manager.
+ Every logical_locations::key is associated with a logical_locations::manager
+ and only has meaning in relation to that manager.
- A "nullptr" within a logical_location means "no logical location".
+ A "nullptr" within a key means "no logical location".
See tree-logical-location.h for concrete subclasses relating to trees,
where the pointer is a const_tree.
- See selftest-logical-location.h for a concrete subclass for selftests. */
+ See diagnostics/selftest-logical-locations.h for a concrete subclass for
+ selftests. */
-/* Abstract base class for giving meaning to logical_location values.
- Typically there will just be one client-provided instance, of a
- client-specific subclass. */
+/* Extrinsic state for identifying a specific logical location.
+ This will be our logical location type.
+ This only makes sense with respect to a specific manager.
+ e.g. for a tree-based one it's a wrapper around "tree".
+
+ "nullptr" means "no logical location".
+
+ Note that there is no integration with GCC's garbage collector and thus
+ keys can't be long-lived. */
-class logical_location_manager
+class key
{
public:
- /* Extrinsic state for identifying a specific logical location.
- This will be our logical_location type.
- This only makes sense with respect to a specific manager.
- e.g. for a tree-based one it's a wrapper around "tree".
- "nullptr" means "no logical location". */
- class key
+ key () : m_ptr (nullptr) {}
+
+ static key from_ptr (const void *ptr)
{
- public:
- key () : m_ptr (nullptr) {}
+ return key (ptr);
+ }
- static key from_ptr (const void *ptr)
- {
- return key (ptr);
- }
+ operator bool () const
+ {
+ return m_ptr != nullptr;
+ }
- operator bool () const
- {
- return m_ptr != nullptr;
- }
+ template <typename T>
+ T cast_to () const { return static_cast<T> (m_ptr); }
- template <typename T>
- T cast_to () const { return static_cast<T> (m_ptr); }
+ bool
+ operator== (const key &other) const
+ {
+ return m_ptr == other.m_ptr;
+ }
- bool
- operator== (const key &other) const
- {
- return m_ptr == other.m_ptr;
- }
+ bool
+ operator!= (const key &other) const
+ {
+ return m_ptr != other.m_ptr;
+ }
- bool
- operator!= (const key &other) const
- {
- return m_ptr != other.m_ptr;
- }
+ bool
+ operator< (const key &other) const
+ {
+ return m_ptr < other.m_ptr;
+ }
- bool
- operator< (const key &other) const
- {
- return m_ptr < other.m_ptr;
- }
+private:
+ explicit key (const void *ptr) : m_ptr (ptr) {}
- private:
- explicit key (const void *ptr) : m_ptr (ptr) {}
+ const void *m_ptr;
+};
- const void *m_ptr;
- };
+/* Abstract base class for giving meaning to keys.
+ Typically there will just be one client-provided instance, of a
+ client-specific subclass. */
- virtual ~logical_location_manager () {}
+class manager
+{
+public:
+ virtual ~manager () {}
- /* vfuncs for interpreting logical_location values. */
+ /* vfuncs for interpreting keys. */
/* Get a string (or NULL) for K suitable for use by the SARIF logicalLocation
"name" property (SARIF v2.1.0 section 3.33.4). */
virtual const char *get_internal_name (key k) const = 0;
/* Get what kind of SARIF logicalLocation K is (if any). */
- virtual enum logical_location_kind get_kind (key k) const = 0;
+ virtual enum kind get_kind (key k) const = 0;
/* Get a string for location K in a form suitable for path output. */
virtual label_text get_name_for_path_output (key k) const = 0;
bool function_p (key k) const;
};
-/* A logical location is a key for a given logical_location_manager.
-
- Note that there is no integration with GCC's garbage collector and thus
- logical_location instances can't be long-lived. */
-
-typedef logical_location_manager::key logical_location;
+} // namespace diagnostics::logical_locations
+} // namespace diagnostics
-#endif /* GCC_LOGICAL_LOCATION_H. */
+#endif /* GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H. */
-/* Concrete subclass of logical_location for use in selftests.
+/* Concrete subclass of logical_locations::manager for use in selftests.
Copyright (C) 2024-2025 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
#include "system.h"
#include "coretypes.h"
#include "selftest.h"
-#include "selftest-logical-location.h"
+#include "diagnostics/selftest-logical-locations.h"
#if CHECKING_P
namespace selftest {
+using namespace diagnostics::logical_locations;
+
/* class test_logical_location_manager : public logical_location_manager. */
test_logical_location_manager::~test_logical_location_manager ()
return item->m_name;
}
-enum logical_location_kind
+enum diagnostics::logical_locations::kind
test_logical_location_manager::get_kind (key k) const
{
auto item = item_from_key (k);
return label_text::borrow (item->m_name);
}
-logical_location
+diagnostics::logical_locations::key
test_logical_location_manager::
logical_location_from_funcname (const char *funcname)
{
if (item **slot = m_name_to_item_map.get (funcname))
return *slot;
- item *i = new item (logical_location_kind::function, funcname);
+ item *i = new item (kind::function, funcname);
m_name_to_item_map.put (funcname, i);
return i;
}
/* Run all of the selftests within this file. */
void
-selftest_logical_location_cc_tests ()
+diagnostics_selftest_logical_locations_cc_tests ()
{
test_logical_location_manager mgr;
ASSERT_FALSE (mgr.logical_location_from_funcname (nullptr));
- logical_location loc_foo = mgr.logical_location_from_funcname ("foo");
- logical_location loc_bar = mgr.logical_location_from_funcname ("bar");
+ key loc_foo = mgr.logical_location_from_funcname ("foo");
+ key loc_bar = mgr.logical_location_from_funcname ("bar");
ASSERT_NE (loc_foo, loc_bar);
-/* Concrete subclass of logical_location for use in selftests.
+/* Concrete subclass of logical_locations::manager for use in selftests.
Copyright (C) 2024-2025 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-#ifndef GCC_SELFTEST_LOGICAL_LOCATION_H
-#define GCC_SELFTEST_LOGICAL_LOCATION_H
+#ifndef GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H
+#define GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
/* The selftest code should entirely disappear in a production
configuration, hence we guard all of it with #if CHECKING_P. */
namespace selftest {
-/* Concrete subclass of logical_location_manager for use in selftests. */
+/* Concrete subclass of logical_locations::manager for use in selftests. */
-class test_logical_location_manager : public logical_location_manager
+class test_logical_location_manager
+ : public diagnostics::logical_locations::manager
{
public:
+ using key = diagnostics::logical_locations::key;
+ using kind = diagnostics::logical_locations::kind;
+
~test_logical_location_manager ();
const char *get_short_name (key) const final override;
const char *get_name_with_scope (key) const final override;
const char *get_internal_name (key) const final override;
- enum logical_location_kind get_kind (key) const final override;
+ kind get_kind (key) const final override;
label_text get_name_for_path_output (key) const final override;
key get_parent (key) const final override
{
return key ();
}
- logical_location
+ key
logical_location_from_funcname (const char *funcname);
private:
struct item
{
- item (enum logical_location_kind kind,
+ item (kind kind_,
const char *name)
- : m_kind (kind),
+ : m_kind (kind_),
m_name (name)
{
}
- enum logical_location_kind m_kind;
+ kind m_kind;
const char *m_name;
};
const item *
item_from_funcname (const char *funcname);
- static const item *item_from_key (logical_location k)
+ static const item *item_from_key (key k)
{
return k.cast_to<const item *> ();
}
#endif /* #if CHECKING_P */
-#endif /* GCC_SELFTEST_LOGICAL_LOCATION_H. */
+#endif /* GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H. */
#include "xml-printer.h"
#include "intl.h"
+using namespace diagnostics;
using namespace diagnostics::state_graphs;
static int
-get_depth (const diagnostics::digraphs::node &n)
+get_depth (const digraphs::node &n)
{
int deepest_child = 0;
for (size_t i = 0; i < n.get_num_children (); ++i)
{
public:
state_diagram (const diagnostics::digraphs::digraph &input_state_graph,
- const logical_location_manager &logical_loc_mgr)
+ const logical_locations::manager &logical_loc_mgr)
: m_logical_loc_mgr (logical_loc_mgr)
{
// "node [shape=plaintext]\n"
}
private:
- const logical_location_manager &m_logical_loc_mgr;
+ const logical_locations::manager &m_logical_loc_mgr;
/* All nodes involved in edges (and thus will need a port). */
- std::set<diagnostics::digraphs::node *> m_src_nodes;
- std::set<diagnostics::digraphs::node *> m_dst_nodes;
+ std::set<digraphs::node *> m_src_nodes;
+ std::set<digraphs::node *> m_dst_nodes;
- std::map<diagnostics::digraphs::node *, dot::node_id> m_src_node_to_port_id;
- std::map<diagnostics::digraphs::node *, dot::node_id> m_dst_node_to_port_id;
+ std::map<digraphs::node *, dot::node_id> m_src_node_to_port_id;
+ std::map<digraphs::node *, dot::node_id> m_dst_node_to_port_id;
};
std::unique_ptr<dot::graph>
-diagnostics::state_graphs::
-make_dot_graph (const diagnostics::digraphs::digraph &state_graph,
- const logical_location_manager &logical_loc_mgr)
+state_graphs::
+make_dot_graph (const digraphs::digraph &state_graph,
+ const logical_locations::manager &logical_loc_mgr)
{
return std::make_unique<state_diagram> (state_graph, logical_loc_mgr);
}
#define GCC_DIAGNOSTICS_STATE_GRAPHS_H
#include "diagnostics/digraphs.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
/* diagnostics::digraphs provides support for directed graphs.
set_node_kind (enum node_kind);
// For node_kind::stack_frame, this will be the function
- logical_location
+ logical_locations::key
get_logical_loc () const
{
return m_node.get_logical_loc ();
extern std::unique_ptr<dot::graph>
make_dot_graph (const diagnostics::digraphs::digraph &state_graph,
- const logical_location_manager &logical_loc_mgr);
+ const logical_locations::manager &logical_loc_mgr);
} // namespace state_graphs
} // namespace diagnostics
#include "diagnostic-output-spec.h"
#include "diagnostics/digraphs.h"
#include "diagnostics/state-graphs.h"
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
#include "edit-context.h"
#include "libgdiagnostics.h"
#include "libgdiagnostics-private.h"
return s;
}
-class impl_logical_location_manager : public logical_location_manager
+class impl_logical_location_manager
+ : public diagnostics::logical_locations::manager
{
public:
+ using key = diagnostics::logical_locations::key;
+ using kind = diagnostics::logical_locations::kind;
+
static const diagnostic_logical_location *
- ptr_from_key (logical_location k)
+ ptr_from_key (key k)
{
return k.cast_to<const diagnostic_logical_location *> ();
}
- static logical_location
+ static key
key_from_ptr (const diagnostic_logical_location *ptr)
{
- return logical_location::from_ptr (ptr);
+ return key::from_ptr (ptr);
}
const char *get_short_name (key k) const final override
return nullptr;
}
- enum logical_location_kind get_kind (key k) const final override
+ kind get_kind (key k) const final override
{
auto loc = ptr_from_key (k);
gcc_assert (loc);
gcc_unreachable ();
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_FUNCTION:
- return logical_location_kind::function;
+ return kind::function;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_MEMBER:
- return logical_location_kind::member;
+ return kind::member;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_MODULE:
- return logical_location_kind::module_;
+ return kind::module_;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_NAMESPACE:
- return logical_location_kind::namespace_;
+ return kind::namespace_;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_TYPE:
- return logical_location_kind::type;
+ return kind::type;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_RETURN_TYPE:
- return logical_location_kind::return_type;
+ return kind::return_type;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PARAMETER:
- return logical_location_kind::parameter;
+ return kind::parameter;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_VARIABLE:
- return logical_location_kind::variable;
+ return kind::variable;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ELEMENT:
- return logical_location_kind::element;
+ return kind::element;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ATTRIBUTE:
- return logical_location_kind::attribute;
+ return kind::attribute;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_TEXT:
- return logical_location_kind::text;
+ return kind::text;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_COMMENT:
- return logical_location_kind::comment;
+ return kind::comment;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PROCESSING_INSTRUCTION:
- return logical_location_kind::processing_instruction;
+ return kind::processing_instruction;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_DTD:
- return logical_location_kind::dtd;
+ return kind::dtd;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_DECLARATION:
- return logical_location_kind::declaration;
+ return kind::declaration;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_OBJECT:
- return logical_location_kind::object;
+ return kind::object;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ARRAY:
- return logical_location_kind::array;
+ return kind::array;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PROPERTY:
- return logical_location_kind::property;
+ return kind::property;
case DIAGNOSTIC_LOGICAL_LOCATION_KIND_VALUE:
- return logical_location_kind::value;
+ return kind::value;
}
}
const client_version_info *get_any_version_info () const final override;
- const logical_location_manager *
+ const diagnostics::logical_locations::manager *
get_logical_location_manager () const final override
{
return &m_logical_location_manager;
}
- logical_location get_current_logical_location () const final override;
+ diagnostics::logical_locations::key
+ get_current_logical_location () const final override;
const char * maybe_get_sarif_source_language (const char *filename)
const final override;
line_maps *get_line_table () { return &m_line_table; }
diagnostic_context &get_dc () { return m_dc; }
- const logical_location_manager &
+ const diagnostics::logical_locations::manager &
get_logical_location_manager () const
{
auto mgr = m_dc.get_logical_location_manager ();
}
}
- logical_location get_logical_location () const final override
+ diagnostics::logical_locations::key
+ get_logical_location () const final override
{
return impl_logical_location_manager::key_from_ptr (m_logical_loc);
}
same_function_p (int event_idx_a,
int event_idx_b) const final override
{
+ using logical_location = diagnostics::logical_locations::key;
logical_location logical_loc_a
= m_events[event_idx_a]->get_logical_location ();
- logical_location logical_loc_b
+ logical_location logical_loc_b
= m_events[event_idx_b]->get_logical_location ();
/* Pointer equality, as we uniqify logical location instances. */
return m_mgr.get_client_version_info ();
}
-logical_location
+diagnostics::logical_locations::key
impl_diagnostic_client_data_hooks::get_current_logical_location () const
{
gcc_assert (m_mgr.get_current_diag ());
add_entry (callee_name, caller_stack_depth + 1, thread_id);
}
-logical_location
+diagnostics::logical_locations::key
test_diagnostic_path::logical_location_from_funcname (const char *funcname)
{
return m_test_logical_loc_mgr.logical_location_from_funcname (funcname);
#define GCC_SELFTEST_DIAGNOSTIC_PATH_H
#include "diagnostic-path.h"
-#include "selftest-logical-location.h"
+#include "diagnostics/selftest-logical-locations.h"
/* The selftest code should entirely disappear in a production
configuration, hence we guard all of it with #if CHECKING_P. */
class test_diagnostic_event : public diagnostic_event
{
public:
+ using logical_location = diagnostics::logical_locations::key;
+
test_diagnostic_event (location_t loc,
logical_location logical_loc,
int depth,
diagnostic_thread_id_t thread_id = 0);
private:
- logical_location
+ diagnostics::logical_locations::key
logical_location_from_funcname (const char *funcname);
test_logical_location_manager m_test_logical_loc_mgr;
digraph_cc_tests ();
tristate_cc_tests ();
ipa_modref_tree_cc_tests ();
- selftest_logical_location_cc_tests ();
+ diagnostics_selftest_logical_locations_cc_tests ();
/* Higher-level tests, or for components that other selftests don't
rely on. */
extern void diagnostic_path_output_cc_tests ();
extern void diagnostic_show_locus_cc_tests ();
extern void diagnostics_digraphs_cc_tests ();
+extern void diagnostics_selftest_logical_locations_cc_tests ();
extern void diagnostics_state_graphs_cc_tests ();
extern void digraph_cc_tests ();
extern void dumpfile_cc_tests ();
extern void rtl_tests_cc_tests ();
extern void sbitmap_cc_tests ();
extern void selftest_cc_tests ();
-extern void selftest_logical_location_cc_tests ();
extern void simple_diagnostic_path_cc_tests ();
extern void simplify_rtx_cc_tests ();
extern void spellcheck_cc_tests ();
location_t get_location () const final override { return m_loc; }
int get_stack_depth () const final override { return m_depth; }
void print_desc (pretty_printer &pp) const final override;
- logical_location get_logical_location () const final override
+ diagnostics::logical_locations::key
+ get_logical_location () const final override
{
return tree_logical_location_manager::key_from_tree (m_fndecl);
}
private:
location_t m_loc;
tree m_fndecl;
- logical_location m_logical_loc;
+ diagnostics::logical_locations::key m_logical_loc;
int m_depth;
char *m_desc; // has been i18n-ed and formatted
bool m_connected_to_next_event;
return &m_version_info;
}
- const logical_location_manager *get_logical_location_manager () const final override
+ const diagnostics::logical_locations::manager *
+ get_logical_location_manager () const final override
{
return &m_logical_location_manager;
}
- logical_location_manager::key get_current_logical_location () const final override
+ diagnostics::logical_locations::key
+ get_current_logical_location () const final override
{
return m_logical_location_manager.key_from_tree (current_function_decl);
}
#include "langhooks.h"
#include "intl.h"
+using namespace diagnostics::logical_locations;
+
static void
assert_valid_tree (const_tree node)
{
gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL);
}
-/* class tree_logical_location_manager : public logical_location_manager. */
+/* class tree_logical_location_manager
+ : public diagnostics::logical_locations::manager. */
const char *
tree_logical_location_manager::get_short_name (key k) const
return NULL;
}
-enum logical_location_kind
+enum kind
tree_logical_location_manager::get_kind (key k) const
{
tree node = tree_from_key (k);
switch (TREE_CODE (node))
{
default:
- return logical_location_kind::unknown;
+ return kind::unknown;
case FUNCTION_DECL:
- return logical_location_kind::function;
+ return kind::function;
case PARM_DECL:
- return logical_location_kind::parameter;
+ return kind::parameter;
case VAR_DECL:
- return logical_location_kind::variable;
+ return kind::variable;
case NAMESPACE_DECL:
- return logical_location_kind::namespace_;
+ return kind::namespace_;
case RECORD_TYPE:
- return logical_location_kind::type;
+ return kind::type;
}
}
return label_text ();
}
-logical_location
+key
tree_logical_location_manager::get_parent (key k) const
{
tree node = tree_from_key (k);
if (DECL_P (node))
{
if (!DECL_CONTEXT (node))
- return logical_location ();
+ return key ();
if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
- return logical_location ();
+ return key ();
return key_from_tree (DECL_CONTEXT (node));
}
else if (TYPE_P (node))
{
if (!TYPE_CONTEXT (node))
- return logical_location ();
+ return key ();
return key_from_tree (TYPE_CONTEXT (node));
}
- return logical_location ();
+ return key ();
}
#ifndef GCC_TREE_LOGICAL_LOCATION_H
#define GCC_TREE_LOGICAL_LOCATION_H
-#include "logical-location.h"
+#include "diagnostics/logical-locations.h"
-/* A subclass of logical_location_manager in which the keys are
- "tree".
+/* A subclass of diagnostics::logical_locations::manager in which the
+ keys are "tree".
Note that there is no integration with the garbage collector,
- and so logical_location instances can only be short-lived. */
-class tree_logical_location_manager : public logical_location_manager
+ and so key instances can only be short-lived. */
+class tree_logical_location_manager
+ : public diagnostics::logical_locations::manager
{
public:
+ using key = diagnostics::logical_locations::key;
+ using kind = diagnostics::logical_locations::kind;
+
const char *get_short_name (key) const final override;
const char *get_name_with_scope (key) const final override;
const char *get_internal_name (key) const final override;
- enum logical_location_kind get_kind (key) const final override;
+ kind get_kind (key) const final override;
label_text get_name_for_path_output (key) const final override;
key get_parent (key) const final override;
- static tree tree_from_key (logical_location k)
+ static tree tree_from_key (key k)
{
return const_cast<tree> (k.cast_to<const_tree> ());
}
- static logical_location key_from_tree (tree node)
+ static key key_from_tree (tree node)
{
- return logical_location::from_ptr (node);
+ return key::from_ptr (node);
}
};