forked from ruslo/hunter
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * First try to compile * use hunterized package * Working package version * Cleanup hunter cmake and add pr in doc * Fix cppast version * Change repo url * Fix version number
- Loading branch information
Showing
6 changed files
with
145 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# !!! DO NOT PLACE HEADER GUARDS HERE !!! | ||
|
||
include(hunter_add_version) | ||
include(hunter_cacheable) | ||
include(hunter_download) | ||
include(hunter_pick_scheme) | ||
|
||
hunter_add_version( | ||
PACKAGE_NAME | ||
cppast | ||
VERSION | ||
0.0.0-b155d6a-p0 | ||
URL | ||
"https://github.com/cpp-pm/cppast/archive/v0.0.0-b155d6a-p0.tar.gz" | ||
SHA1 | ||
aaa370f185fb5d14398622863a35b5ebe96ab4a2 | ||
) | ||
|
||
hunter_pick_scheme(DEFAULT url_sha1_cmake) | ||
hunter_cacheable(cppast) | ||
hunter_download( | ||
PACKAGE_NAME cppast | ||
PACKAGE_INTERNAL_DEPS_ID "1" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. spelling:: | ||
|
||
cppast | ||
|
||
.. index:: | ||
single: unsorted ; cppast | ||
|
||
.. _pkg.cppast: | ||
|
||
cppast | ||
====== | ||
|
||
- `Official <https://github.com/foonathan/cppast>`__ | ||
- `Hunterized <https://github.com/cpp-pm/cppast>` | ||
- `Example <https://github.com/cpp-pm/hunter/blob/master/examples/cppast/CMakeLists.txt>`__ | ||
- Added by `Joerg-Christian Boehme <https://github.com/Bjoe>`__ (`pr-110 <https://github.com/cpp-pm/hunter/pull/110>`__) | ||
|
||
.. literalinclude:: /../examples/cppast/CMakeLists.txt | ||
:language: cmake | ||
:start-after: # DOCUMENTATION_START { | ||
:end-before: # DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2016-2018, Ruslan Baratov | ||
# All rights reserved. | ||
|
||
cmake_minimum_required(VERSION 3.2) | ||
|
||
# Emulate HunterGate: | ||
# * https://github.com/hunter-packages/gate | ||
include("../common.cmake") | ||
|
||
project(cppast) | ||
|
||
# DOCUMENTATION_START { | ||
hunter_add_package(cppast) | ||
find_package(cppast CONFIG REQUIRED) | ||
|
||
add_executable(boo boo.cpp) | ||
target_link_libraries(boo PUBLIC cppast::cppast) | ||
# DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (C) 2017-2019 Jonathan Müller <jonathanmueller.dev@gmail.com> | ||
// This file is subject to the license terms in the LICENSE file | ||
// found in the top-level directory of this distribution. | ||
|
||
/// \file | ||
/// This is a very primitive version of the cppast tool. | ||
/// | ||
/// Given an input file it will print the AST. | ||
|
||
#include <cppast/visitor.hpp> // visit() | ||
|
||
#include <iostream> | ||
|
||
#include <cppast/libclang_parser.hpp> | ||
|
||
// reads the database directory from the command line argument | ||
// parses all files in that directory | ||
// and invokes the callback for each of them | ||
template <typename Callback> | ||
int example_main(int argc, char* argv[], const cppast::cpp_entity_index& index, Callback cb) try | ||
{ | ||
if (argc != 2) | ||
{ | ||
std::cerr << "usage: " << argv[0] << " <compile-commands-json-dir>\n"; | ||
return 1; | ||
} | ||
else | ||
{ | ||
cppast::libclang_compilation_database database(argv[1]); // the compilation database | ||
|
||
// simple_file_parser allows parsing multiple files and stores the results for us | ||
cppast::simple_file_parser<cppast::libclang_parser> parser(type_safe::ref(index)); | ||
try | ||
{ | ||
cppast::parse_database(parser, database); // parse all files in the database | ||
} | ||
catch (cppast::libclang_error& ex) | ||
{ | ||
std::cerr << "fatal libclang error: " << ex.what() << '\n'; | ||
return 1; | ||
} | ||
|
||
if (parser.error()) | ||
// a non-fatal parse error | ||
// error has been logged to stderr | ||
return 1; | ||
|
||
for (auto& file : parser.files()) | ||
cb(file); | ||
} | ||
|
||
return 0; | ||
} | ||
catch (std::exception& ex) | ||
{ | ||
std::cerr << ex.what() << '\n'; | ||
return 1; | ||
} | ||
|
||
void print_ast(const cppast::cpp_file& file) | ||
{ | ||
std::string prefix; | ||
// visit each entity in the file | ||
cppast::visit(file, [&](const cppast::cpp_entity& e, cppast::visitor_info info) { | ||
if (info.event == cppast::visitor_info::container_entity_exit) // exiting an old container | ||
prefix.pop_back(); | ||
else if (info.event == cppast::visitor_info::container_entity_enter) | ||
// entering a new container | ||
{ | ||
std::cout << prefix << "'" << e.name() << "' - " << cppast::to_string(e.kind()) << '\n'; | ||
prefix += "\t"; | ||
} | ||
else // if (info.event == cppast::visitor_info::leaf_entity) // a non-container entity | ||
std::cout << prefix << "'" << e.name() << "' - " << cppast::to_string(e.kind()) << '\n'; | ||
}); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
return example_main(argc, argv, {}, &print_ast); | ||
} |