Logical locations

A “logical” location is a location expressed in terms of construct in a programming language, such as within function 'foo' (as opposed to a “physical” location, which refers to a specific file, and line(s) and/or column(s))

Creating location information

type diagnostic_logical_location

A diagnostic_logical_location is an opaque type describing a “logical” source 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)

Create a diagnostic_logical_location.

diag_mgr must be non-NULL.

kind describes the kind of logical location:

enum diagnostic_logical_location_kind_t

This roughly corresponds to the kind property in SARIF v2.1.0 (§3.33.7).

DIAGNOSTIC_LOGICAL_LOCATION_KIND_FUNCTION
DIAGNOSTIC_LOGICAL_LOCATION_KIND_MEMBER
DIAGNOSTIC_LOGICAL_LOCATION_KIND_MODULE
DIAGNOSTIC_LOGICAL_LOCATION_KIND_NAMESPACE
DIAGNOSTIC_LOGICAL_LOCATION_KIND_TYPE
DIAGNOSTIC_LOGICAL_LOCATION_KIND_RETURN_TYPE
DIAGNOSTIC_LOGICAL_LOCATION_KIND_PARAMETER
DIAGNOSTIC_LOGICAL_LOCATION_KIND_VARIABLE

parent can be NULL; if non-NULL it can be used to express tree-like nesting of logical locations, such as in:

namespace foo { namespace bar { class baz { baz (); }; } }

where a diagnostic within baz’s constructor could be reported as being within foo::bar::baz::baz where the logical locations are two namespaces, a type, and a member, respectively.

short_name can be NULL, or else a string suitable for use by the SARIF logicalLocation name property (SARIF v2.1.0 §3.33.4).

fully_qualified_name can be NULL or else a string suitable for use by the SARIF logicalLocation fullyQualifiedName property (SARIF v2.1.0 §3.33.5).

decorated_name can be NULL or else a string suitable for use by the SARIF logicalLocation decoratedName property (SARIF v2.1.0 §3.33.6).

void diagnostic_manager_debug_dump_logical_location(const diagnostic_manager *diag_mgr, const diagnostic_logical_location *loc, FILE *out)

Write a representation of file to out, for debugging. Both diag_mgr and out must be non-NULL. file may be NULL.

TODO: example of output

Associating diagnostics with locations

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

Set the logical location of diag.

diag must be non-NULL; logical_loc can be NULL.