Skip to content

Commit

Permalink
[feat] add icon and analysis enabled logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shenjunjiekoda committed Jul 26, 2024
1 parent 1c40d05 commit 2e85539
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<img src="doc/icon.png" alt="logo" width="20%" />

# Knight

Knight is a static analysis tool for c/c++ programs written in C++20.
Expand Down
Binary file added doc/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion include/dfa/analysis_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class AnalysisManager {
internal::VisitStmtKind kind);
/// @}

private:
/// \brief check analysis is enabled or not
void add_required_analysis(AnalysisID id);

Expand Down
8 changes: 5 additions & 3 deletions include/tooling/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ class CheckerManager;
class KnightFactory {
public:
using Analysis = dfa::AnalysisBase;
using UniqueAnalysisRef = std::unique_ptr< Analysis >;
using AnalysisRef = std::unique_ptr< Analysis >;
using AnalysisRefs = std::vector< AnalysisRef >;

using Checker = dfa::CheckerBase;
using CheckerRef = std::unique_ptr< Checker >;
using UniqueCheckerRef = std::unique_ptr< Checker >;
using CheckerRef = Checker*;
using CheckerRefs = std::vector< CheckerRef >;

using AnalysisRegistryFn = std::function< AnalysisRef() >;
using CheckerRegistryFn = std::function< CheckerRef() >;
using AnalysisRegistryFn = std::function< UniqueAnalysisRef() >;
using CheckerRegistryFn = std::function< UniqueCheckerRef() >;

using AnalysisRegistryFnMap =
llvm::DenseMap< std::pair< dfa::AnalysisID, llvm::StringRef >,
Expand Down
3 changes: 2 additions & 1 deletion src/dfa/checker_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ void CheckerManager::register_checker(CheckerID id) {
}

bool CheckerManager::is_checker_required(CheckerID id) const {
return m_enabled_checkers.count(id) > 0U;
return m_required_checkers.count(id) > 0U;
}

void CheckerManager::enable_checker(
// TODO: add enabling logic for checkers (check filter and required checkers)
std::unique_ptr< CheckerBase > checker) {
auto id = checker->get_id();
m_required_checkers.emplace(id);
m_enabled_checkers.emplace(id, std::move(checker));
}

Expand Down
5 changes: 3 additions & 2 deletions src/tooling/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ KnightFactory::CheckerRefs KnightFactory::create_checkers(
const auto& LO = context->get_lang_options();
for (const auto& [checker, registry] : m_checker_registry) {
if (m_checker_mgr.is_checker_required(checker.first)) {
CheckerRef checker = registry();
checkers.push_back(std::move(checker));
auto checker = registry();
checkers.push_back(checker.get());
m_checker_mgr.enable_checker(std::move(checker));
}
}
return checkers;
Expand Down
11 changes: 9 additions & 2 deletions src/tooling/knight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ std::unique_ptr< clang::ASTConsumer > KnightASTConsumerFactory::
m_ctx.set_current_build_dir(working_dir.get());
}

// TODO: add checkers and analyses register and enabled logic here.

for (const auto& [id, _] : get_enabled_checks()) {
m_checker_manager->register_checker(id);
}
auto checkers = m_factory->create_checkers(&m_ctx);

for (const auto& [id, _] : get_directly_enabled_analyses()) {
m_analysis_manager->register_analysis(id);
}
m_analysis_manager->compute_all_required_analyses_by_dependencies();
auto analyses = m_factory->create_analyses(&m_ctx);

return std::make_unique< KnightASTConsumer >(m_ctx,
*m_analysis_manager,
*m_checker_manager,
Expand Down

0 comments on commit 2e85539

Please sign in to comment.