Skip to content

Add escaping for some float typedefs #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion server/src/clang-utils/SourceToHeaderMatchCallback.cpp
Original file line number Diff line number Diff line change
@@ -382,6 +382,13 @@ std::string SourceToHeaderMatchCallback::decorate(std::string_view name) const {
return forStubHeader ? std::string(name) : NameDecorator::decorate(name);
}

const std::string GNUPREREQ = "!__GNUC_PREREQ (7, 0) || defined __cplusplus";
const std::set<std::string> TypedefEscapeMap = {
"_Float32",
"_Float64",
"_Float32x",
"_Float64x"
};

void SourceToHeaderMatchCallback::print(const NamedDecl *decl, const PrintingPolicy &policy) const {
if (externalStream == nullptr) {
@@ -394,8 +401,20 @@ void SourceToHeaderMatchCallback::print(const NamedDecl *decl, const PrintingPol
}
auto name = decl->getNameAsString();
auto decoratedName = decorate(name);
const auto it = TypedefEscapeMap.find(name);
auto declaration = getRenamedDeclarationAsString(decl, policy, decoratedName);
*externalStream << declaration << ";\n";
if (it != TypedefEscapeMap.end()) {
*externalStream << "#ifdef __GNUC__\n"
<< "# include <features.h>\n"
<< "# if " << GNUPREREQ << "\n"
<< declaration << ";\n"
<< "# endif" << "\n"
<< "#else" << "\n"
<< declaration << ";\n"
<< "#endif" << "\n";
} else {
*externalStream << declaration << ";\n";
}
if (pAlignmentAttr) {
*externalStream << "#pragma pack(pop)\n";
}