Skip to content

Commit 7a8049a

Browse files
committed
Delete comments and move function in converter_lib
1 parent a0e2b8b commit 7a8049a

12 files changed

Lines changed: 19 additions & 29 deletions

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
128128

129129
bool Converter::VisitRecordType(clang::RecordType *type) {
130130
auto *decl = type->getDecl();
131-
132131
if (auto lambda = clang::dyn_cast<clang::CXXRecordDecl>(decl)) {
133132
if (lambda->isLambda()) {
134133
auto call_op = lambda->getLambdaCallOperator();
@@ -360,9 +359,9 @@ bool Converter::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *decl) {
360359

361360
void Converter::ConvertVaListVarDecl(clang::VarDecl *decl) {
362361
if (clang::isa<clang::ParmVarDecl>(decl)) {
363-
// va_list parameter (decayed to __va_list_tag *): emit "mut ap: VaList"
362+
// va_list parameter (decayed to __va_list_tag *)
364363
} else {
365-
// va_list local variable: emit "let mut ap: VaList"
364+
// va_list local variable
366365
StrCat(keyword::kLet);
367366
}
368367
StrCat(keyword_mut_, GetNamedDeclAsString(decl), token::kColon, "VaList");

cpp2rust/converter/converter_lib.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,16 @@ bool IsBuiltinVaCopy(const clang::CallExpr *expr) {
600600
return false;
601601
}
602602

603+
bool ContainsVAArgExpr(const clang::Stmt *stmt) {
604+
if (clang::isa<clang::VAArgExpr>(stmt)) {
605+
return true;
606+
}
607+
for (auto *child : stmt->children()) {
608+
if (ContainsVAArgExpr(child)) {
609+
return true;
610+
}
611+
}
612+
return false;
613+
}
614+
603615
} // namespace cpp2rust

cpp2rust/converter/converter_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,6 @@ bool IsBuiltinVaEnd(const clang::CallExpr *expr);
150150

151151
bool IsBuiltinVaCopy(const clang::CallExpr *expr);
152152

153+
bool ContainsVAArgExpr(const clang::Stmt *stmt);
154+
153155
} // namespace cpp2rust

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ void ConverterRefCount::EmitFunctionPreamble(clang::FunctionDecl *decl) {
479479

480480
void ConverterRefCount::ConvertVaListVarDecl(clang::VarDecl *decl) {
481481
if (clang::isa<clang::ParmVarDecl>(decl)) {
482-
// va_list parameter (decayed to __va_list_tag *): emit "mut ap: VaList"
482+
// va_list parameter (decayed to __va_list_tag *)
483483
} else {
484-
// va_list local variable: emit "let mut ap: VaList"
484+
// va_list local variable
485485
StrCat(keyword::kLet);
486486
}
487487

@@ -1495,18 +1495,6 @@ void ConverterRefCount::ConvertVarInit(clang::QualType qual_type,
14951495
in_function_formals_ = false;
14961496
}
14971497

1498-
static bool ContainsVAArgExpr(const clang::Stmt *stmt) {
1499-
if (clang::isa<clang::VAArgExpr>(stmt)) {
1500-
return true;
1501-
}
1502-
for (auto *child : stmt->children()) {
1503-
if (ContainsVAArgExpr(child)) {
1504-
return true;
1505-
}
1506-
}
1507-
return false;
1508-
}
1509-
15101498
static std::unordered_set<const clang::ValueDecl *>
15111499
GetAllVars(const clang::Stmt *stmt) {
15121500
std::unordered_set<const clang::ValueDecl *> vars;

tests/unit/va_arg_chain.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Pattern from curl's trc_write chain: variadic -> va_list -> va_list forwarding
21
#include <assert.h>
32
#include <stdarg.h>
43

@@ -22,7 +21,6 @@ int top_level(int n, ...) {
2221
}
2322

2423
int main() {
25-
// Extract the 3rd arg (0-indexed): 100, 200, 300, 400 -> 300
2624
assert(top_level(2, 100, 200, 300, 400) == 300);
2725
assert(top_level(0, 42, 99) == 42);
2826
assert(top_level(3, 1, 2, 3, 4) == 4);

tests/unit/va_arg_conditional.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Pattern from Curl_failf: va_start only under a condition
21
#include <assert.h>
32
#include <stdarg.h>
43

tests/unit/va_arg_copy.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// va_copy: save position, consume from copy, original still usable
21
#include <assert.h>
32
#include <stdarg.h>
43

@@ -28,7 +27,6 @@ int sum_with_copy(int count, ...) {
2827
}
2928

3029
int main() {
31-
// sum1 = 10+20+30 = 60, sum2 = 10+20+30 = 60, total = 120
3230
assert(sum_with_copy(3, 10, 20, 30) == 120);
3331
return 0;
3432
}

tests/unit/va_arg_mixed_int_ptr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// va_arg with mixed int and pointer types in the same call
21
#include <assert.h>
32
#include <stdarg.h>
43

@@ -23,7 +22,6 @@ int mixed_args(int count, ...) {
2322

2423
int main() {
2524
int x = 100;
26-
// tag=0 val=10, tag=1 ptr=&x(100), tag=0 val=20
2725
assert(mixed_args(3, 0, 10, 1, &x, 0, 20) == 130);
2826

2927
int y = 50;

tests/unit/va_arg_mixed_types.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ int sum_mixed(int count, ...) {
2121
}
2222

2323
int main() {
24-
// tag=0 int=10, tag=1 double=20.5, tag=2 long=30
2524
assert(sum_mixed(3, 0, 10, 1, 20.5, 2, 30L) == 60);
2625
assert(sum_mixed(1, 0, 42) == 42);
2726
assert(sum_mixed(2, 1, 3.7, 2, 100L) == 103);

tests/unit/va_arg_promotion.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// C promotion rules: char/short promote to int, float promotes to double
21
#include <assert.h>
32
#include <stdarg.h>
43

@@ -23,7 +22,7 @@ int test_promotions(int count, ...) {
2322
}
2423

2524
int main() {
26-
char x = 'A'; // 65
25+
char x = 'A';
2726
short y = 10;
2827
float z = 3.0f;
2928
// 65 + 10 + 3 = 78

0 commit comments

Comments
 (0)