40 {
"limiter",
'l',
RequiredArgument,
"Limits the number of results shown to the user. By default, all results are shown."},
41 {
"pattern",
'p',
RequiredArgument,
"Defines a pattern that function names must match to be included in the results. A function is considered a match if the pattern is a substring of the function's concatenated file path and name (e.g., `path/to/file.c:function_name`)."},
42 {
"both-match",
'b',
NoArgument,
"Enable both-pattern matching. By default, the pattern only needs to match one function."},
43 {
"sort",
's',
NoArgument,
"Sort results by number of duplicated lines. By default, results are sorted by the similarity metric."},
44 {
"cluster",
'c',
NoArgument,
"Print results with cluster relationships from the similarity table."},
45 {
"verbose", 0,
NoArgument,
"Enable verbose output"},
46 {
"template",
't',
RequiredArgument,
"Output format template for each result entry. Run --template-help to see available variables and an example."},
47 {
"template-help", 0,
NoArgument,
"Show available template variables for --template."},
51 "Explore duplicated functions detected in the project.")
67 static constexpr const
char* TEMPLATE_PROCESSED_RESULTS =
68 "Functions find: {path_a}
"
70 ", TOTAL NUMBER LINES IN FUNCTIONS: {duplicated_lines}
";
71 static constexpr const char* TEMPLATE_PROCESSED_RESULTS_CLUSTERS =
73 ", TOTAL NUMBER LINES IN FUNCTION: {duplicated_lines}
";
74 static constexpr const char* TEMPLATE_INITIAL_TEXT =
75 "It was found a total of {found:bold}
"
76 "pair of duplicate functions in the codebase. Which the first
"
77 "{show:bold} can be found below.
";
79 int INITIAL_PROCESSED_RESULTS = 0; ///< Initial counter for processed results
81 Similarity_Table* similarity_table; ///< Source of similarity data
82 int limit_on_results; ///< Maximum number of results to show
83 std::string pattern_to_match; ///< Pattern to filter results
84 bool both_path_need_to_match_pattern; ///< Whether both paths must match pattern
85 bool sorted_by_number_of_duplicated_code; ///< Whether to sort by line count
86 bool use_clusters; ///< Whether clusters be printed
87 int processed_results = INITIAL_PROCESSED_RESULTS; ///< Counter for processed results
88 bool mode_verbose = false; ///< Detailed execution information
89 std::string template_processed_results_output = TEMPLATE_PROCESSED_RESULTS;
96 int find_number_pairs_show(int number_pair_found) const;
104 bool match_pattern(const Function& function1, const Function& function2) const;
111 SimilarityExplorerEntry process_similar_path_pair(const Path& path1, const Path& path2);
118 int find_number_pair_found(const std::vector<SimilarPair>& similar_path_pairs) const;
124 std::vector<SimilarPair> build_similar_path_pairs();
129 static void print_template_variables();
134 void explorer_clusters();
const CliOption * options() const final
Represents a function extracted from a codebase.
Duplicate function explorer and analyzer.
static constexpr int UNLIMITED_RESULTS
Constant for unlimited results display.
static constexpr const char * EMPTY_PATTERN
Constant for empty search pattern.
static constexpr CliOption options_[]
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
COMMAND_DESCRIPTION("Explore duplicated functions detected in the project.") explicit SimilarityExplorer(Similarity_Table *_similarity_table)
Constructs explorer with configuration.
bool run(const ParsedOptions &options) override
Handles code exploration command.
Represents a similarity graph between functions (paths).
Function representation for a codebase.
#define OPTION_END
This marks the end of a long array of options.
Logical path abstraction for source code elements.
Similarity relationships storage and analysis.