Skip to content

Commit 4ce4ada

Browse files
authored
Add escaping for some float typedefs (#656)
1 parent b39958f commit 4ce4ada

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

server/src/clang-utils/SourceToHeaderMatchCallback.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ std::string SourceToHeaderMatchCallback::decorate(std::string_view name) const {
382382
return forStubHeader ? std::string(name) : NameDecorator::decorate(name);
383383
}
384384

385+
const std::string GNUPREREQ = "!__GNUC_PREREQ (7, 0) || defined __cplusplus";
386+
const std::set<std::string> TypedefEscapeMap = {
387+
"_Float32",
388+
"_Float64",
389+
"_Float32x",
390+
"_Float64x"
391+
};
385392

386393
void SourceToHeaderMatchCallback::print(const NamedDecl *decl, const PrintingPolicy &policy) const {
387394
if (externalStream == nullptr) {
@@ -394,8 +401,20 @@ void SourceToHeaderMatchCallback::print(const NamedDecl *decl, const PrintingPol
394401
}
395402
auto name = decl->getNameAsString();
396403
auto decoratedName = decorate(name);
404+
const auto it = TypedefEscapeMap.find(name);
397405
auto declaration = getRenamedDeclarationAsString(decl, policy, decoratedName);
398-
*externalStream << declaration << ";\n";
406+
if (it != TypedefEscapeMap.end()) {
407+
*externalStream << "#ifdef __GNUC__\n"
408+
<< "# include <features.h>\n"
409+
<< "# if " << GNUPREREQ << "\n"
410+
<< declaration << ";\n"
411+
<< "# endif" << "\n"
412+
<< "#else" << "\n"
413+
<< declaration << ";\n"
414+
<< "#endif" << "\n";
415+
} else {
416+
*externalStream << declaration << ";\n";
417+
}
399418
if (pAlignmentAttr) {
400419
*externalStream << "#pragma pack(pop)\n";
401420
}

0 commit comments

Comments
 (0)