Skip to content

Commit d8c4522

Browse files
committed
Stop spelling library specific names __stdoutp and __stderrp
1 parent 505326e commit d8c4522

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,9 @@ bool IsCallToOstream(clang::CallExpr *expr) {
685685
}
686686

687687
bool IsCDecl(const clang::NamedDecl *decl, llvm::StringRef name) {
688-
bool is_extern_c = false;
689-
if (auto *function = clang::dyn_cast_or_null<clang::FunctionDecl>(decl)) {
690-
is_extern_c = function->isExternC();
691-
} else if (auto *var = clang::dyn_cast_or_null<clang::VarDecl>(decl)) {
692-
is_extern_c = var->isExternC();
693-
}
694-
return is_extern_c && decl->getIdentifier() && decl->getName() == name;
688+
auto *function = clang::dyn_cast_or_null<clang::FunctionDecl>(decl);
689+
return function && function->isExternC() && function->getIdentifier() &&
690+
function->getName() == name;
695691
}
696692

697693
bool IsStdFunction(const clang::Expr *expr, llvm::StringRef name) {

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <clang/AST/RecordLayout.h>
77
#include <clang/Basic/OperatorKinds.h>
8+
#include <clang/Lex/Lexer.h>
89
#include <llvm/Support/ErrorHandling.h>
910

1011
#include <algorithm>
@@ -1238,15 +1239,17 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
12381239
expr->getArg(is_fprintf)->IgnoreImplicit()));
12391240
bool ends_newline = format.ends_with("\\n\"");
12401241

1241-
const clang::NamedDecl *stream = nullptr;
1242-
if (auto *ref = clang::dyn_cast<clang::DeclRefExpr>(
1243-
expr->getArg(0)->IgnoreParenImpCasts())) {
1244-
stream = ref->getDecl();
1242+
llvm::StringRef stream = "stdout";
1243+
if (is_fprintf) {
1244+
auto loc = expr->getArg(0)->IgnoreParenImpCasts()->getBeginLoc();
1245+
stream = loc.isMacroID()
1246+
? clang::Lexer::getImmediateMacroName(
1247+
loc, ctx_.getSourceManager(), ctx_.getLangOpts())
1248+
: "";
12451249
}
1246-
if (!is_fprintf || IsCDecl(stream, "stdout") ||
1247-
IsCDecl(stream, "__stdoutp")) {
1250+
if (stream == "stdout") {
12481251
StrCat(ends_newline ? "println!(" : "print!(");
1249-
} else if (IsCDecl(stream, "stderr") || IsCDecl(stream, "__stderrp")) {
1252+
} else if (stream == "stderr") {
12501253
StrCat(ends_newline ? "eprintln!(" : "eprint!(");
12511254
} else {
12521255
llvm::errs() << "Unknown fprintf fd:\n";

0 commit comments

Comments
 (0)