Fix issue with double quotation of macros
Fixes foonathan/standardese#117.
This commit is contained in:
parent
9605bb328f
commit
44fbe78b2e
3 changed files with 33 additions and 18 deletions
|
|
@ -401,17 +401,7 @@ void libclang_compile_config::do_add_macro_definition(std::string name, std::str
|
||||||
{
|
{
|
||||||
auto str = "-D" + std::move(name);
|
auto str = "-D" + std::move(name);
|
||||||
if (!definition.empty())
|
if (!definition.empty())
|
||||||
{
|
str += "=" + definition;
|
||||||
str += "=\"";
|
|
||||||
for (auto c : definition)
|
|
||||||
{
|
|
||||||
if (c == '"')
|
|
||||||
str += "\\\"";
|
|
||||||
else
|
|
||||||
str += c;
|
|
||||||
}
|
|
||||||
str += "\"";
|
|
||||||
}
|
|
||||||
add_flag(std::move(str));
|
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 libclang_compile_config& config, const char* path,
|
||||||
const std::string& source)
|
const std::string& source)
|
||||||
{
|
{
|
||||||
CXUnsavedFile file;
|
CXUnsavedFile file{path, source.c_str(), static_cast<unsigned long>(source.length())};
|
||||||
file.Filename = path;
|
|
||||||
file.Contents = source.c_str();
|
|
||||||
file.Length = static_cast<unsigned long>(source.length());
|
|
||||||
|
|
||||||
auto args = get_arguments(config);
|
auto args = get_arguments(config);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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")
|
TEST_CASE("cpp_include_directive")
|
||||||
{
|
{
|
||||||
write_file("cpp_include_directive-header.hpp", R"(
|
write_file("cpp_include_directive-header.hpp", R"(
|
||||||
|
|
|
||||||
|
|
@ -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);
|
auto config_flags = detail::libclang_compile_config_access::flags(config);
|
||||||
// skip until including __cppast_version__minor__, those are the default options
|
// skip until including __cppast_version__minor__, those are the default options
|
||||||
auto in_default = true;
|
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;
|
in_default = false;
|
||||||
else if (!in_default)
|
else if (!in_default)
|
||||||
result += *iter + ' ';
|
result += config_flag + ' ';
|
||||||
}
|
}
|
||||||
|
REQUIRE(!result.empty());
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
REQUIRE(result == flags);
|
REQUIRE(result == flags);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue