28 clang::SourceManager & ,
37 clang::SourceManager &sm,
44#if LLVM_VERSION_MAJOR >= 19
46 clang::SourceLocation hash_loc,
const clang::Token & ,
47 clang::StringRef file_name,
bool is_angled,
48 clang::CharSourceRange , clang::OptionalFileEntryRef file,
49 clang::StringRef , clang::StringRef relative_path,
50 const clang::Module * ,
bool ,
51 clang::SrcMgr::CharacteristicKind file_type)
52#elif LLVM_VERSION_MAJOR >= 16
54 clang::SourceLocation hash_loc,
const clang::Token & ,
55 clang::StringRef file_name,
bool is_angled,
56 clang::CharSourceRange , clang::OptionalFileEntryRef file,
57 clang::StringRef , clang::StringRef relative_path,
58 const clang::Module * ,
59 clang::SrcMgr::CharacteristicKind file_type)
60#elif LLVM_VERSION_MAJOR > 14
62 clang::SourceLocation hash_loc,
const clang::Token & ,
63 clang::StringRef file_name,
bool is_angled,
64 clang::CharSourceRange ,
65 clang::Optional<clang::FileEntryRef> file, clang::StringRef ,
66 clang::StringRef relative_path,
const clang::Module * ,
67 clang::SrcMgr::CharacteristicKind file_type)
70 clang::SourceLocation hash_loc,
const clang::Token & ,
71 clang::StringRef file_name,
bool is_angled,
72 clang::CharSourceRange ,
const clang::FileEntry *file,
73 clang::StringRef , clang::StringRef relative_path,
74 const clang::Module * ,
75 clang::SrcMgr::CharacteristicKind file_type)
84 std::filesystem::path{source_manager().getFilename(hash_loc).str()};
86 std::string file_name_str = file_name.str();
87 current_file = std::filesystem::absolute(current_file);
88 current_file = current_file.lexically_normal();
89 const auto current_dir = current_file.parent_path();
91 auto current_file_id = process_source_file(current_file);
95 assert(
diagram().get(current_file_id.value()));
98 std::filesystem::path real_include_path{
99#if LLVM_VERSION_MAJOR > 14
100 file->getFileEntry().tryGetRealPathName().str()
102 file->tryGetRealPathName().str()
106 if (real_include_path.empty()) {
108#if LLVM_VERSION_MAJOR > 14
109 if (!file.has_value())
111 auto include_path_parent =
112 std::filesystem::path(file->getDir().getName().str());
113 const std::string include_file_dir{file->getDir().getName()};
117 auto include_path_parent =
118 std::filesystem::path(file->getDir()->getName().str());
119 const std::string include_file_dir{file->getDir()->getName()};
122 const std::string include_name{file->getName().str()};
123 const auto include_path_pre_normalization =
124 std::filesystem::path{include_file_dir} / include_name;
126 real_include_path = include_path_pre_normalization.lexically_normal();
129 real_include_path = real_include_path.lexically_normal();
134 LOG_DBG(
"Processing include directive {} [{}] in file {}", file_name_str,
135 real_include_path.string(), current_file.string());
137 if (
diagram().should_include(source_file{real_include_path})) {
138 LOG_DBG(
"Processing internal header: {}", real_include_path.string());
139 process_internal_header(real_include_path,
140 file_type != clang::SrcMgr::CharacteristicKind::C_User,
141 current_file_id.value());
143 else if (
config().generate_system_headers() && is_angled) {
144 process_external_system_header(
145 relative_path.str(), current_file_id.value());
148 LOG_DBG(
"Skipping include directive to file {}",
149 real_include_path.string());
154 const std::filesystem::path &include_path,
bool is_system,
155 const eid_t current_file_id)
158 auto relative_include_path =
159 std::filesystem::relative(include_path,
config().root_directory());
165 if (!
diagram().get_element(diagram_path.to_string()).has_value()) {
167 diagram_path.to_string()));
173 include_file.set_file(
174 std::filesystem::absolute(include_path).lexically_normal().
string());
175 include_file.set_line(0);
176 include_file.set_system_header(is_system);
180 const auto relationship_type = is_system
184 if (
diagram().get(current_file_id)) {
186 .
get(current_file_id)
194 const std::filesystem::path &include_path,
const eid_t current_file_id)
196 const auto file_name = include_path.filename();
197 const auto file_name_str = file_name.string();
199 auto f = std::make_unique<common::model::source_file>();
200 f->set_name(include_path.string());
203 f->set_system_header(
true);
205 const auto f_id = f->id();
209 if (
diagram().get(current_file_id)) {
211 .
get(current_file_id)
221 const std::filesystem::path &file)
227 auto file_path = std::filesystem::path{file};
231 if (file_path.is_relative()) {
235 file_path = file_path.lexically_normal();
237 if (
diagram().should_include(source_file{file_path})) {
238 LOG_DBG(
"Processing source file {}", file.string());
241 auto relative_file_path =
242 std::filesystem::relative(file_path,
config().root_directory());
244 [[maybe_unused]]
const auto relative_file_path_str =
245 relative_file_path.string();
249 auto diagram_path = source_file{relative_file_path}.full_path();
250 if (!
diagram().get_element(diagram_path).has_value()) {
252 std::make_unique<source_file>(relative_file_path));
257 const std::string implementation_suffix_prefix{
".c"};
258 if (file_path.has_extension() &&
260 implementation_suffix_prefix) ||
261 file_path.extension() ==
".m")) {
262 source_file.set_type(source_file_t::kImplementation);
265 source_file.set_type(source_file_t::kHeader);
267 source_file.set_file(std::filesystem::absolute(file.string())
273 relative(source_file.file(),
config().root_directory())
277 source_file.set_file_relative(
"");
280 source_file.set_line(0);
282 return source_file.id();