Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor variadics #638

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3866a89
Refactor `is_va_decl` to use `.map()` and `.unwrap_or_default()`.
kkysen Aug 23, 2022
593da11
Refactored `match_vacopy` with `?`.
kkysen Aug 23, 2022
67deb33
Replaced an `as &str` with a `.as_str()`.
kkysen Aug 23, 2022
0560612
Refactored `if ... { return None; }`s in `match` arms into `match` `i…
kkysen Aug 23, 2022
c2e1136
Replaced `args.len() == n` and then `args[0]`, etc. with `match`ing o…
kkysen Aug 23, 2022
f9eec5f
Reformatted the `match_vapart` `match` after refactoring it.
kkysen Aug 23, 2022
51b3d91
Refactored out repeated `match`ing on `__builtin_va_*` into a `.strip…
kkysen Aug 23, 2022
15575c3
Improved doc comments on inner variadic matching functions.
kkysen Aug 23, 2022
35701ce
Made the variadic-matching inner functions closures instead so we don…
kkysen Aug 23, 2022
578dc62
Renamed the local `ast_context` to `ast` for brevity since it's used …
kkysen Aug 23, 2022
66cebb5
Removed non-local control flow (`return None`) and variable declarati…
kkysen Aug 23, 2022
8fae26f
Fixed confusing "`*` pointer" language in docs, which could be a `**`…
kkysen Aug 24, 2022
eaccb5c
Favor `.unwrap_or(false)` over `.unwrap_or_default()` as it's less cl…
kkysen Aug 24, 2022
b4428a3
Revert "Refactored out repeated `match`ing on `__builtin_va_*` into a…
kkysen Aug 24, 2022
0e48fdb
Refactored out `let ast = &self.ast_context` for brevity in `fn match…
kkysen Aug 24, 2022
8ac1538
Re-formatted `match_or!`s onto 1 line each. 2 lines with an indented…
kkysen Aug 24, 2022
2439ed4
Revert "Refactor `is_va_decl` to use `.map()` and `.unwrap_or_default…
kkysen Aug 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved doc comments on inner variadic matching functions.
  • Loading branch information
kkysen committed Aug 23, 2022
commit 15575c396c66579e6bb833663c937b5b2c2ec3bc
17 changes: 10 additions & 7 deletions c2rust-transpile/src/translator/variadic.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ macro_rules! match_or {
}

impl<'c> Translation<'c> {
/// Returns true iff `va_start`, `va_end`, or `va_copy` may be called on `decl_id`.
/// Returns `true` iff `va_start`, `va_end`, or `va_copy` may be called on `decl_id`.
pub fn is_va_decl(&self, decl_id: CDeclId) -> bool {
self.function_context
.borrow()
@@ -34,7 +34,7 @@ impl<'c> Translation<'c> {
}

pub fn match_vastart(&self, expr: CExprId) -> Option<CDeclId> {
// struct-based va_list (e.g. x86_64)
/// `struct`-based `va_list` (e.g. x86_64).
fn match_vastart_struct(ast_context: &TypedAstContext, expr: CExprId) -> Option<CDeclId> {
match_or! { [ast_context[expr].kind]
CExprKind::ImplicitCast(_, e, _, _, _) => e }
@@ -43,8 +43,9 @@ impl<'c> Translation<'c> {
Some(va_id)
}

// struct-based va_list (e.g. x86_64) where va_list is accessed as a struct member
// supporting this pattern is necessary to transpile apache httpd
/// `struct`-based `va_list` (e.g. x86_64) where `va_list` is accessed as a `struct` member.
///
/// Supporting this pattern is necessary to transpile apache httpd.
fn match_vastart_struct_member(
ast_context: &TypedAstContext,
expr: CExprId,
@@ -58,8 +59,10 @@ impl<'c> Translation<'c> {
Some(va_id)
}

// struct-based va_list (e.g. x86_64) where va_list is accessed as a member of a struct pointer
// supporting this pattern is necessary to transpile [graphviz](https://gitlab.com/graphviz/graphviz/-/blob/5.0.0/lib/sfio/sftable.c#L321)
/// `struct`-based `va_list` (e.g. x86_64) where `va_list` is accessed as a member of a `struct *` pointer.
///
/// Supporting this pattern is necessary to transpile
/// [graphviz](https://gitlab.com/graphviz/graphviz/-/blob/5.0.0/lib/sfio/sftable.c#L321).
fn match_vastart_struct_pointer_member(
ast_context: &TypedAstContext,
expr: CExprId,
@@ -75,7 +78,7 @@ impl<'c> Translation<'c> {
Some(va_id)
}

// char pointer-based va_list (e.g. x86)
/// `char *` pointer-based `va_list` (e.g. x86).
fn match_vastart_pointer(ast_context: &TypedAstContext, expr: CExprId) -> Option<CDeclId> {
match_or! { [ast_context[expr].kind]
CExprKind::DeclRef(_, va_id, _) => va_id }