Fix issue with double quotation of macros

Fixes foonathan/standardese#117.
This commit is contained in:
Jonathan Müller 2018-12-20 16:20:45 +01:00
commit 44fbe78b2e
3 changed files with 33 additions and 18 deletions

View file

@ -401,17 +401,7 @@ void libclang_compile_config::do_add_macro_definition(std::string name, std::str
{
auto str = "-D" + std::move(name);
if (!definition.empty())
{
str += "=\"";
for (auto c : definition)
{
if (c == '"')
str += "\\\"";
else
str += c;
}
str += "\"";
}
str += "=" + definition;
add_flag(std::move(str));
}
@ -517,10 +507,7 @@ detail::cxtranslation_unit get_cxunit(const diagnostic_logger& logger, const det
const libclang_compile_config& config, const char* path,
const std::string& source)
{
CXUnsavedFile file;
file.Filename = path;
file.Contents = source.c_str();
file.Length = static_cast<unsigned long>(source.length());
CXUnsavedFile file{path, source.c_str(), static_cast<unsigned long>(source.length())};
auto args = get_arguments(config);

View file

@ -93,6 +93,33 @@ namespace ns2
}
}
TEST_CASE("command line macro definition")
{
write_file("command_line_macro_definition.hpp", "NAME foo;");
write_file("command_line_macro_definition.cpp",
R"(#include "command_line_macro_definition.hpp")");
struct test_logger : diagnostic_logger
{
mutable bool error = false;
bool do_log(const char* source, const diagnostic& d) const override
{
error = true;
default_logger()->log(source, d);
return false;
}
} logger;
libclang_compile_config config;
config.define_macro("NAME", "int");
libclang_parser parser{type_safe::ref(logger)};
parser.parse({}, "command_line_macro_definition.cpp", config);
REQUIRE(!parser.error());
REQUIRE(!logger.error);
}
TEST_CASE("cpp_include_directive")
{
write_file("cpp_include_directive-header.hpp", R"(

View file

@ -25,13 +25,14 @@ void require_flags(const libclang_compile_config& config, const char* flags)
auto config_flags = detail::libclang_compile_config_access::flags(config);
// skip until including __cppast_version__minor__, those are the default options
auto in_default = true;
for (auto iter = config_flags.begin(); iter != config_flags.end(); ++iter)
for (auto& config_flag : config_flags)
{
if (*iter == "-D__cppast_version_minor__=\"" CPPAST_VERSION_MINOR "\"")
if (config_flag == "-D__cppast_version_minor__=" CPPAST_VERSION_MINOR)
in_default = false;
else if (!in_default)
result += *iter + ' ';
result += config_flag + ' ';
}
REQUIRE(!result.empty());
result.pop_back();
REQUIRE(result == flags);
}