Add preprocessor
The parser now parses macros and inclusion directives.
This commit is contained in:
parent
ac8b81400c
commit
0684be5788
6 changed files with 519 additions and 11 deletions
|
|
@ -56,7 +56,7 @@ namespace cppast
|
|||
{
|
||||
public:
|
||||
/// \effects Sets the given C++ standard and compilation flags.
|
||||
void set_standard(cpp_standard standard, type_safe::flag_set<compile_flag> flags)
|
||||
void set_flags(cpp_standard standard, type_safe::flag_set<compile_flag> flags = {})
|
||||
{
|
||||
do_set_flags(standard, flags);
|
||||
}
|
||||
|
|
@ -79,6 +79,13 @@ namespace cppast
|
|||
do_remove_macro_definition(std::move(name));
|
||||
}
|
||||
|
||||
/// \returns A unique name of the configuration.
|
||||
/// \notes This allows detecting mismatches of configurations and parsers.
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return do_get_name();
|
||||
}
|
||||
|
||||
protected:
|
||||
compile_config(std::vector<std::string> def_flags) : flags_(std::move(def_flags))
|
||||
{
|
||||
|
|
@ -110,6 +117,10 @@ namespace cppast
|
|||
/// \effects Undefines the given macro.
|
||||
virtual void do_remove_macro_definition(std::string name) = 0;
|
||||
|
||||
/// \returns A unique name of the configuration.
|
||||
/// \notes This allows detecting mismatches of configurations and parsers.
|
||||
virtual const char* do_get_name() const noexcept = 0;
|
||||
|
||||
std::vector<std::string> flags_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,11 @@ namespace cppast
|
|||
|
||||
/// \effects Parses the given file.
|
||||
/// \returns The [cppast::cpp_file]() object describing it.
|
||||
std::unique_ptr<cpp_file> parse(const cpp_entity_index& idx, const std::string& path,
|
||||
/// \requires The dynamic type of `config` must match the required config type.
|
||||
std::unique_ptr<cpp_file> parse(const cpp_entity_index& idx, std::string path,
|
||||
const compile_config& config) const
|
||||
{
|
||||
return do_parse(idx, path, config);
|
||||
return do_parse(idx, std::move(path), config);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
@ -37,9 +38,8 @@ namespace cppast
|
|||
private:
|
||||
/// \effects Parses the given file.
|
||||
/// \returns The [cppast::cpp_file]() object describing it.
|
||||
virtual std::unique_ptr<cpp_file> do_parse(const cpp_entity_index& idx,
|
||||
const std::string& path,
|
||||
const compile_config& config) const = 0;
|
||||
virtual std::unique_ptr<cpp_file> do_parse(const cpp_entity_index& idx, std::string path,
|
||||
const compile_config& config) const = 0;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue