Properly fix #46
This commit is contained in:
commit
8255455533
3 changed files with 16 additions and 20 deletions
|
|
@ -216,7 +216,7 @@ namespace
|
||||||
for (; is_digit(*ptr) || *ptr == '\''; ++ptr)
|
for (; is_digit(*ptr) || *ptr == '\''; ++ptr)
|
||||||
if (*ptr != '\'')
|
if (*ptr != '\'')
|
||||||
result += *ptr;
|
result += *ptr;
|
||||||
DEBUG_ASSERT(result.back() != '\'', detail::assert_handler{});
|
DEBUG_ASSERT(result.empty() || result.back() != '\'', detail::assert_handler{});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -569,7 +569,7 @@ namespace
|
||||||
|
|
||||||
return type_safe::nullopt;
|
return type_safe::nullopt;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
cpp_token_string cpp_token_string::tokenize(std::string str)
|
cpp_token_string cpp_token_string::tokenize(std::string str)
|
||||||
{
|
{
|
||||||
|
|
@ -605,7 +605,7 @@ namespace
|
||||||
{
|
{
|
||||||
return std::isalnum(c) || c == '_';
|
return std::isalnum(c) || c == '_';
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
std::string cpp_token_string::as_string() const
|
std::string cpp_token_string::as_string() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ namespace
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
libclang_compile_config::libclang_compile_config()
|
libclang_compile_config::libclang_compile_config()
|
||||||
: compile_config({}),
|
: compile_config({}),
|
||||||
|
|
@ -150,7 +150,7 @@ namespace
|
||||||
// relative w/o separator
|
// relative w/o separator
|
||||||
return dir.std_str() + file;
|
return dir.std_str() + file;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
void detail::for_each_file(const libclang_compilation_database& database, void* user_data,
|
void detail::for_each_file(const libclang_compilation_database& database, void* user_data,
|
||||||
void (*callback)(void*, std::string))
|
void (*callback)(void*, std::string))
|
||||||
|
|
@ -226,7 +226,7 @@ namespace
|
||||||
// else skip argument
|
// else skip argument
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
libclang_compile_config::libclang_compile_config(const libclang_compilation_database& database,
|
libclang_compile_config::libclang_compile_config(const libclang_compilation_database& database,
|
||||||
const std::string& file)
|
const std::string& file)
|
||||||
|
|
@ -303,7 +303,12 @@ void libclang_compile_config::do_set_flags(cpp_standard standard, compile_flags
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & compile_flag::ms_compatibility)
|
if (flags & compile_flag::ms_compatibility)
|
||||||
|
{
|
||||||
add_flag("-fms-compatibility");
|
add_flag("-fms-compatibility");
|
||||||
|
// see https://github.com/foonathan/cppast/issues/46
|
||||||
|
define_macro("_DEBUG_FUNCTIONAL_MACHINERY", "");
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & compile_flag::ms_extensions)
|
if (flags & compile_flag::ms_extensions)
|
||||||
add_flag("-fms-extensions");
|
add_flag("-fms-extensions");
|
||||||
}
|
}
|
||||||
|
|
@ -484,7 +489,7 @@ namespace
|
||||||
clang_getPresumedLocation(loc, nullptr, &line, nullptr);
|
clang_getPresumedLocation(loc, nullptr, &line, nullptr);
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx, std::string path,
|
std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx, std::string path,
|
||||||
const compile_config& c) const try
|
const compile_config& c) const try
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse and log diagnostic
|
// parse and log diagnostic
|
||||||
// returns true if a diagnostic was logged due to a bug, but it is otherwise harmless
|
void log_diagnostic(const diagnostic_logger& logger, const std::string& msg)
|
||||||
bool log_diagnostic(const diagnostic_logger& logger, const std::string& msg)
|
|
||||||
{
|
{
|
||||||
auto ptr = msg.c_str();
|
auto ptr = msg.c_str();
|
||||||
|
|
||||||
|
|
@ -105,13 +104,7 @@ namespace
|
||||||
while (*ptr && *ptr != '\n')
|
while (*ptr && *ptr != '\n')
|
||||||
message.push_back(*ptr++);
|
message.push_back(*ptr++);
|
||||||
|
|
||||||
// see https://github.com/foonathan/cppast/issues/46
|
|
||||||
auto harmless_diag =
|
|
||||||
message.find("invalid filename for #line directive") != std::string::npos;
|
|
||||||
|
|
||||||
logger.log("preprocessor", diagnostic{std::move(message), std::move(loc), sev});
|
logger.log("preprocessor", diagnostic{std::move(message), std::move(loc), sev});
|
||||||
|
|
||||||
return harmless_diag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parses missing header file diagnostic and returns the file name,
|
// parses missing header file diagnostic and returns the file name,
|
||||||
|
|
@ -362,8 +355,6 @@ namespace
|
||||||
std::string write_macro_file(const libclang_compile_config& c, const std::string& full_path,
|
std::string write_macro_file(const libclang_compile_config& c, const std::string& full_path,
|
||||||
const diagnostic_logger& logger)
|
const diagnostic_logger& logger)
|
||||||
{
|
{
|
||||||
auto expect_bad_exit_code = false;
|
|
||||||
|
|
||||||
std::string diagnostic;
|
std::string diagnostic;
|
||||||
auto diagnostic_logger = [&](const char* str, std::size_t n) {
|
auto diagnostic_logger = [&](const char* str, std::size_t n) {
|
||||||
diagnostic.reserve(diagnostic.size() + n);
|
diagnostic.reserve(diagnostic.size() + n);
|
||||||
|
|
@ -373,7 +364,7 @@ namespace
|
||||||
else if (*str == '\n')
|
else if (*str == '\n')
|
||||||
{
|
{
|
||||||
// consume current diagnostic
|
// consume current diagnostic
|
||||||
expect_bad_exit_code |= log_diagnostic(logger, diagnostic);
|
log_diagnostic(logger, diagnostic);
|
||||||
diagnostic.clear();
|
diagnostic.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -396,7 +387,7 @@ namespace
|
||||||
|
|
||||||
auto exit_code = process.get_exit_status();
|
auto exit_code = process.get_exit_status();
|
||||||
DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{});
|
DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{});
|
||||||
if (exit_code != 0 && !expect_bad_exit_code)
|
if (exit_code != 0)
|
||||||
throw libclang_error("preprocessor (macro): command '" + cmd
|
throw libclang_error("preprocessor (macro): command '" + cmd
|
||||||
+ "' exited with non-zero exit code (" + std::to_string(exit_code)
|
+ "' exited with non-zero exit code (" + std::to_string(exit_code)
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
@ -438,7 +429,7 @@ namespace
|
||||||
expect_bad_exit_code = true;
|
expect_bad_exit_code = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
expect_bad_exit_code |= log_diagnostic(logger, diagnostic);
|
log_diagnostic(logger, diagnostic);
|
||||||
|
|
||||||
diagnostic.clear();
|
diagnostic.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue