diff --git a/include/cppast/compile_config.hpp b/include/cppast/compile_config.hpp new file mode 100644 index 0000000..cfc668e --- /dev/null +++ b/include/cppast/compile_config.hpp @@ -0,0 +1,117 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#ifndef CPPAST_COMPILE_CONFIG_HPP_INCLUDED +#define CPPAST_COMPILE_CONFIG_HPP_INCLUDED + +#include +#include + +#include +#include + +namespace cppast +{ + /// The C++ standard that should be used. + enum class cpp_standard + { + cpp_98, + cpp_03, + cpp_11, + cpp_14, + + cpp_latest = cpp_standard::cpp_14, + }; + + /// Other special compilation flags. + enum class compile_flag + { + gnu_extensions, //< Enable GCC extensions. + + ms_extensions, //< Enable MSVC extensions. + ms_compatibility, //< Enable MSVC compatibility. + + _count, //< \exclude + }; +} // namespace cppast + +namespace type_safe +{ + /// Specialization of [ts::flag_set_traits]() to use [cppast::compile_flag]() with [ts::flag_set](). + template <> + struct flag_set_traits : std::true_type + { + static constexpr std::size_t size() noexcept + { + return static_cast(cppast::compile_flag::_count); + } + }; +} // namespace type_safe + +namespace cppast +{ + /// Base class for the configuration of a [cppast::parser](). + class compile_config + { + public: + /// \effects Sets the given C++ standard and compilation flags. + void set_standard(cpp_standard standard, type_safe::flag_set flags) + { + do_set_flags(standard, flags); + } + + /// \effects Adds the given path to the set of include directories. + void add_include_dir(std::string path) + { + do_add_include_dir(std::move(path)); + } + + /// \effects Defines the given macro. + void define_macro(std::string name, std::string definition) + { + do_add_macro_definition(std::move(name), std::move(definition)); + } + + /// \effects Undefines the given macro. + void undefine_macro(std::string name) + { + do_remove_macro_definition(std::move(name)); + } + + protected: + compile_config(std::vector def_flags) : flags_(std::move(def_flags)) + { + } + + ~compile_config() noexcept = default; + + void add_flag(std::string flag) + { + flags_.push_back(std::move(flag)); + } + + const std::vector& get_flags() const noexcept + { + return flags_; + } + + private: + /// \effects Sets the given C++ standard and compilation flags. + virtual void do_set_flags(cpp_standard standard, + type_safe::flag_set flags) = 0; + + /// \effects Adds the given path to the set of include directories. + virtual void do_add_include_dir(std::string path) = 0; + + /// \effects Defines the given macro. + virtual void do_add_macro_definition(std::string name, std::string definition) = 0; + + /// \effects Undefines the given macro. + virtual void do_remove_macro_definition(std::string name) = 0; + + std::vector flags_; + }; +} // namespace cppast + +#endif // CPPAST_COMPILE_CONFIG_HPP_INCLUDED diff --git a/include/cppast/parser.hpp b/include/cppast/parser.hpp new file mode 100644 index 0000000..2c6803d --- /dev/null +++ b/include/cppast/parser.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#ifndef CPPAST_PARSER_HPP_INCLUDED +#define CPPAST_PARSER_HPP_INCLUDED + +#include +#include + +namespace cppast +{ + class cpp_entity_index; + + /// Base class for a parser. + /// + /// It reads a C++ source file and creates the matching [cppast::cpp_file](). + class parser + { + public: + parser(const parser&) = delete; + parser& operator=(const parser&) = delete; + + virtual ~parser() noexcept = default; + + /// \effects Parses the given file. + /// \returns The [cppast::cpp_file]() object describing it. + std::unique_ptr parse(const cpp_entity_index& idx, const std::string& path, + const compile_config& config) const + { + return do_parse(idx, path, config); + } + + protected: + parser() = default; + + private: + /// \effects Parses the given file. + /// \returns The [cppast::cpp_file]() object describing it. + virtual std::unique_ptr do_parse(const cpp_entity_index& idx, + const std::string& path, + const compile_config& config) const = 0; + }; +} // namespace cppast + +#endif // CPPAST_PARSER_HPP_INCLUDED