ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
function.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <limits>
15#include <string>
16#include <vector>
17
18#include <arkanjo/base/path.hpp>
19
20static constexpr uint32_t INVALID_LINE = std::numeric_limits<uint32_t>::max();
21
23 uint32_t declaration{INVALID_LINE};
24 uint32_t begin{INVALID_LINE};
25 uint32_t end{INVALID_LINE};
26
27 [[nodiscard]]
28 constexpr uint32_t size() const noexcept {
29 if (declaration == INVALID_LINE || end == INVALID_LINE)
30 return 0;
31
32 if (end < declaration)
33 return 0;
34
35 return end - declaration + 1;
36 }
37};
38
45class Function {
46 friend class FunctionLoader;
47
48 private:
49 Path path_;
50 std::string name_;
51
52 std::vector<std::string> content_;
53 std::vector<std::string> header_;
54
55 FunctionLocation location_;
56
57 public:
58 Function() = default;
59
64 explicit Function(const Path& _path);
65
70 const Path& path() const;
71
76 const std::string& name() const;
77
83 const FunctionLocation& scope_location() const;
84
89 const std::vector<std::string>& header() const;
90
95 std::vector<std::string> build_all_content() const;
96
103 bool contains_given_pattern(const std::string& pattern) const;
104};
Represents a function extracted from a codebase.
Definition: function.hpp:45
bool contains_given_pattern(const std::string &pattern) const
Checks whether the function contains a pattern.
Definition: function.cpp:41
Function()=default
const std::vector< std::string > & header() const
Gets the function's header content.
Definition: function.cpp:21
const Path & path() const
Gets the function path information.
Definition: function.cpp:5
std::vector< std::string > build_all_content() const
Builds combined content of header and source.
Definition: function.cpp:25
const std::string & name() const
Gets the function name.
Definition: function.cpp:9
const FunctionLocation & scope_location() const
Gets the function location inside the source file.
Definition: function.cpp:17
Represents a logical path to a function in the codebase.
Definition: path.hpp:26
Logical path abstraction for source code elements.
uint32_t end
Line number where function ends.
Definition: function.hpp:25
uint32_t declaration
Line number of function declaration.
Definition: function.hpp:23
uint32_t begin
Line number where function starts.
Definition: function.hpp:24
constexpr uint32_t size() const noexcept
Definition: function.hpp:28