parent
2004780ea6
commit
61a2a22542
4 changed files with 35 additions and 4 deletions
|
|
@ -27,6 +27,8 @@ namespace cppast
|
|||
static bool write_preprocessed(const libclang_compile_config& config);
|
||||
|
||||
static bool fast_preprocessing(const libclang_compile_config& config);
|
||||
|
||||
static bool remove_comments_in_macro(const libclang_compile_config& config);
|
||||
};
|
||||
|
||||
void for_each_file(const libclang_compilation_database& database, void* user_data,
|
||||
|
|
@ -144,6 +146,15 @@ namespace cppast
|
|||
fast_preprocessing_ = b;
|
||||
}
|
||||
|
||||
/// \effects Sets whether or not documentation comments generated by macros are removed.
|
||||
/// Default value is `false`.
|
||||
/// \notes If this leads to an error due to preprocessing and comments, you have to enable it.
|
||||
/// \notes If this is `true`, `clang` will be invoked with `-CC`, otherwise `-C`.
|
||||
void remove_comments_in_macro(bool b) noexcept
|
||||
{
|
||||
remove_comments_in_macro_ = b;
|
||||
}
|
||||
|
||||
private:
|
||||
void do_set_flags(cpp_standard standard, compile_flags flags) override;
|
||||
|
||||
|
|
@ -162,6 +173,7 @@ namespace cppast
|
|||
int clang_version_;
|
||||
bool write_preprocessed_ : 1;
|
||||
bool fast_preprocessing_ : 1;
|
||||
bool remove_comments_in_macro_ : 1;
|
||||
|
||||
friend detail::libclang_compile_config_access;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ bool detail::libclang_compile_config_access::fast_preprocessing(
|
|||
return config.fast_preprocessing_;
|
||||
}
|
||||
|
||||
bool detail::libclang_compile_config_access::remove_comments_in_macro(
|
||||
const libclang_compile_config& config)
|
||||
{
|
||||
return config.remove_comments_in_macro_;
|
||||
}
|
||||
|
||||
libclang_compilation_database::libclang_compilation_database(const std::string& build_directory)
|
||||
{
|
||||
static_assert(std::is_same<database, CXCompilationDatabase>::value, "forgot to update type");
|
||||
|
|
@ -88,7 +94,10 @@ namespace
|
|||
}
|
||||
|
||||
libclang_compile_config::libclang_compile_config()
|
||||
: compile_config({}), write_preprocessed_(false), fast_preprocessing_(false)
|
||||
: compile_config({}),
|
||||
write_preprocessed_(false),
|
||||
fast_preprocessing_(false),
|
||||
remove_comments_in_macro_(false)
|
||||
{
|
||||
// set given clang binary
|
||||
auto ptr = CPPAST_CLANG_VERSION_STRING;
|
||||
|
|
|
|||
|
|
@ -200,9 +200,15 @@ namespace
|
|||
{
|
||||
// -x c++: force C++ as input language
|
||||
// -E: print preprocessor output
|
||||
// -CC: keep comments, even in macro
|
||||
// -dD: keep macros
|
||||
auto flags = std::string("-x c++ -E -CC -dD");
|
||||
auto flags = std::string("-x c++ -E -dD");
|
||||
|
||||
// -CC: keep comments, even in macro
|
||||
// -C: keep comments, but not in macro
|
||||
if (!detail::libclang_compile_config_access::remove_comments_in_macro(c))
|
||||
flags += " -CC";
|
||||
else
|
||||
flags += " -C";
|
||||
|
||||
if (macro_file_path)
|
||||
// -no*: disable default include search paths
|
||||
|
|
|
|||
|
|
@ -210,7 +210,8 @@ int main(int argc, char* argv[]) try
|
|||
("gnu_extensions", "enable GNU extensions (equivalent to -std=gnu++XX)")
|
||||
("msvc_extensions", "enable MSVC extensions (equivalent to -fms-extensions)")
|
||||
("msvc_compatibility", "enable MSVC compatibility (equivalent to -fms-compatibility)")
|
||||
("fast_preprocessing", "enable fast preprocessing, be careful, this breaks if you e.g. redefine macros in the same file!");
|
||||
("fast_preprocessing", "enable fast preprocessing, be careful, this breaks if you e.g. redefine macros in the same file!")
|
||||
("remove_comments_in_macro", "whether or not comments generated by macro are kept, enable if you run into errors");
|
||||
// clang-format on
|
||||
options.parse_positional("file");
|
||||
options.parse(argc, argv);
|
||||
|
|
@ -252,6 +253,9 @@ int main(int argc, char* argv[]) try
|
|||
if (options.count("fast_preprocessing"))
|
||||
config.fast_preprocessing(true);
|
||||
|
||||
if (options.count("remove_comments_in_macro"))
|
||||
config.remove_comments_in_macro(true);
|
||||
|
||||
if (options.count("include_directory"))
|
||||
for (auto& include : options["include_directory"].as<std::vector<std::string>>())
|
||||
config.add_include_dir(include);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue