Add preprocessor

The parser now parses macros and inclusion directives.
This commit is contained in:
Jonathan Müller 2017-02-12 21:43:14 +01:00
commit 0684be5788
6 changed files with 519 additions and 11 deletions

View file

@ -9,12 +9,31 @@
namespace cppast
{
class libclang_compile_config;
namespace detail
{
struct libclang_compile_config_access
{
static const std::string& clang_binary(const libclang_compile_config& config);
static const std::vector<std::string>& flags(const libclang_compile_config& config);
};
} // namespace detail
/// Compilation config for the [cppast::libclang_parser]().
class libclang_compile_config final : public compile_config
{
public:
libclang_compile_config();
/// \effects Sets the path to the location of the `clang++` binary.
/// \notes It will be used for preprocessing.
void set_clang_binary(std::string binary)
{
clang_binary_ = std::move(binary);
}
private:
void do_set_flags(cpp_standard standard, type_safe::flag_set<compile_flag> flags) override;
@ -23,6 +42,15 @@ namespace cppast
void do_add_macro_definition(std::string name, std::string definition) override;
void do_remove_macro_definition(std::string name) override;
const char* do_get_name() const noexcept override
{
return "libclang";
}
std::string clang_binary_;
friend detail::libclang_compile_config_access;
};
/// A parser that uses libclang.
@ -33,7 +61,7 @@ namespace cppast
~libclang_parser() noexcept override;
private:
std::unique_ptr<cpp_file> do_parse(const cpp_entity_index& idx, const std::string& path,
std::unique_ptr<cpp_file> do_parse(const cpp_entity_index& idx, std::string path,
const compile_config& config) const override;
struct impl;