Skip to content

Commit

Permalink
libclang
Browse files Browse the repository at this point in the history
  • Loading branch information
an-tao committed Aug 15, 2021
1 parent 6d576c0 commit eda4363
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions drogon_ctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ else(WIN32)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dg_ctl"
DESTINATION ${INSTALL_BIN_DIR})
endif(WIN32)
find_package(Clang REQUIRED)
include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)

# Link against LLVM libraries
target_link_libraries(drogon_ctl PRIVATE ${llvm_libs})

set(ctl_targets _drogon_ctl drogon_ctl)
set_property(TARGET ${ctl_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD})
set_property(TARGET ${ctl_targets} PROPERTY CXX_STANDARD_REQUIRED ON)
Expand Down
17 changes: 14 additions & 3 deletions drogon_ctl/create_swagger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#endif
#include <fstream>

#include <clang-c/Index.h>

using namespace drogon_ctl;

static void forEachControllerHeaderIn(
Expand Down Expand Up @@ -78,11 +80,20 @@ static void forEachControllerHeaderIn(
static void parseControllerHeader(const std::string &headerFile,
Json::Value &docs)
{
std::ifstream infile(headerFile);

for (std::string buffer; std::getline(infile, buffer);)
CXIndex index = clang_createIndex(0, 0);
CXTranslationUnit unit = clang_parseTranslationUnit(
index,
headerFile.c_str(), nullptr, 0,
nullptr, 0,
CXTranslationUnit_None);
if (unit == nullptr)
{
std::cerr << "Unable to parse translation unit. Quitting." << std::endl;
exit(-1);
}

clang_disposeTranslationUnit(unit);
clang_disposeIndex(index);
}
static std::string makeSwaggerDocument(const Json::Value &config)
{
Expand Down

0 comments on commit eda4363

Please sign in to comment.