#pragma once #include #include #include #include #include "nlohmann/json_fwd.hpp" namespace SARIF { struct Message { std::string text; std::vector arguments; std::string to_string() const; }; void from_json(const nlohmann::json &json, Message &message); struct Region { std::size_t start_line; std::size_t end_line; std::size_t start_column; std::size_t end_column; std::string snippet; bool operator<(const Region &other) const noexcept; }; void from_json(const nlohmann::json &json, Region ®ion); struct Location { Message message; boost::filesystem::path artifact_location; Region region; boost::optional context_region; }; void from_json(const nlohmann::json &json, Location &location); struct ThreadFlowLocation { enum class Importance { important, essential, unimportant, }; Importance importance; Location location; }; void from_json(const nlohmann::json &json, ThreadFlowLocation &location); struct ThreadFlow { std::vector locations; }; void from_json(const nlohmann::json &json, ThreadFlow &flow); struct CodeFlow { std::vector thread_flows; }; void from_json(const nlohmann::json &json, CodeFlow &flow); struct Result { enum class Level { none, note, warning, error, }; Level level; Message message; std::vector locations; std::vector code_flows; std::string rule_id; // Custom field std::string help_uri; std::string get_message(const Location &location, bool markdown = false) const; }; std::string to_string(Result::Level level); void from_json(const nlohmann::json &json, Result &result); struct ReportingDescriptor { std::string id; std::string name; std::string help_uri; }; void from_json(const nlohmann::json &json, ReportingDescriptor &descriptor); struct ToolComponent { std::vector rules; }; void from_json(const nlohmann::json &json, ToolComponent &component); struct Tool { ToolComponent driver; }; void from_json(const nlohmann::json &json, Tool &tool); struct Run { std::vector results; Tool tool; }; void from_json(const nlohmann::json &json, Run &run); // According to Static Analysis Results Interchange Format (SARIF) specification version 2.1, // see https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html struct Log { std::vector runs; }; void from_json(const nlohmann::json &json, Log &log); /// Merges the results of all input files. /// Removes duplicate entries (e.g. findings in headers included in multiple files). /// Adds a context region for each location where possible. /// Returns the list of merged results. std::vector merge_files(const boost::filesystem::path &output_file, std::vector &input_files); /// Returns the list of results for the given file. std::vector results_for_file(const boost::filesystem::path &results_file, const boost::filesystem::path &source_file); } // namespace SARIF