Skip to content

Commit e46e1ad

Browse files
committed
Translate nameless C++ params as _a1, _a2, etc
1 parent fd2ea09 commit e46e1ad

11 files changed

Lines changed: 113 additions & 107 deletions

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,10 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) {
652652
llvm::dyn_cast<clang::FunctionDecl>(pdecl->getDeclContext());
653653
const auto *ctor = llvm::dyn_cast_or_null<clang::CXXConstructorDecl>(fn);
654654
if (pdecl->isExplicitObjectParameter() ||
655-
(ctor && ctor->isCopyOrMoveConstructor())) {
655+
(ctor && ctor->isCopyConstructor())) {
656656
name = "self";
657-
} else if (fn && fn->isDefaulted() && IsComparisonOperator(fn)) {
658-
name = std::format("_arg{}", pdecl->getFunctionScopeIndex());
659657
} else {
660-
name = "_";
658+
name = std::format("_a{}", pdecl->getFunctionScopeIndex());
661659
}
662660
} else if (auto *pdecl = llvm::dyn_cast<clang::ParmVarDecl>(decl)) {
663661
// Expanded parameter packs share one name across the expansion

‎tests/unit/out/refcount/empty_main.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub fn main() {
2222
(*argv.borrow_mut()).push(Ptr::null());
2323
::std::process::exit(main_0(::std::env::args().len() as i32, argv.as_pointer()));
2424
}
25-
fn main_0(_: i32, _: Ptr<Ptr<u8>>) -> i32 {
25+
fn main_0(_a0: i32, _a1: Ptr<Ptr<u8>>) -> i32 {
26+
let _a0: Value<i32> = Rc::new(RefCell::new(_a0));
27+
let _a1: Value<Ptr<Ptr<u8>>> = Rc::new(RefCell::new(_a1));
2628
return 0;
2729
}

‎tests/unit/out/refcount/operator_arithmetic_free.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ pub fn operator_inc_7(a: Ptr<S>) -> Ptr<S> {
8686
(*(*a.upgrade().deref()).v.borrow_mut()).prefix_inc();
8787
return (a).clone();
8888
}
89-
pub fn operator_post_inc_8(a: Ptr<S>, _: i32) -> S {
89+
pub fn operator_post_inc_8(a: Ptr<S>, _a1: i32) -> S {
90+
let _a1: Value<i32> = Rc::new(RefCell::new(_a1));
9091
let old: Value<S> = Rc::new(RefCell::new((*a.upgrade().deref()).clone()));
9192
(*(*a.upgrade().deref()).v.borrow_mut()).prefix_inc();
9293
return (*old.borrow()).clone();
@@ -95,7 +96,8 @@ pub fn operator_dec_9(a: Ptr<S>) -> Ptr<S> {
9596
(*(*a.upgrade().deref()).v.borrow_mut()).prefix_dec();
9697
return (a).clone();
9798
}
98-
pub fn operator_post_dec_10(a: Ptr<S>, _: i32) -> S {
99+
pub fn operator_post_dec_10(a: Ptr<S>, _a1: i32) -> S {
100+
let _a1: Value<i32> = Rc::new(RefCell::new(_a1));
99101
let old: Value<S> = Rc::new(RefCell::new((*a.upgrade().deref()).clone()));
100102
(*(*a.upgrade().deref()).v.borrow_mut()).prefix_dec();
101103
return (*old.borrow()).clone();

‎tests/unit/out/refcount/operator_arithmetic_member.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ pub trait SImpl {
123123
fn operator_pos_const(&self) -> S;
124124
fn operator_neg_const(&self) -> S;
125125
fn operator_inc(&self) -> Ptr<S>;
126-
fn operator_post_inc_i32(&self, _: i32) -> S;
126+
fn operator_post_inc_i32(&self, _a0: i32) -> S;
127127
fn operator_dec(&self) -> Ptr<S>;
128-
fn operator_post_dec_i32(&self, _: i32) -> S;
128+
fn operator_post_dec_i32(&self, _a0: i32) -> S;
129129
}
130130
impl SImpl for Ptr<S> {
131131
fn operator_add_pconstS_const(&self, o: Ptr<S>) -> S {
@@ -182,7 +182,8 @@ impl SImpl for Ptr<S> {
182182
(*(*(*self).upgrade().deref()).v.borrow_mut()).prefix_inc();
183183
return (*self).clone();
184184
}
185-
fn operator_post_inc_i32(&self, _: i32) -> S {
185+
fn operator_post_inc_i32(&self, _a0: i32) -> S {
186+
let _a0: Value<i32> = Rc::new(RefCell::new(_a0));
186187
let old: Value<S> = Rc::new(RefCell::new((*(*self).upgrade().deref()).clone()));
187188
(*(*(*self).upgrade().deref()).v.borrow_mut()).prefix_inc();
188189
return (*old.borrow()).clone();
@@ -191,7 +192,8 @@ impl SImpl for Ptr<S> {
191192
(*(*(*self).upgrade().deref()).v.borrow_mut()).prefix_dec();
192193
return (*self).clone();
193194
}
194-
fn operator_post_dec_i32(&self, _: i32) -> S {
195+
fn operator_post_dec_i32(&self, _a0: i32) -> S {
196+
let _a0: Value<i32> = Rc::new(RefCell::new(_a0));
195197
let old: Value<S> = Rc::new(RefCell::new((*(*self).upgrade().deref()).clone()));
196198
(*(*(*self).upgrade().deref()).v.borrow_mut()).prefix_dec();
197199
return (*old.borrow()).clone();

‎tests/unit/out/refcount/operator_comparison_defaulted.rs‎

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -527,21 +527,21 @@ fn main_0() -> i32 {
527527
return 0;
528528
}
529529
pub trait BothImpl {
530-
fn operator_eq(&self, _arg0: Ptr<Both>) -> bool;
531-
fn operator_cmp(&self, _arg0: Ptr<Both>) -> std::cmp::Ordering;
530+
fn operator_eq(&self, _a0: Ptr<Both>) -> bool;
531+
fn operator_cmp(&self, _a0: Ptr<Both>) -> std::cmp::Ordering;
532532
}
533533
impl BothImpl for Ptr<Both> {
534-
fn operator_eq(&self, _arg0: Ptr<Both>) -> bool {
534+
fn operator_eq(&self, _a0: Ptr<Both>) -> bool {
535535
return {
536536
let _lhs = (*(*(*self).upgrade().deref()).a.borrow());
537-
_lhs == (*(*_arg0.upgrade().deref()).a.borrow())
537+
_lhs == (*(*_a0.upgrade().deref()).a.borrow())
538538
};
539539
}
540-
fn operator_cmp(&self, _arg0: Ptr<Both>) -> std::cmp::Ordering {
540+
fn operator_cmp(&self, _a0: Ptr<Both>) -> std::cmp::Ordering {
541541
{
542542
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
543543
(*(*(*self).upgrade().deref()).a.borrow())
544-
.cmp(&(*(*_arg0.upgrade().deref()).a.borrow())),
544+
.cmp(&(*(*_a0.upgrade().deref()).a.borrow())),
545545
));
546546
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
547547
return (*cmp.borrow_mut()).clone();
@@ -551,15 +551,15 @@ impl BothImpl for Ptr<Both> {
551551
}
552552
}
553553
pub trait CmpImpl {
554-
fn operator_cmp(&self, _arg0: Ptr<Cmp>) -> std::cmp::Ordering;
555-
fn operator_eq(&self, _arg0: Ptr<Cmp>) -> bool;
554+
fn operator_cmp(&self, _a0: Ptr<Cmp>) -> std::cmp::Ordering;
555+
fn operator_eq(&self, _a0: Ptr<Cmp>) -> bool;
556556
}
557557
impl CmpImpl for Ptr<Cmp> {
558-
fn operator_cmp(&self, _arg0: Ptr<Cmp>) -> std::cmp::Ordering {
558+
fn operator_cmp(&self, _a0: Ptr<Cmp>) -> std::cmp::Ordering {
559559
{
560560
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
561561
(*(*(*self).upgrade().deref()).a.borrow())
562-
.cmp(&(*(*_arg0.upgrade().deref()).a.borrow())),
562+
.cmp(&(*(*_a0.upgrade().deref()).a.borrow())),
563563
));
564564
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
565565
return (*cmp.borrow_mut()).clone();
@@ -568,71 +568,71 @@ impl CmpImpl for Ptr<Cmp> {
568568
{
569569
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
570570
(*(*(*self).upgrade().deref()).b.borrow())
571-
.cmp(&(*(*_arg0.upgrade().deref()).b.borrow())),
571+
.cmp(&(*(*_a0.upgrade().deref()).b.borrow())),
572572
));
573573
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
574574
return (*cmp.borrow_mut()).clone();
575575
}
576576
}
577577
return std::cmp::Ordering::Equal;
578578
}
579-
fn operator_eq(&self, _arg0: Ptr<Cmp>) -> bool {
579+
fn operator_eq(&self, _a0: Ptr<Cmp>) -> bool {
580580
return ({
581581
let _lhs = (*(*(*self).upgrade().deref()).a.borrow());
582-
_lhs == (*(*_arg0.upgrade().deref()).a.borrow())
582+
_lhs == (*(*_a0.upgrade().deref()).a.borrow())
583583
}) && ({
584584
let _lhs = (*(*(*self).upgrade().deref()).b.borrow());
585-
_lhs == (*(*_arg0.upgrade().deref()).b.borrow())
585+
_lhs == (*(*_a0.upgrade().deref()).b.borrow())
586586
});
587587
}
588588
}
589589
pub trait EqImpl {
590-
fn operator_eq(&self, _arg0: Ptr<Eq>) -> bool;
590+
fn operator_eq(&self, _a0: Ptr<Eq>) -> bool;
591591
}
592592
impl EqImpl for Ptr<Eq> {
593-
fn operator_eq(&self, _arg0: Ptr<Eq>) -> bool {
593+
fn operator_eq(&self, _a0: Ptr<Eq>) -> bool {
594594
return ({
595595
let _lhs = (*(*(*self).upgrade().deref()).a.borrow());
596-
_lhs == (*(*_arg0.upgrade().deref()).a.borrow())
596+
_lhs == (*(*_a0.upgrade().deref()).a.borrow())
597597
}) && ({
598598
let _lhs = (*(*(*self).upgrade().deref()).b.borrow());
599-
_lhs == (*(*_arg0.upgrade().deref()).b.borrow())
599+
_lhs == (*(*_a0.upgrade().deref()).b.borrow())
600600
});
601601
}
602602
}
603603
pub trait InnerImpl {
604-
fn operator_cmp(&self, _arg0: Ptr<Inner>) -> std::cmp::Ordering;
605-
fn operator_eq(&self, _arg0: Ptr<Inner>) -> bool;
604+
fn operator_cmp(&self, _a0: Ptr<Inner>) -> std::cmp::Ordering;
605+
fn operator_eq(&self, _a0: Ptr<Inner>) -> bool;
606606
}
607607
impl InnerImpl for Ptr<Inner> {
608-
fn operator_cmp(&self, _arg0: Ptr<Inner>) -> std::cmp::Ordering {
608+
fn operator_cmp(&self, _a0: Ptr<Inner>) -> std::cmp::Ordering {
609609
{
610610
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
611611
(*(*(*self).upgrade().deref()).x.borrow())
612-
.cmp(&(*(*_arg0.upgrade().deref()).x.borrow())),
612+
.cmp(&(*(*_a0.upgrade().deref()).x.borrow())),
613613
));
614614
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
615615
return (*cmp.borrow_mut()).clone();
616616
}
617617
}
618618
return std::cmp::Ordering::Equal;
619619
}
620-
fn operator_eq(&self, _arg0: Ptr<Inner>) -> bool {
620+
fn operator_eq(&self, _a0: Ptr<Inner>) -> bool {
621621
return {
622622
let _lhs = (*(*(*self).upgrade().deref()).x.borrow());
623-
_lhs == (*(*_arg0.upgrade().deref()).x.borrow())
623+
_lhs == (*(*_a0.upgrade().deref()).x.borrow())
624624
};
625625
}
626626
}
627627
pub trait OrdOnlyImpl {
628-
fn operator_cmp(&self, _arg0: Ptr<OrdOnly>) -> std::cmp::Ordering;
628+
fn operator_cmp(&self, _a0: Ptr<OrdOnly>) -> std::cmp::Ordering;
629629
}
630630
impl OrdOnlyImpl for Ptr<OrdOnly> {
631-
fn operator_cmp(&self, _arg0: Ptr<OrdOnly>) -> std::cmp::Ordering {
631+
fn operator_cmp(&self, _a0: Ptr<OrdOnly>) -> std::cmp::Ordering {
632632
{
633633
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
634634
(*(*(*self).upgrade().deref()).a.borrow())
635-
.cmp(&(*(*_arg0.upgrade().deref()).a.borrow())),
635+
.cmp(&(*(*_a0.upgrade().deref()).a.borrow())),
636636
));
637637
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
638638
return (*cmp.borrow_mut()).clone();
@@ -642,15 +642,15 @@ impl OrdOnlyImpl for Ptr<OrdOnly> {
642642
}
643643
}
644644
pub trait OuterImpl {
645-
fn operator_cmp(&self, _arg0: Ptr<Outer>) -> std::cmp::Ordering;
646-
fn operator_eq(&self, _arg0: Ptr<Outer>) -> bool;
645+
fn operator_cmp(&self, _a0: Ptr<Outer>) -> std::cmp::Ordering;
646+
fn operator_eq(&self, _a0: Ptr<Outer>) -> bool;
647647
}
648648
impl OuterImpl for Ptr<Outer> {
649-
fn operator_cmp(&self, _arg0: Ptr<Outer>) -> std::cmp::Ordering {
649+
fn operator_cmp(&self, _a0: Ptr<Outer>) -> std::cmp::Ordering {
650650
{
651651
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
652652
({
653-
let _arg0: Ptr<Inner> = (*_arg0.upgrade().deref()).i.as_pointer();
653+
let _arg0: Ptr<Inner> = (*_a0.upgrade().deref()).i.as_pointer();
654654
InnerImpl::operator_cmp(&(*(*self).upgrade().deref()).i.as_pointer(), _arg0)
655655
}),
656656
));
@@ -661,65 +661,65 @@ impl OuterImpl for Ptr<Outer> {
661661
{
662662
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
663663
(*(*(*self).upgrade().deref()).y.borrow())
664-
.cmp(&(*(*_arg0.upgrade().deref()).y.borrow())),
664+
.cmp(&(*(*_a0.upgrade().deref()).y.borrow())),
665665
));
666666
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
667667
return (*cmp.borrow_mut()).clone();
668668
}
669669
}
670670
return std::cmp::Ordering::Equal;
671671
}
672-
fn operator_eq(&self, _arg0: Ptr<Outer>) -> bool {
672+
fn operator_eq(&self, _a0: Ptr<Outer>) -> bool {
673673
return ({
674-
let _arg0: Ptr<Inner> = (*_arg0.upgrade().deref()).i.as_pointer();
674+
let _arg0: Ptr<Inner> = (*_a0.upgrade().deref()).i.as_pointer();
675675
InnerImpl::operator_eq(&(*(*self).upgrade().deref()).i.as_pointer(), _arg0)
676676
}) && ({
677677
let _lhs = (*(*(*self).upgrade().deref()).y.borrow());
678-
_lhs == (*(*_arg0.upgrade().deref()).y.borrow())
678+
_lhs == (*(*_a0.upgrade().deref()).y.borrow())
679679
});
680680
}
681681
}
682682
pub trait SecondaryImpl {
683-
fn operator_eq(&self, _arg0: Ptr<Secondary>) -> bool;
684-
fn operator_ne(&self, _arg0: Ptr<Secondary>) -> bool;
685-
fn operator_cmp(&self, _arg0: Ptr<Secondary>) -> std::cmp::Ordering;
686-
fn operator_lt(&self, _arg0: Ptr<Secondary>) -> bool;
687-
fn operator_ge(&self, _arg0: Ptr<Secondary>) -> bool;
683+
fn operator_eq(&self, _a0: Ptr<Secondary>) -> bool;
684+
fn operator_ne(&self, _a0: Ptr<Secondary>) -> bool;
685+
fn operator_cmp(&self, _a0: Ptr<Secondary>) -> std::cmp::Ordering;
686+
fn operator_lt(&self, _a0: Ptr<Secondary>) -> bool;
687+
fn operator_ge(&self, _a0: Ptr<Secondary>) -> bool;
688688
}
689689
impl SecondaryImpl for Ptr<Secondary> {
690-
fn operator_eq(&self, _arg0: Ptr<Secondary>) -> bool {
690+
fn operator_eq(&self, _a0: Ptr<Secondary>) -> bool {
691691
return {
692692
let _lhs = (*(*(*self).upgrade().deref()).a.borrow());
693-
_lhs == (*(*_arg0.upgrade().deref()).a.borrow())
693+
_lhs == (*(*_a0.upgrade().deref()).a.borrow())
694694
};
695695
}
696-
fn operator_ne(&self, _arg0: Ptr<Secondary>) -> bool {
696+
fn operator_ne(&self, _a0: Ptr<Secondary>) -> bool {
697697
return !({
698-
let _arg0: Ptr<Secondary> = (_arg0).clone();
698+
let _arg0: Ptr<Secondary> = (_a0).clone();
699699
SecondaryImpl::operator_eq(&(*self), _arg0)
700700
});
701701
}
702-
fn operator_cmp(&self, _arg0: Ptr<Secondary>) -> std::cmp::Ordering {
702+
fn operator_cmp(&self, _a0: Ptr<Secondary>) -> std::cmp::Ordering {
703703
{
704704
let cmp: Value<std::cmp::Ordering> = Rc::new(RefCell::new(
705705
(*(*(*self).upgrade().deref()).a.borrow())
706-
.cmp(&(*(*_arg0.upgrade().deref()).a.borrow())),
706+
.cmp(&(*(*_a0.upgrade().deref()).a.borrow())),
707707
));
708708
if !((*cmp.borrow()) == std::cmp::Ordering::Equal) {
709709
return (*cmp.borrow_mut()).clone();
710710
}
711711
}
712712
return std::cmp::Ordering::Equal;
713713
}
714-
fn operator_lt(&self, _arg0: Ptr<Secondary>) -> bool {
714+
fn operator_lt(&self, _a0: Ptr<Secondary>) -> bool {
715715
return ({
716-
let _arg0: Ptr<Secondary> = (_arg0).clone();
716+
let _arg0: Ptr<Secondary> = (_a0).clone();
717717
SecondaryImpl::operator_cmp(&(*self), _arg0)
718718
}) == std::cmp::Ordering::Less;
719719
}
720-
fn operator_ge(&self, _arg0: Ptr<Secondary>) -> bool {
720+
fn operator_ge(&self, _a0: Ptr<Secondary>) -> bool {
721721
return ({
722-
let _arg0: Ptr<Secondary> = (_arg0).clone();
722+
let _arg0: Ptr<Secondary> = (_a0).clone();
723723
SecondaryImpl::operator_cmp(&(*self), _arg0)
724724
}) != std::cmp::Ordering::Less;
725725
}

‎tests/unit/out/refcount/vector_with_allocator.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn main_0() -> i32 {
341341
}
342342
pub trait TestAllocator_double_Impl {
343343
fn allocate(&self, n: usize) -> Ptr<f64>;
344-
fn deallocate(&self, p: Ptr<f64>, _: usize);
344+
fn deallocate(&self, p: Ptr<f64>, _a1: usize);
345345
}
346346
impl TestAllocator_double_Impl for Ptr<TestAllocator_double_> {
347347
fn allocate(&self, n: usize) -> Ptr<f64> {
@@ -352,14 +352,15 @@ impl TestAllocator_double_Impl for Ptr<TestAllocator_double_> {
352352
.collect::<Box<[f64]>>(),
353353
);
354354
}
355-
fn deallocate(&self, p: Ptr<f64>, _: usize) {
355+
fn deallocate(&self, p: Ptr<f64>, _a1: usize) {
356356
let p: Value<Ptr<f64>> = Rc::new(RefCell::new(p));
357+
let _a1: Value<usize> = Rc::new(RefCell::new(_a1));
357358
(*p.borrow()).delete_array();
358359
}
359360
}
360361
pub trait TestAllocator_int_Impl {
361362
fn allocate(&self, n: usize) -> Ptr<i32>;
362-
fn deallocate(&self, p: Ptr<i32>, _: usize);
363+
fn deallocate(&self, p: Ptr<i32>, _a1: usize);
363364
}
364365
impl TestAllocator_int_Impl for Ptr<TestAllocator_int_> {
365366
fn allocate(&self, n: usize) -> Ptr<i32> {
@@ -370,8 +371,9 @@ impl TestAllocator_int_Impl for Ptr<TestAllocator_int_> {
370371
.collect::<Box<[i32]>>(),
371372
);
372373
}
373-
fn deallocate(&self, p: Ptr<i32>, _: usize) {
374+
fn deallocate(&self, p: Ptr<i32>, _a1: usize) {
374375
let p: Value<Ptr<i32>> = Rc::new(RefCell::new(p));
376+
let _a1: Value<usize> = Rc::new(RefCell::new(_a1));
375377
(*p.borrow()).delete_array();
376378
}
377379
}

‎tests/unit/out/unsafe/empty_main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ pub fn main() {
1919
argv.push(::std::ptr::null_mut());
2020
unsafe { ::std::process::exit(main_0((argv.len() - 1) as i32, argv.as_mut_ptr()) as i32) }
2121
}
22-
unsafe fn main_0(_: i32, _: *mut *mut libc::c_char) -> i32 {
22+
unsafe fn main_0(mut _a0: i32, mut _a1: *mut *mut libc::c_char) -> i32 {
2323
return 0;
2424
}

‎tests/unit/out/unsafe/operator_arithmetic_free.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub unsafe fn operator_inc_7(a: *mut S) -> *mut S {
4646
(*a).v.prefix_inc();
4747
return a;
4848
}
49-
pub unsafe fn operator_post_inc_8(a: *mut S, _: i32) -> S {
49+
pub unsafe fn operator_post_inc_8(a: *mut S, mut _a1: i32) -> S {
5050
let mut old: S = (*a);
5151
(*a).v.prefix_inc();
5252
return old;
@@ -55,7 +55,7 @@ pub unsafe fn operator_dec_9(a: *mut S) -> *mut S {
5555
(*a).v.prefix_dec();
5656
return a;
5757
}
58-
pub unsafe fn operator_post_dec_10(a: *mut S, _: i32) -> S {
58+
pub unsafe fn operator_post_dec_10(a: *mut S, mut _a1: i32) -> S {
5959
let mut old: S = (*a);
6060
(*a).v.prefix_dec();
6161
return old;

0 commit comments

Comments
 (0)