Skip to content

Commit 4d7ec58

Browse files
committed
PrintAsClang: Apply review comments to check on should print of @cdecl
1 parent 372dfe4 commit 4d7ec58

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,14 +3007,22 @@ bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {
30073007
return false;
30083008
}
30093009

3010-
// In C output mode print only @cdecls and skip them in other modes.
3011-
bool isCDeclForC = false;
3012-
auto *FD = dyn_cast<AbstractFunctionDecl>(VD);
3013-
if (FD)
3014-
isCDeclForC = FD->getCDeclKind() == ForeignLanguage::C;
3015-
if (isCDeclForC != (outputLang == OutputLanguageMode::C))
3010+
// In C output mode print only the C variant `@cdecl` (no `@_cdecl`),
3011+
// while in other modes print only `@_cdecl`.
3012+
std::optional<ForeignLanguage> cdeclKind = std::nullopt;
3013+
if (auto *FD = dyn_cast<AbstractFunctionDecl>(VD))
3014+
cdeclKind = FD->getCDeclKind();
3015+
if (cdeclKind &&
3016+
(*cdeclKind == ForeignLanguage::C) !=
3017+
(outputLang == OutputLanguageMode::C))
30163018
return false;
30173019

3020+
// C output mode only accepts @cdecl functions.
3021+
if (outputLang == OutputLanguageMode::C &&
3022+
!cdeclKind) {
3023+
return false;
3024+
}
3025+
30183026
if (VD->getAttrs().hasAttribute<ImplementationOnlyAttr>())
30193027
return false;
30203028

0 commit comments

Comments
 (0)