28 clang::SourceManager & ,
37 clang::SourceManager &sm,
44#if LLVM_VERSION_MAJOR >= 16
46 clang::SourceLocation hash_loc,
const clang::Token & ,
47 clang::StringRef ,
bool is_angled,
48 clang::CharSourceRange , clang::OptionalFileEntryRef file,
49 clang::StringRef , clang::StringRef relative_path,
50 const clang::Module * ,
51 clang::SrcMgr::CharacteristicKind file_type)
52#elif LLVM_VERSION_MAJOR > 14
54 clang::SourceLocation hash_loc,
const clang::Token & ,
55 clang::StringRef ,
bool is_angled,
56 clang::CharSourceRange ,
57 clang::Optional<clang::FileEntryRef> file, clang::StringRef ,
58 clang::StringRef relative_path,
const clang::Module * ,
59 clang::SrcMgr::CharacteristicKind file_type)
62 clang::SourceLocation hash_loc,
const clang::Token & ,
63 clang::StringRef ,
bool is_angled,
64 clang::CharSourceRange ,
const clang::FileEntry *file,
65 clang::StringRef , clang::StringRef relative_path,
66 const clang::Module * ,
67 clang::SrcMgr::CharacteristicKind file_type)
75 std::filesystem::path{source_manager().getFilename(hash_loc).str()};
76 current_file = std::filesystem::absolute(current_file);
77 current_file = current_file.lexically_normal();
79 auto current_file_id = process_source_file(current_file);
83 assert(
diagram().get(current_file_id.value()));
85#if LLVM_VERSION_MAJOR > 14
86 if (!file.has_value())
88 auto include_path = std::filesystem::path(file->getDir().getName().str());
92 auto include_path = std::filesystem::path(file->getDir()->getName().str());
94 include_path = include_path / file->getName().str();
95 include_path = include_path.lexically_normal();
97 LOG_DBG(
"Processing include directive {} in file {}", include_path.string(),
98 current_file.string());
100 auto relative_include_path =
101 std::filesystem::relative(include_path,
config().root_directory());
103 if (
diagram().should_include(source_file{include_path})) {
104 process_internal_header(include_path,
105 file_type != clang::SrcMgr::CharacteristicKind::C_User,
106 current_file_id.value());
108 else if (
config().generate_system_headers() && is_angled) {
109 process_external_system_header(
110 relative_path.str(), current_file_id.value());
113 LOG_DBG(
"Skipping include directive to file {}", include_path.string());
118 const std::filesystem::path &include_path,
bool is_system,
119 const eid_t current_file_id)
122 auto relative_include_path =
123 std::filesystem::relative(include_path,
config().root_directory());
129 if (!
diagram().get_element(diagram_path.to_string()).has_value()) {
131 diagram_path.to_string()));
137 include_file.set_file(
138 std::filesystem::absolute(include_path).lexically_normal().
string());
139 include_file.set_line(0);
140 include_file.set_system_header(is_system);
144 const auto relationship_type = is_system
148 if (
diagram().get(current_file_id)) {
150 .
get(current_file_id)
158 const std::filesystem::path &include_path,
const eid_t current_file_id)
160 const auto file_name = include_path.filename();
161 const auto file_name_str = file_name.string();
163 auto f = std::make_unique<common::model::source_file>();
164 f->set_name(include_path.string());
167 f->set_system_header(
true);
169 const auto f_id = f->id();
173 if (
diagram().get(current_file_id)) {
175 .
get(current_file_id)
185 const std::filesystem::path &file)
191 auto file_path = std::filesystem::path{file};
195 if (file_path.is_relative()) {
199 file_path = file_path.lexically_normal();
201 if (
diagram().should_include(source_file{file_path})) {
202 LOG_DBG(
"Processing source file {}", file.string());
205 auto relative_file_path =
206 std::filesystem::relative(file_path,
config().root_directory());
208 [[maybe_unused]]
const auto relative_file_path_str =
209 relative_file_path.string();
213 auto diagram_path = source_file{relative_file_path}.full_path();
214 if (!
diagram().get_element(diagram_path).has_value()) {
216 std::make_unique<source_file>(relative_file_path));
221 const std::string implementation_suffix_prefix{
".c"};
222 if (file_path.has_extension() &&
224 file_path.extension().string(), implementation_suffix_prefix)) {
225 source_file.set_type(source_file_t::kImplementation);
228 source_file.set_type(source_file_t::kHeader);
230 source_file.set_file(std::filesystem::absolute(file.string())
236 relative(source_file.file(),
config().root_directory())
240 source_file.set_file_relative(
"");
243 source_file.set_line(0);
245 return source_file.id();