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

typedef struct { char a; int b; } *S7; #324

Open
phadej opened this issue Dec 2, 2024 · 2 comments
Open

typedef struct { char a; int b; } *S7; #324

phadej opened this issue Dec 2, 2024 · 2 comments
Assignees

Comments

@phadej
Copy link
Collaborator

phadej commented Dec 2, 2024

|-RecordDecl 0x27e80a70 <ex.h:1:9, col:33> col:9 struct definition
| |-FieldDecl 0x27e80b20 <col:18, col:23> col:23 a 'char'
| `-FieldDecl 0x27e80b88 <col:26, col:30> col:30 b 'int'
`-TypedefDecl 0x27e80ca0 <col:1, col:36> col:36 S7 'struct (unnamed struct at ex.h:1:9) *'
  `-PointerType 0x27e80c50 'struct (unnamed struct at ex.h:1:9) *'
    `-ElaboratedType 0x27e80be0 'struct (unnamed struct at ex.h:1:9)' sugar
      `-RecordType 0x27e80af0 'struct (unnamed at ex.h:1:9)'
        `-Record 0x27e80a70 ''
@phadej phadej self-assigned this Dec 2, 2024
@phadej
Copy link
Collaborator Author

phadej commented Dec 2, 2024

Here we need to come up with a name for the struct, as typedef is pointer to it. Rust bindgen generates

pub struct _bindgen_ty_1 {
    pub a: ::std::os::raw::c_char,
    pub b: ::std::os::raw::c_int,
}

pub type S7 = *mut _bindgen_ty_1;

@TravisCardwell
Copy link
Collaborator

Here is an initial design for a type constructor context:

data TypeConstrContext =
  ...
  | -- | Context for anonymous top-level structures/unions
    --
    -- Example: @typedef struct {...} *foo@
    AnonTopLevelTypeConstrContext {
      -- | Index (1-based) of anonymous top-level type constructors within the
      -- translation unit
      ctxAnonTopLevelTypeConstrIdx :: Word
    }

Perhaps the default could create names like HsBindgenType1, which is similar to the Rust behavior?

Another option would be to use the variable name, like how we use field names when an anonymous structure is for a named field.

@edsko edsko added this to the 1: `Storable` instances milestone Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants